Example #1
0
    def invalid_settings_test3(self):
        # dict without options
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {"os": None, "compiler": ["Visual Studio"]}
"""

        self.client.save({CONANFILE: content})
        self.client.run("install -s compiler=gcc -s compiler.version=4.8 --build missing", ignore_error=True)
        self.assertIn(bad_value_msg("settings.compiler", "gcc", ["Visual Studio"]),
                      str(self.client.user_io.out))

        # Test wrong settings in conanfile
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = invalid
"""

        self.client.save({CONANFILE: content})
        self.client.run("install --build missing", ignore_error=True)
        self.assertIn("invalid' is not defined",
                      str(self.client.user_io.out))
 def remove_compiler_test(self):
     self.sut.compiler.remove("Visual Studio")
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler = "Visual Studio"
     self.assertEqual(
         str(cm.exception),
         bad_value_msg("settings.compiler", "Visual Studio", ["gcc"]))
Example #3
0
 def basic_test(self):
     s = Settings({"os": ["Windows", "Linux"]})
     s.os = "Windows"
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler = "kk"
     self.assertEqual(str(cm.exception),
                      bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']"))
    def invalid_settings_test3(self):
        # dict without options
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {"os": None, "compiler": ["Visual Studio"]}
"""

        self.client.save({CONANFILE: content})
        self.client.run(
            "install -s compiler=gcc -s compiler.version=4.8 --build missing",
            ignore_error=True)
        self.assertIn(
            bad_value_msg("settings.compiler", "gcc", ["Visual Studio"]),
            str(self.client.user_io.out))

        # Test wrong settings in conanfile
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = invalid
"""

        self.client.save({CONANFILE: content})
        self.client.run("install --build missing", ignore_error=True)
        self.assertIn("invalid' is not defined", str(self.client.user_io.out))
Example #5
0
 def remove_os_test(self):
     self.sut.os.remove("Windows")
     with self.assertRaises(ConanException) as cm:
         self.sut.os = "Windows"
     self.assertEqual(str(cm.exception),
                      bad_value_msg("settings.os", "Windows", ["Linux"]))
     self.sut.os = "Linux"
     self.assertEqual(self.sut.os, "Linux")
Example #6
0
    def constraint4_test(self):
        s2 = {"os": ["Windows"]}
        self.sut.constraint(s2)
        with self.assertRaises(ConanException) as cm:
            self.sut.os = "Linux"
        self.assertEqual(str(cm.exception), bad_value_msg("settings.os", "Linux", ["Windows"]))

        self.sut.os = "Windows"
 def remove_os_test(self):
     self.sut.os.remove("Windows")
     with self.assertRaises(ConanException) as cm:
         self.sut.os = "Windows"
     self.assertEqual(str(cm.exception),
                      bad_value_msg("settings.os", "Windows", ["Linux"]))
     self.sut.os = "Linux"
     self.assertEqual(self.sut.os, "Linux")
Example #8
0
    def invalid_settings_test4(self):
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = "os"
"""

        self.client.save({CONANFILE: content})
        self.client.run("install -s os=ChromeOS --build missing",
                        ignore_error=True)
        self.assertIn(
            bad_value_msg(
                "settings.os", "ChromeOS",
                ['Android', 'FreeBSD', 'Linux', 'Macos', 'Windows', 'iOS']),
            str(self.client.user_io.out))

        # Now add new settings to config and try again
        config = load(self.client.paths.settings_path)
        config = config.replace("Windows,", "Windows, ChromeOS,")

        save(self.client.paths.settings_path, config)
        self.client.run("install -s os=ChromeOS --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))

        # Settings is None
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = None
"""
        self.client.save({CONANFILE: content})
        self.client.run("install --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))
        conan_info = ConanInfo.loads(
            load(os.path.join(self.client.current_folder, CONANINFO)))
        self.assertEquals(conan_info.settings.dumps(), "")

        # Settings is {}
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {}
"""
        self.client.save({CONANFILE: content})
        self.client.run("install --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))
        conan_info = ConanInfo.loads(
            load(os.path.join(self.client.current_folder, CONANINFO)))
        self.assertEquals(conan_info.settings.dumps(), "")
Example #9
0
 def remove_version_test(self):
     self.sut.compiler["Visual Studio"].version.remove("12")
     self.sut.compiler = "Visual Studio"
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler.version = "12"
     self.assertEqual(str(cm.exception),
                      bad_value_msg("settings.compiler.version", "12", ["10", "11"]))
     self.sut.compiler.version = 11
     self.assertEqual(self.sut.compiler.version, "11")
    def constraint4_test(self):
        s2 = {"os": ["Windows"]}
        self.sut.constraint(s2)
        with self.assertRaises(ConanException) as cm:
            self.sut.os = "Linux"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.os", "Linux", ["Windows"]))

        self.sut.os = "Windows"
 def basic_test(self):
     s = Settings({"os": ["Windows", "Linux"]})
     s.os = "Windows"
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler = "kk"
     self.assertEqual(
         str(cm.exception),
         bad_value_msg("settings.compiler", "kk",
                       "['Visual Studio', 'gcc']"))
 def remove_version_test(self):
     self.sut.compiler["Visual Studio"].version.remove("12")
     self.sut.compiler = "Visual Studio"
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler.version = "12"
     self.assertEqual(
         str(cm.exception),
         bad_value_msg("settings.compiler.version", "12", ["10", "11"]))
     self.sut.compiler.version = 11
     self.assertEqual(self.sut.compiler.version, "11")
Example #13
0
    def invalid_settings_test4(self):
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = "os"
"""

        self.client.save({CONANFILE: content})
        self.client.run("install -s os=ChromeOS --build missing", ignore_error=True)
        self.assertIn(bad_value_msg("settings.os", "ChromeOS",
                                    ['Android', 'Linux', 'Macos', 'Windows', 'iOS']),
                      str(self.client.user_io.out))

        # Now add new settings to config and try again
        config = load(self.client.paths.settings_path)
        config = config.replace("Windows,",
                                "Windows, ChromeOS,")

        save(self.client.paths.settings_path, config)
        self.client.run("install -s os=ChromeOS --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))

        # Settings is None
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = None
"""
        self.client.save({CONANFILE: content})
        self.client.run("install --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))
        conan_info = ConanInfo.loads(load(os.path.join(self.client.current_folder, CONANINFO)))
        self.assertEquals(conan_info.settings.dumps(), "")

        # Settings is {}
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {}
"""
        self.client.save({CONANFILE: content})
        self.client.run("install --build missing")
        self.assertIn('Generated conaninfo.txt', str(self.client.user_io.out))
        conan_info = ConanInfo.loads(load(os.path.join(self.client.current_folder, CONANINFO)))
        self.assertEquals(conan_info.settings.dumps(), "")
Example #14
0
    def invalid_settings_test2(self):
        # MISSING A DEFAULT VALUE BECAUSE ITS RESTRICTED TO OTHER, SO ITS REQUIRED
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {"os": ["Windows", "Linux", "Macos"], "compiler": ["Visual Studio"]}
"""

        self.client.save({CONANFILE: content})
        self.client.run("install -s compiler=gcc -s compiler.version=4.8 --build missing", ignore_error=True)
        self.assertIn(bad_value_msg("settings.compiler", "gcc", ["Visual Studio"]),
                      str(self.client.user_io.out))
Example #15
0
    def constraint7_test(self):
        s2 = {"os": None,
              "compiler": {"Visual Studio": {"version": ("11", "10")},
                            "gcc": None}}

        self.sut.constraint(s2)
        self.sut.compiler = "Visual Studio"
        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.version = "12"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler.version", "12", ["10", "11"]))
        self.sut.compiler.version = "10"
        self.sut.compiler.version = "11"
        self.sut.os = "Windows"
        self.sut.compiler = "gcc"
Example #16
0
    def constraint(self, constraint_def):
        """ allows to restrict a given Settings object with the input of another Settings object
        1. The other Settings object MUST be exclusively a subset of the former.
           No additions allowed
        2. If the other defines {"compiler": None} means to keep the full specification
        """
        if isinstance(constraint_def, (list, tuple, set)):
            constraint_def = {str(k): None for k in constraint_def or []}
        else:
            constraint_def = {str(k): v for k, v in constraint_def.iteritems()}

        fields_to_remove = []
        for field, config_item in self._data.iteritems():
            if field not in constraint_def:
                fields_to_remove.append(field)
                continue

            other_field_def = constraint_def[field]
            if other_field_def is None:  # Means leave it as is
                continue

            values_to_remove = []
            for value in config_item.values_range:  # value = "Visual Studio"
                if value not in other_field_def:
                    values_to_remove.append(value)
                else:  # recursion
                    if (not config_item.is_final
                            and isinstance(other_field_def, dict)
                            and other_field_def[value] is not None):
                        config_item[value].constraint(other_field_def[value])

            # Sanity check of input constraint values
            for value in other_field_def:
                if value not in config_item.values_range:
                    raise ConanException(
                        bad_value_msg(field, value, config_item.values_range))

            config_item.remove(values_to_remove)

        # Sanity check for input constraint wrong fields
        for field in constraint_def:
            if field not in self._data:
                raise ConanException(
                    undefined_field(self._name, field, self.fields))

        # remove settings not defined in the constraint
        self.remove(fields_to_remove)
    def invalid_settings_test2(self):
        # MISSING A DEFAULT VALUE BECAUSE ITS RESTRICTED TO OTHER, SO ITS REQUIRED
        content = """
from conans import ConanFile

class SayConan(ConanFile):
    name = "Say"
    version = "0.1"
    settings = {"os": ["Windows", "Linux", "Macos"], "compiler": ["Visual Studio"]}
"""

        self.client.save({CONANFILE: content})
        self.client.run(
            "install -s compiler=gcc -s compiler.version=4.8 --build missing",
            ignore_error=True)
        self.assertIn(
            bad_value_msg("settings.compiler", "gcc", ["Visual Studio"]),
            str(self.client.user_io.out))
Example #18
0
    def constraint(self, constraint_def):
        """ allows to restrict a given Settings object with the input of another Settings object
        1. The other Settings object MUST be exclusively a subset of the former.
           No additions allowed
        2. If the other defines {"compiler": None} means to keep the full specification
        """
        if isinstance(constraint_def, (list, tuple, set)):
            constraint_def = {str(k): None for k in constraint_def or []}
        else:
            constraint_def = {str(k): v for k, v in constraint_def.items()}

        fields_to_remove = []
        for field, config_item in self._data.items():
            if field not in constraint_def:
                fields_to_remove.append(field)
                continue

            other_field_def = constraint_def[field]
            if other_field_def is None:  # Means leave it as is
                continue

            values_to_remove = []
            for value in config_item.values_range:  # value = "Visual Studio"
                if value not in other_field_def:
                    values_to_remove.append(value)
                else:  # recursion
                    if (not config_item.is_final and isinstance(other_field_def, dict) and
                            other_field_def[value] is not None):
                        config_item[value].constraint(other_field_def[value])

            # Sanity check of input constraint values
            for value in other_field_def:
                if value not in config_item.values_range:
                    raise ConanException(bad_value_msg(field, value, config_item.values_range))

            config_item.remove(values_to_remove)

        # Sanity check for input constraint wrong fields
        for field in constraint_def:
            if field not in self._data:
                raise ConanException(undefined_field(self._name, field, self.fields))

        # remove settings not defined in the constraint
        self.remove(fields_to_remove)
    def constraint7_test(self):
        s2 = {
            "os": None,
            "compiler": {
                "Visual Studio": {
                    "version": ("11", "10")
                },
                "gcc": None
            }
        }

        self.sut.constraint(s2)
        self.sut.compiler = "Visual Studio"
        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.version = "12"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler.version", "12", ["10", "11"]))
        self.sut.compiler.version = "10"
        self.sut.compiler.version = "11"
        self.sut.os = "Windows"
        self.sut.compiler = "gcc"
Example #20
0
 def constraint3_test(self):
     s2 = {"os": ["Win"]}
     with self.assertRaises(ConanException) as cm:
         self.sut.constraint(s2)
     self.assertEqual(str(cm.exception),
                      bad_value_msg("os", "Win", ["Linux", "Windows"]))
    def my_test(self):
        self.assertEqual(self.sut.compiler, None)

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler = "kk"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler", "kk",
                          "['Visual Studio', 'gcc']"))

        self.sut.compiler = "Visual Studio"
        self.assertEqual(str(self.sut.compiler), "Visual Studio")
        self.assertEqual(self.sut.compiler, "Visual Studio")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.kk
        self.assertEqual(
            str(cm.exception),
            undefined_field("settings.compiler", "kk",
                            "['runtime', 'version']", "Visual Studio"))

        self.assertEqual(self.sut.compiler.version, None)

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.version = "123"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler.version", "123",
                          ['10', '11', '12']))

        self.sut.compiler.version = "12"
        self.assertEqual(self.sut.compiler.version, "12")
        self.assertEqual(str(self.sut.compiler.version), "12")

        with self.assertRaises(ConanException) as cm:
            assert self.sut.compiler == "kk"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler", "kk",
                          "['Visual Studio', 'gcc']"))

        self.assertFalse(self.sut.compiler == "gcc")
        self.assertTrue(self.sut.compiler == "Visual Studio")

        self.assertTrue(self.sut.compiler.version == "12")
        self.assertFalse(self.sut.compiler.version == "11")

        with self.assertRaises(ConanException) as cm:
            assert self.sut.compiler.version == "13"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler.version", "13",
                          ['10', '11', '12']))

        self.sut.compiler = "gcc"
        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.runtime
        self.assertEqual(
            str(cm.exception),
            undefined_field("settings.compiler", "runtime",
                            "['arch', 'version']", "gcc"))

        self.sut.compiler.arch = "x86"
        self.sut.compiler.arch.speed = "A"
        self.assertEqual(self.sut.compiler.arch.speed, "A")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.arch.speed = "D"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler.arch.speed", "D", ['A', 'B']))

        self.sut.compiler.arch = "x64"
        self.sut.compiler.arch.speed = "C"
        self.assertEqual(self.sut.compiler.arch.speed, "C")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.arch.speed = "A"
        self.assertEqual(
            str(cm.exception),
            bad_value_msg("settings.compiler.arch.speed", "A", ['C', 'D']))

        self.sut.compiler.arch.speed = "D"
        self.assertEqual(self.sut.compiler.arch.speed, "D")
Example #22
0
    def my_test(self):
        self.assertEqual(self.sut.compiler, None)

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler = "kk"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']"))

        self.sut.compiler = "Visual Studio"
        self.assertEqual(str(self.sut.compiler), "Visual Studio")
        self.assertEqual(self.sut.compiler, "Visual Studio")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.kk
        self.assertEqual(str(cm.exception),
                         undefined_field("settings.compiler", "kk", "['runtime', 'version']",
                                         "Visual Studio"))

        self.assertEqual(self.sut.compiler.version, None)

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.version = "123"
        self.assertEqual(str(cm.exception),
                             bad_value_msg("settings.compiler.version", "123", ['10', '11', '12']))

        self.sut.compiler.version = "12"
        self.assertEqual(self.sut.compiler.version, "12")
        self.assertEqual(str(self.sut.compiler.version), "12")

        with self.assertRaises(ConanException) as cm:
            assert self.sut.compiler == "kk"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler", "kk", "['Visual Studio', 'gcc']"))

        self.assertFalse(self.sut.compiler == "gcc")
        self.assertTrue(self.sut.compiler == "Visual Studio")

        self.assertTrue(self.sut.compiler.version == "12")
        self.assertFalse(self.sut.compiler.version == "11")

        with self.assertRaises(ConanException) as cm:
            assert self.sut.compiler.version == "13"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler.version", "13", ['10', '11', '12']))

        self.sut.compiler = "gcc"
        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.runtime
        self.assertEqual(str(cm.exception),
                         undefined_field("settings.compiler", "runtime", "['arch', 'version']",
                                         "gcc"))

        self.sut.compiler.arch = "x86"
        self.sut.compiler.arch.speed = "A"
        self.assertEqual(self.sut.compiler.arch.speed, "A")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.arch.speed = "D"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler.arch.speed", "D", ['A', 'B']))

        self.sut.compiler.arch = "x64"
        self.sut.compiler.arch.speed = "C"
        self.assertEqual(self.sut.compiler.arch.speed, "C")

        with self.assertRaises(ConanException) as cm:
            self.sut.compiler.arch.speed = "A"
        self.assertEqual(str(cm.exception),
                         bad_value_msg("settings.compiler.arch.speed", "A", ['C', 'D']))

        self.sut.compiler.arch.speed = "D"
        self.assertEqual(self.sut.compiler.arch.speed, "D")
Example #23
0
 def remove_compiler_test(self):
     self.sut.compiler.remove("Visual Studio")
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler = "Visual Studio"
     self.assertEqual(str(cm.exception),
                      bad_value_msg("settings.compiler", "Visual Studio", ["gcc"]))
 def constraint3_test(self):
     s2 = {"os": ["Win"]}
     with self.assertRaises(ConanException) as cm:
         self.sut.constraint(s2)
     self.assertEqual(str(cm.exception),
                      bad_value_msg("os", "Win", ["Linux", "Windows"]))