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))
def invalid_settings_test4(self): content = """ from conans import ConanFile class SayConan(ConanFile): name = "Say" version = "0.1" settings = "os" """ client = TestClient() client.save({CONANFILE: content}) client.run("install . -s os=ChromeOS --build missing", assert_error=True) self.assertIn( bad_value_msg("settings.os", "ChromeOS", [ 'Android', 'Arduino', 'FreeBSD', 'Linux', 'Macos', 'SunOS', 'Windows', 'WindowsStore', 'iOS', 'tvOS', 'watchOS' ]), str(client.user_io.out)) # Now add new settings to config and try again config = load(client.client_cache.settings_path) config = config.replace( "Windows:%s" % os.linesep, "Windows:%s ChromeOS:%s" % (os.linesep, os.linesep)) save(client.client_cache.settings_path, config) client.run("install . -s os=ChromeOS --build missing") self.assertIn('Generated conaninfo.txt', str(client.user_io.out)) # Settings is None content = """ from conans import ConanFile class SayConan(ConanFile): name = "Say" version = "0.1" settings = None """ client.save({CONANFILE: content}) client.run("install . --build missing") self.assertIn('Generated conaninfo.txt', str(client.user_io.out)) conan_info = ConanInfo.loads( load(os.path.join(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 = {} """ client.save({CONANFILE: content}) client.run("install . --build missing") self.assertIn('Generated conaninfo.txt', str(client.user_io.out)) conan_info = ConanInfo.loads( load(os.path.join(client.current_folder, CONANINFO))) self.assertEquals(conan_info.settings.dumps(), "")
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 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 test_invalid_settings3(self): # dict without options content = """ from conans import ConanFile class SayConan(ConanFile): name = "Say" version = "0.1" settings = {"os": None, "compiler": ["Visual Studio"]} """ client = TestClient() client.save({CONANFILE: content}) client.run("install . -s compiler=gcc -s compiler.version=4.8 --build missing", assert_error=True) self.assertIn(bad_value_msg("settings.compiler", "gcc", ["Visual Studio"]), str(client.out)) # Test wrong settings in conanfile content = textwrap.dedent(""" from conans import ConanFile class SayConan(ConanFile): settings = invalid """) client.save({CONANFILE: content}) client.run("install . --build missing", assert_error=True) self.assertIn("invalid' is not defined", client.out)
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")
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_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 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', 'Arduino', 'FreeBSD', 'Linux', 'Macos', 'SunOS', 'Windows', 'WindowsStore', 'iOS', 'tvOS', 'watchOS']), 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:%s" % os.linesep, "Windows:%s ChromeOS:%s" % (os.linesep, os.linesep)) 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(), "")
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"
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", "FreeBSD", "SunOS"], "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))
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), str( 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), str( 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")
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), str(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), str(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")
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"]))