def test_rel_path(self): base_folder = temp_folder() source_folder = os.path.join(base_folder, "source") current_folder = os.path.join(base_folder, "current") os.makedirs(current_folder) client = TestClient(current_folder=current_folder) files = cpp_hello_conan_files("Hello0", "0.1") conan_ref = ConanFileReference("Hello0", "0.1", "lasote", "stable") client.save(files, path=source_folder) client.run("export lasote/stable --path=../source") reg_path = client.paths.export(conan_ref) manif = FileTreeManifest.loads(load(client.paths.digestfile_conanfile(conan_ref))) self.assertIn('%s: A new conanfile.py version was exported' % str(conan_ref), client.user_io.out) self.assertIn('%s: Folder: %s' % (str(conan_ref), reg_path), client.user_io.out) self.assertTrue(os.path.exists(reg_path)) for name in list(files.keys()): self.assertTrue(os.path.exists(os.path.join(reg_path, name))) expected_sums = {'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': '5632cf850a7161388ab24f42b9bdb3fd', 'executable': '68b329da9893e34099c7d8ad5cb9c940', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, manif.file_sums)
def complete_build_flow_test(self): """In local user folder""" client = TestClient() command = os.sep.join([".", "bin", "say_hello"]) for install, lang, static in [("install", 0, True), ("install -o language=1", 1, True), ("install -o language=1 -o static=False", 1, False), ("install -o static=False", 0, False)]: dll_export = client.default_compiler_visual_studio and not static files = cpp_hello_conan_files("Hello0", "0.1", dll_export=dll_export) client.save(files) client.run(install) time.sleep(1) # necessary so the conaninfo.txt is flushed to disc client.run('build') client.runner(command, client.current_folder) msg = "Hello" if lang == 0 else "Hola" self.assertIn("%s Hello0" % msg, client.user_io.out) conan_info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.loads(load(conan_info_path)) self.assertTrue(conan_info.full_options.language == lang) if static: self.assertTrue(conan_info.full_options.static) else: self.assertFalse(conan_info.full_options.static)
def test_update_settings(self): default_conf = """[storage] path: ~/.conan/data [settings_defaults] compiler=Visual Studio compiler.version=42 """ client = TestClient() save(client.client_cache.conan_conf_path, default_conf) error = client.run("install Any/0.2@user/channel", ignore_error=True) self.assertTrue(error) self.assertIn("'42' is not a valid 'settings.compiler.version' value", client.user_io.out) error = client.run( 'install -s compiler="Visual Studio" -s compiler.version=14', ignore_error=True) self.assertTrue(error) self.assertIn("'42' is not a valid 'settings.compiler.version' value", client.user_io.out) with tools.environment_append({"CONAN_ENV_COMPILER_VERSION": "14"}): self.assertEqual(os.environ.get("CONAN_ENV_COMPILER_VERSION"), "14") error = client.run('install', ignore_error=True) self.assertTrue(error) self.assertIn( "'42' is not a valid 'settings.compiler.version' value", client.user_io.out) self.assertIsNone(os.environ.get("CONAN_ENV_COMPILER_VERSION"))
def external_python_with_simple_var_test(self): client = TestClient() conanfile_simple = """from conans import ConanFile, tools class ToolsTest(ConanFile): name = "Hello" version = "0.1" def build(self): with tools.pythonpath(self): import external external.external_baz() """ external_py = ''' def external_baz(): print("External baz") ''' external_dir = temp_folder() save(os.path.join(external_dir, "external.py"), external_py) client.save({CONANFILE: conanfile_simple}) client.run("export lasote/stable") # Should work even if PYTHONPATH is not declared as [], only external resource needed client.run( 'install Hello/0.1@lasote/stable --build missing -e PYTHONPATH="%s"' % external_dir)
def no_signature_test(self): auth = AuthorizationHeaderSpy() retur = ReturnHandlerPlugin() server = TestServer(plugins=[auth, retur]) server.app servers = {"default": server} client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) client.save({"conanfile.py": conanfile}) client.run("export lasote/stable") errors = client.run("upload Hello/0.1@lasote/stable") self.assertFalse(errors) expected_calls = [('get_conan_digest_url', None), ('check_credentials', None), ('authenticate', 'Basic'), ('get_conanfile_snapshot', 'Bearer'), ('get_conanfile_upload_urls', 'Bearer'), ('put', 'Bearer')] self.assertEqual(len(expected_calls), len(auth.auths)) for i, (method, auth_type) in enumerate(expected_calls): real_call = auth.auths[i] self.assertEqual(method, real_call[0]) if auth_type: self.assertIn(auth_type, real_call[1]) # The Bearer of the last two calls must be identical self.assertEqual(auth.auths[-1][1], auth.auths[-2][1])
def reuse_test(self): files = cpp_hello_conan_files("Hello0", "1.0") # To avoid building files[CONANFILE] = files[CONANFILE].replace("build(", "build2(") self.client.save(files) self.client.run("export lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload Hello0/1.0@lasote/stable --all") client2 = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client2.run("install Hello0/1.0@lasote/stable") files["helloHello0.h"] = "//EMPTY!" self.client.save(files, clean_first=True) sleep(1) self.client.run("export lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload Hello0/1.0@lasote/stable --all") client2.run("install Hello0/1.0@lasote/stable --update") ref = ConanFileReference.loads("Hello0/1.0@lasote/stable") package_ids = client2.paths.conan_packages(ref) package_path = client2.paths.package(PackageReference(ref, package_ids[0])) header = load(os.path.join(package_path, "include/helloHello0.h")) self.assertEqual(header, "//EMPTY!")
def _build(self, cmd, static, pure_c, use_cmake, lang): client = TestClient() dll_export = client.default_compiler_visual_studio and not static files = cpp_hello_conan_files("Hello0", "0.1", dll_export=dll_export, pure_c=pure_c, use_cmake=use_cmake) client.save(files) client.run(cmd) client.run('build') ld_path = ("LD_LIBRARY_PATH=$(pwd)" if not static and not platform.system() == "Windows" else "") command = os.sep.join([".", "bin", "say_hello"]) client.runner("%s %s" % (ld_path, command), cwd=client.current_folder) msg = "Hello" if lang == 0 else "Hola" self.assertIn("%s Hello0" % msg, client.user_io.out) conan_info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.loads(load(conan_info_path)) self.assertTrue(conan_info.full_options.language == lang) if static: self.assertTrue(conan_info.full_options.static) else: self.assertFalse(conan_info.full_options.static)
def reuse_test(self): files = cpp_hello_conan_files("Hello0", "1.0") # To avoid building files[CONANFILE] = files[CONANFILE].replace("build(", "build2(") self.client.save(files) self.client.run("export lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload Hello0/1.0@lasote/stable --all") client2 = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) client2.run("install Hello0/1.0@lasote/stable") files["helloHello0.h"] = "//EMPTY!" self.client.save(files, clean_first=True) sleep(1) self.client.run("export lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload Hello0/1.0@lasote/stable --all") client2.run("install Hello0/1.0@lasote/stable --update") ref = ConanFileReference.loads("Hello0/1.0@lasote/stable") package_ids = client2.paths.conan_packages(ref) package_path = client2.paths.package( PackageReference(ref, package_ids[0])) header = load(os.path.join(package_path, "include/helloHello0.h")) self.assertEqual(header, "//EMPTY!")
def global_test(self): client = TestClient() files = {'conanfile.py': base_conanfile.replace("%GLOBAL%", "self.global_system_requirements=True")} client.save(files) client.run("export user/testing") client.run("install Test/0.1@user/testing --build missing") self.assertIn("*+Running system requirements+*", client.user_io.out) conan_ref = ConanFileReference.loads("Test/0.1@user/testing") package_ref = PackageReference(conan_ref, "a527106fd9f2e3738a55b02087c20c0a63afce9d") self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref))) load_file = load(client.paths.system_reqs(conan_ref)) self.assertIn("Installed my stuff", load_file) # Run again client.run("install Test/0.1@user/testing --build missing") self.assertNotIn("*+Running system requirements+*", client.user_io.out) self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref))) load_file = load(client.paths.system_reqs(conan_ref)) self.assertIn("Installed my stuff", load_file) # Run with different option client.run("install Test/0.1@user/testing -o myopt=False --build missing") self.assertNotIn("*+Running system requirements+*", client.user_io.out) package_ref2 = PackageReference(conan_ref, "54c9626b48cefa3b819e64316b49d3b1e1a78c26") self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref))) self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref2))) load_file = load(client.paths.system_reqs(conan_ref)) self.assertIn("Installed my stuff", load_file) # remove packages client.run("remove Test* -f -p") self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref))) self.assertFalse(os.path.exists(client.paths.system_reqs_package(package_ref2))) self.assertFalse(os.path.exists(client.paths.system_reqs(conan_ref)))
def reuse_test(self): client = TestClient() client.save({ CONANFILE: conanfile, "__init__.py": "", "mytest.py": test }) client.run("export lasote/stable") client.save({CONANFILE: reuse}, clean_first=True) client.run("install . -g txt -g env") content = load(os.path.join(client.current_folder, CONANENV)) self.assertIn("PYTHONPATH", content) self.assertIn("Hello Bar", client.user_io.out) self.assertNotIn("Hello Foo", client.user_io.out) client.run("build") self.assertNotIn("Hello Bar", client.user_io.out) self.assertIn("Hello Foo", client.user_io.out) client.run("export lasote/stable") client.run("install Consumer/0.1@lasote/stable --build") lines = [ line.split(":")[1] for line in str(client.user_io.out).splitlines() if line.startswith("Consumer/0.1@lasote/stable: Hello") ] self.assertEqual( [' Hello Baz', ' Hello Foo', ' Hello Boom', ' Hello Bar'], lines)
def setUp(self): client = TestClient() base = ''' from conans import ConanFile class ConanLib(ConanFile): name = "lib" version = "0.1" ''' files = {"conanfile.py": base} client.save(files) client.run("export user/channel") base = ''' from conans import ConanFile class ConanOtherLib(ConanFile): name = "otherlib" version = "0.2" options = {"otherlib_option": [1, 2, 3]} default_options="otherlib_option=3" ''' files = {"conanfile.py": base} client.save(files) client.run("export user/channel") self.base_folder = client.base_folder
def complete_build_flow_test(self): """In local user folder""" client = TestClient() command = os.sep.join([".", "bin", "say_hello"]) for pure_c in (False, True): for install, lang, static in [ ("install", 0, True), ("install -o language=1", 1, True), ("install -o language=1 -o static=False", 1, False), ("install -o static=False", 0, False) ]: dll_export = client.default_compiler_visual_studio and not static files = cpp_hello_conan_files("Hello0", "0.1", dll_export=dll_export, pure_c=pure_c) client.save(files, clean_first=True) client.run(install) time.sleep( 1) # necessary so the conaninfo.txt is flushed to disc client.run('build') client.runner(command, cwd=client.current_folder) msg = "Hello" if lang == 0 else "Hola" self.assertIn("%s Hello0" % msg, client.user_io.out) conan_info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.loads(load(conan_info_path)) self.assertTrue(conan_info.full_options.language == lang) if static: self.assertTrue(conan_info.full_options.static) else: self.assertFalse(conan_info.full_options.static)
def test_path(self): base_folder = temp_folder() source_folder = os.path.join(base_folder, "source") current_folder = os.path.join(base_folder, "current") client = TestClient(current_folder=current_folder) files = cpp_hello_conan_files("Hello0", "0.1") conan_ref = ConanFileReference("Hello0", "0.1", "lasote", "stable") conanfile = files.pop("conanfile.py") client.save(files, path=source_folder) conanfile = conanfile.replace("exports = '*'", 'exports = "../source*"') client.save({"conanfile.py": conanfile}) client.run("export lasote/stable") reg_path = client.paths.export(conan_ref) manif = FileTreeManifest.loads(load(client.paths.digestfile_conanfile(conan_ref))) self.assertIn('%s: A new conanfile.py version was exported' % str(conan_ref), client.user_io.out) self.assertIn('%s: Folder: %s' % (str(conan_ref), reg_path), client.user_io.out) self.assertTrue(os.path.exists(reg_path)) for name in ['conanfile.py', 'conanmanifest.txt', 'source/main.cpp', 'source/executable', 'source/hello.cpp', 'source/CMakeLists.txt', 'source/helloHello0.h']: self.assertTrue(os.path.exists(os.path.join(reg_path, name))) expected_sums = {'source/hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'source/main.cpp': '0479f3c223c9a656a718f3148e044124', 'source/CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': 'c90fe9d800e1f48c8ea0999e8e5929d8', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, manif.file_sums)
def test_export_the_same_code(self): file_list = self._create_packages_and_builds() # Export the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") conan2.save(files2) conan2.run("export lasote/stable") reg_path2 = conan2.paths.export(self.conan_ref) digest2 = FileTreeManifest.loads(load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertNotIn('A new Conan version was exported', conan2.user_io.out) self.assertNotIn('Cleaning the old builds ...', conan2.user_io.out) self.assertNotIn('Cleaning the old packs ...', conan2.user_io.out) self.assertNotIn('All the previous packs were cleaned', conan2.user_io.out) self.assertIn('conanfile.py exported as %s in %s' % (self.conan_ref, reg_path2), conan2.user_io.out) self.assertTrue(os.path.exists(reg_path2)) for name in files2.keys(): self.assertTrue(os.path.exists(os.path.join(reg_path2, name))) expected_sums = {'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': '310d65b60943b879286cf8839cf9ba08', 'conanfile.py': '4df4b5266ad6d5d55cbdd0a8b12c9d1a', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, digest2.file_sums) for f in file_list: self.assertTrue(os.path.exists(f))
def test_export_a_new_version(self): self._create_packages_and_builds() # Export an update of the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") files2[CONANFILE] = "# insert comment\n %s" % files2[CONANFILE] conan2.save(files2) conan2.run("export lasote/stable") reg_path3 = conan2.paths.export(self.conan_ref) digest3 = FileTreeManifest.loads(load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertIn('A new conanfile.py version was exported', conan2.user_io.out) # self.assertIn('All the previous packs were cleaned', conan2.user_io.out) self.assertIn('conanfile.py exported as %s in %s' % (self.conan_ref, reg_path3), conan2.user_io.out) self.assertTrue(os.path.exists(reg_path3)) for name in files2.keys(): self.assertTrue(os.path.exists(os.path.join(reg_path3, name))) expected_sums = {'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': '310d65b60943b879286cf8839cf9ba08', 'conanfile.py': '5a2c6e2d6b39638b7d8560786d7935a3', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, digest3.file_sums)
def test_base(self): base = ''' [generators] cmake gcc qbs qmake scons txt visual_studio xcode ycm ''' files = {"conanfile.txt": base} client = TestClient() client.save(files) client.run("install --build") self.assertEqual( sorted([ 'conanfile.txt', 'conaninfo.txt', 'conanbuildinfo.cmake', 'conanbuildinfo.gcc', 'conanbuildinfo.qbs', 'conanbuildinfo.pri', 'SConscript_conan', 'conanbuildinfo.txt', 'conanbuildinfo.props', 'conanbuildinfo.xcconfig', '.ycm_extra_conf.py' ]), sorted(os.listdir(client.current_folder)))
def local_source_test(self): conanfile = ''' from conans import ConanFile from conans.util.files import save class ConanLib(ConanFile): def source(self): self.output.info("Running source!") err save("file1.txt", "Hello World") ''' # First, failing source() client = TestClient() client.save({CONANFILE: conanfile}) client.run("source .", ignore_error=True) self.assertIn("PROJECT: Running source!", client.user_io.out) self.assertIn("ERROR: PROJECT: Error in source() method, line 9", client.user_io.out) # Fix the error and repeat client.save({CONANFILE: conanfile.replace("err", "")}) client.run("source .") self.assertIn("PROJECT: Configuring sources in", client.user_io.out) self.assertIn("PROJECT: WARN: Your previous source command failed", client.user_io.out) self.assertIn("PROJECT: Running source!", client.user_io.out) self.assertEqual( "Hello World", load(os.path.join(client.current_folder, "file1.txt")))
def test_txt(self): base = '''[requires] lib/0.1@user/channel ''' extension = '''[requires] lib/0.1@user/channel otherlib/0.2@user/channel [options] otherlib:otherlib_option = 1 ''' files = {"conanfile.txt": base, "conanfile_dev.txt": extension} client = TestClient(self.base_folder) client.save(files) client.run("install --build") conaninfo = load(os.path.join(client.current_folder, "conaninfo.txt")) self.assertIn("lib/0.1@user/channel", conaninfo) self.assertNotIn("otherlib/0.2@user/channel", conaninfo) self.assertNotIn("otherlib:otherlib_option=1", conaninfo) client.run("install --build --file=conanfile_dev.txt") conaninfo = load(os.path.join(client.current_folder, "conaninfo.txt")) self.assertIn("lib/0.1@user/channel", conaninfo) self.assertIn("otherlib/0.2@user/channel", conaninfo) self.assertIn("otherlib:otherlib_option=1", conaninfo)
def reuse_downloaded_tgz_test(self): '''Download packages from a remote, then copy to another channel and reupload them. It needs to compress it again, not tgz is kept''' # UPLOAD A PACKAGE conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1", need_patch=True, build=False) files["another_export_file.lib"] = "to compress" self.client.save(files) self.client.run("export lasote/stable") self.client.run("install %s --build missing" % str(conan_reference)) self.client.run("upload %s --all" % str(conan_reference)) self.assertIn("Compressing exported files", self.client.user_io.out) self.assertIn("Compressing package", self.client.user_io.out) # Other user downloads the package # THEN A NEW USER DOWNLOADS THE PACKAGES AND UPLOADS COMPRESSING AGAIN # BECAUSE ONLY TGZ IS KEPT WHEN UPLOADING other_client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) other_client.run("install Hello0/0.1@lasote/stable --all") other_client.run("upload Hello0/0.1@lasote/stable --all") self.assertIn("Compressing exported files", self.client.user_io.out) self.assertIn("Compressing package", self.client.user_io.out)
def test_override_simple2(self): client = TestClient() # Try injecting some package level ENV in the install self._export(client, "A", [], {"VAR3": "-23"}, { "VAR1": "900", "VAR2": "23" }) self._export(client, "B", ["A"], {}, {"VAR1": "800", "VAR2": "24"}) self._export(client, "C", ["B"], {}, {"VAR1": "700"}) client.save({"conanfile.py": reuse}) client.run("install . --build missing -e VAR3=override") self.assertIn("Building LIB_A, VAR1:None", client.user_io.out) self.assertIn("Building LIB_A, VAR2:None", client.user_io.out) self.assertIn("Building LIB_A, VAR3:override", client.user_io.out) self.assertIn("Building LIB_B, VAR1:900", client.user_io.out) self.assertIn("Building LIB_B, VAR2:23", client.user_io.out) self.assertIn("Building LIB_B, VAR3:override", client.user_io.out) self.assertIn("Building LIB_C, VAR1:800", client.user_io.out) self.assertIn("Building LIB_C, VAR2:24", client.user_io.out) self.assertIn("Building LIB_C, VAR3:override", client.user_io.out) client.run("build") self.assertInSep("VAR1=>700:800:900", client.user_io.out) self.assertInSep("VAR2=>24:23*", client.user_io.out) self.assertInSep("VAR3=>override*", client.user_io.out)
def test_export_a_new_version(self): self._create_packages_and_builds() # Export an update of the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") files2[CONANFILE] = "# insert comment\n %s" % files2[CONANFILE] conan2.save(files2) conan2.run("export lasote/stable") reg_path3 = conan2.paths.export(self.conan_ref) digest3 = FileTreeManifest.loads( load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertIn('A new conanfile.py version was exported', conan2.user_io.out) # self.assertIn('All the previous packs were cleaned', conan2.user_io.out) self.assertIn( 'conanfile.py exported as %s in %s' % (self.conan_ref, reg_path3), conan2.user_io.out) self.assertTrue(os.path.exists(reg_path3)) for name in files2.keys(): self.assertTrue(os.path.exists(os.path.join(reg_path3, name))) expected_sums = { 'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': '4ddc61c8efb118c7a0b1621dc04b31af', 'conanfile.py': '5a2c6e2d6b39638b7d8560786d7935a3', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, digest3.file_sums)
def fail_test_package_test(self): client = TestClient() conanfile = """ from conans import ConanFile class HelloConan(ConanFile): name = "Hello" version = "0.1" exports = "*" def package(self): self.copy("*") """ test_conanfile = """ from conans import ConanFile, CMake import os class HelloReuseConan(ConanFile): requires = "Hello/0.1@lasote/stable" def test(self): self.conanfile_directory """ client.save({"conanfile.py": conanfile, "FindXXX.cmake": "Hello FindCmake", "test/conanfile.py": test_conanfile}) client.run("test_package") ref = PackageReference.loads("Hello/0.1@lasote/stable:" "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertEqual("Hello FindCmake", load(os.path.join(client.paths.package(ref), "FindXXX.cmake"))) client.save({"FindXXX.cmake": "Bye FindCmake"}) client.run("test_package") self.assertEqual("Bye FindCmake", load(os.path.join(client.paths.package(ref), "FindXXX.cmake")))
def copy_test(self): client = TestClient() client.save({CONANFILE: conanfile}) client.run("export lasote/stable") client.run("install Hello0/0.1@lasote/stable --build=missing") error = client.run("copy hello0/0.1@lasote/stable otheruser/testing", ignore_error=True) self._check(error, client)
def test_export_a_new_version(self): self._create_packages_and_builds() # Export an update of the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") files2[CONANFILE] = "# insert comment\n %s" % files2[CONANFILE] conan2.save(files2) conan2.run("export lasote/stable") reg_path3 = conan2.paths.export(self.conan_ref) digest3 = FileTreeManifest.loads(load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertIn('A new conanfile.py version was exported', conan2.user_io.out) self.assertIn('%s: conanfile.py exported to local storage' % str(self.conan_ref), self.conan.user_io.out) self.assertIn('%s: Folder: %s' % (str(self.conan_ref), reg_path3), self.conan.user_io.out) self.assertTrue(os.path.exists(reg_path3)) for name in files2.keys(): self.assertTrue(os.path.exists(os.path.join(reg_path3, name))) expected_sums = {'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': 'c5889ea6485599c7a0cae02b54270b35', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, digest3.file_sums)
def remove_specific_builds_test(self): client = TestClient() client.save({"conanfile.py": conanfile}) client.run("export user/channel") client.save({"conanfile.txt": consumer}, clean_first=True) client.run('install -s build_type=Debug') client.run('install -s build_type=Release') ref = ConanFileReference.loads("Pkg/0.1@user/channel") def _check_builds(): builds = client.client_cache.conan_builds(ref) self.assertEqual(1, len(builds)) packages = client.client_cache.conan_packages(ref) self.assertEqual(2, len(packages)) self.assertNotIn(builds[0], packages) return builds[0], packages build, packages = _check_builds() client.run("remove Pkg/0.1@user/channel -b %s -f" % packages[0]) _check_builds() client.run("remove Pkg/0.1@user/channel -b %s -f" % build) builds = client.client_cache.conan_builds(ref) self.assertEqual(0, len(builds)) packages = client.client_cache.conan_packages(ref) self.assertEqual(2, len(packages))
def check_multi_server_test(self): # Check what happen if we have 2 servers and one is outdated # The expected behavior: If we specify the remote with (-r), the commmand will fail # if the client fot that remote is outdated. If we are just looking for a package (not with -r) # the client will look for the package on each remote. # Client deprecated for "the_last_server" but OK for "normal_server" self.servers = OrderedDict({"the_last_server": self._get_server(10, 4), "normal_server": self._get_server(4, 2)}) # First upload a package ok with an ok client tmp_client = TestClient(servers=self.servers, users={"default":[("lasote", "mypass")]}, client_version=4) files = cpp_hello_conan_files("Hello0", "0.1") tmp_client.save(files) tmp_client.run("export lasote/stable") errors = tmp_client.run("upload Hello0/0.1@lasote/stable -r normal_server --all") errors |= tmp_client.run("upload Hello0/0.1@lasote/stable -r the_last_server --all") self.assertFalse(errors) # Now with a conflictive client...try to look in servers self.client = TestClient(servers=self.servers, users={"default":[("lasote", "mypass")]}, client_version=2) errors = self.client.run("search something -r the_last_server", ignore_error=True) self.assertIn("Your conan's client version is deprecated for the current remote (v10). Upgrade conan client.", self.client.user_io.out) self.assertTrue(errors) # Errors errors = self.client.run("install Hello0/0.1@lasote/stable --build missing", ignore_error=True) self.assertIn("Your conan's client version is deprecated for the current remote (v10). Upgrade conan client.", self.client.user_io.out) self.assertFalse(errors) # No Errors! because it finds the package in the second remote
def install_same_test(self): client = TestClient() client.save({CONANFILE: conanfile}) client.run("export lasote/stable") error = client.run("install hello0/0.1@lasote/stable --build=missing", ignore_error=True) self._check(error, client)
def local_source_test(self): conanfile = """ from conans import ConanFile from conans.util.files import save class ConanLib(ConanFile): def source(self): self.output.info("Running source!") err save("file1.txt", "Hello World") """ # First, failing source() client = TestClient() client.save({CONANFILE: conanfile}) client.run("source .", ignore_error=True) self.assertIn("PROJECT: Running source!", client.user_io.out) self.assertIn("ERROR: PROJECT: Error in source() method, line 9", client.user_io.out) # Fix the error and repeat client.save({CONANFILE: conanfile.replace("err", "")}) client.run("source .") self.assertIn("PROJECT: Configuring sources in", client.user_io.out) self.assertIn("PROJECT: WARN: Your previous source command failed", client.user_io.out) self.assertIn("PROJECT: Running source!", client.user_io.out) self.assertEqual("Hello World", load(os.path.join(client.current_folder, "file1.txt")))
def source_test(self): client = TestClient() client.save({CONANFILE: conanfile}) client.run("export lasote/stable") error = client.run("source hello0/0.1@lasote/stable", ignore_error=True) self._check(error, client)
def test_export_a_new_version(self): self._create_packages_and_builds() # Export an update of the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") files2[CONANFILE] = "# insert comment\n %s" % files2[CONANFILE] conan2.save(files2) conan2.run("export lasote/stable") reg_path3 = conan2.paths.export(self.conan_ref) digest3 = FileTreeManifest.loads( load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertIn( '%s: A new conanfile.py version was exported' % str(self.conan_ref), self.conan.user_io.out) self.assertIn('%s: Folder: %s' % (str(self.conan_ref), reg_path3), self.conan.user_io.out) self.assertTrue(os.path.exists(reg_path3)) for name in list(files2.keys()): self.assertTrue(os.path.exists(os.path.join(reg_path3, name))) expected_sums = { 'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': '6b19dfd1241712a6c694c7c397f909ce', 'executable': '68b329da9893e34099c7d8ad5cb9c940', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, digest3.file_sums)
def _test_with_conanfile(self, test_conanfile): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") print_build = 'self.output.warn("BUILD_TYPE=>%s" % self.settings.build_type)' files[CONANFILE] = files[CONANFILE].replace("def build(self):", 'def build(self):\n %s' % print_build) # Add build_type setting files[CONANFILE] = files[CONANFILE].replace(', "arch"', ', "arch", "build_type"') cmakelist = """PROJECT(MyHello) cmake_minimum_required(VERSION 2.8) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() ADD_EXECUTABLE(greet main.cpp) TARGET_LINK_LIBRARIES(greet ${CONAN_LIBS}) """ files["test_package/CMakeLists.txt"] = cmakelist files["test_package/conanfile.py"] = test_conanfile files["test_package/main.cpp"] = files["main.cpp"] client.save(files) client.run("export lasote/stable") error = client.run("test -s build_type=Release") self.assertFalse(error) self.assertNotIn("Project: WARN: conanbuildinfo.txt file not found", client.user_io.out) self.assertNotIn("Project: WARN: conanenv.txt file not found", client.user_io.out) self.assertIn('Hello Hello0', client.user_io.out) error = client.run("test -s Hello0:build_type=Debug -o Hello0:language=1") self.assertFalse(error) self.assertIn('Hola Hello0', client.user_io.out) self.assertIn('BUILD_TYPE=>Debug', client.user_io.out)
def test_command_user(self): """ Test that the user can be shown and changed, and it is reflected in the user cache localdb """ client = TestClient() client.run('user', ignore_error=True) self.assertIn("ERROR: No default remote defined", client.user_io.out)
def scopes_test_package_test(self): client = TestClient() conanfile = """ from conans import ConanFile class HelloConan(ConanFile): name = "Hello" version = "0.1" def build(self): self.output.info("Scope: %s" % self.scope) """ test_conanfile = """ from conans import ConanFile, CMake import os class HelloReuseConan(ConanFile): requires = "Hello/0.1@lasote/stable" def test(self): self.conanfile_directory """ client.save({"conanfile.py": conanfile, "test/conanfile.py": test_conanfile}) client.run("test_package --scope Hello:dev=True --build=missing") self.assertIn("Hello/0.1@lasote/stable: Scope: dev=True", client.user_io.out)
def test_no_remotes(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") client.save(files) client.run("export lasote/stable") client.run("upload Hello0/0.1@lasote/stable", ignore_error=True) self.assertIn("ERROR: No default remote defined", client.user_io.out)
def local_flow_test(self): """Use 'conan package' to process locally the package method""" client = TestClient() conanfile_template = """ from conans import ConanFile class MyConan(ConanFile): def package(self): self.copy(pattern="*.h", dst="include", src="include") """ files = {"include/file.h": "foo", CONANFILE: conanfile_template} client.save(files) origin_folder = client.current_folder client.run("install -g env -g txt") client.run("source") client.run("build") client.run("package .", ignore_error=True) self.assertIn("ERROR: Cannot 'conan package' to the build folder", client.user_io.out) package_folder = os.path.join(origin_folder, "package") mkdir(package_folder) client.current_folder = package_folder client.run('package ..') content = load(os.path.join(client.current_folder, "include/file.h")) self.assertEqual(content, "foo")
def test_with_remote_no_connect(self): test_server = TestServer() client = TestClient(servers={"default": test_server}) client.run('user') self.assertIn("Current 'default' user: None (anonymous)", client.user_io.out) client.run('user john') self.assertIn("Change 'default' user from None (anonymous) to john", client.user_io.out) self.assertEqual(('john', None), client.localdb.get_login(test_server.fake_url)) client.run('user will') self.assertIn("Change 'default' user from john to will", client.user_io.out) self.assertEqual(('will', None), client.localdb.get_login(test_server.fake_url)) client.run('user None') self.assertIn("Change 'default' user from will to None (anonymous)", client.user_io.out) self.assertEqual((None, None), client.localdb.get_login(test_server.fake_url)) client.run('user') self.assertIn("Current 'default' user: None (anonymous)", client.user_io.out)
def test_rel_path(self): base_folder = temp_folder() source_folder = os.path.join(base_folder, "source") current_folder = os.path.join(base_folder, "current") os.makedirs(current_folder) client = TestClient(current_folder=current_folder) files = cpp_hello_conan_files("Hello0", "0.1") conan_ref = ConanFileReference("Hello0", "0.1", "lasote", "stable") client.save(files, path=source_folder) client.run("export lasote/stable --path=../source") reg_path = client.paths.export(conan_ref) manif = FileTreeManifest.loads( load(client.paths.digestfile_conanfile(conan_ref))) self.assertIn( '%s: A new conanfile.py version was exported' % str(conan_ref), client.user_io.out) self.assertIn('%s: Folder: %s' % (str(conan_ref), reg_path), client.user_io.out) self.assertTrue(os.path.exists(reg_path)) for name in list(files.keys()): self.assertTrue(os.path.exists(os.path.join(reg_path, name))) expected_sums = { 'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': '05bd2ffe3ff0c35b3a1deede3264a8b6', 'executable': '68b329da9893e34099c7d8ad5cb9c940', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, manif.file_sums)
def test_complex_deps_propagation_override(self): client = TestClient() # Try injecting some package level ENV in the install, but without priority self._export(client, "A", [], {}, { "VAR1": "900", "VAR2": "23", "VAR3": "-23" }) self._export(client, "B", ["A"], {}, {"VAR1": "800", "VAR2": "24"}) self._export(client, "C", ["B"], {"VAR3": "bestvalue"}, {"VAR1": "700"}) client.save({"conanfile.py": reuse}) client.run("install . --build missing -e LIB_B:VAR3=override") self.assertIn("Building LIB_A, VAR1:None", client.user_io.out) self.assertIn("Building LIB_A, VAR2:None", client.user_io.out) self.assertIn("Building LIB_A, VAR3:None", client.user_io.out) self.assertIn("Building LIB_B, VAR1:900", client.user_io.out) self.assertIn("Building LIB_B, VAR2:23", client.user_io.out) self.assertIn("Building LIB_B, VAR3:override", client.user_io.out) self.assertIn("Building LIB_C, VAR1:800", client.user_io.out) self.assertIn("Building LIB_C, VAR2:24", client.user_io.out) self.assertIn("Building LIB_C, VAR3:-23", client.user_io.out) client.run("build") self.assertInSep("VAR1=>700:800:900", client.user_io.out) self.assertInSep("VAR2=>24:23*", client.user_io.out) self.assertInSep("VAR3=>bestvalue*", client.user_io.out)
def check_multi_server_test(self): # Check what happen if we have 2 servers and one is outdated # The expected behavior: If we specify the remote with (-r), the commmand will fail # if the client fot that remote is outdated. If we are just looking for a package (not with -r) # the client will look for the package on each remote. # Client deprecated for "the_last_server" but OK for "normal_server" self.servers = OrderedDict({"the_last_server": self._get_server(10, 4), "normal_server": self._get_server(4, 2)}) # First upload a package ok with an ok client tmp_client = TestClient(servers=self.servers, users=[("lasote", "mypass")], client_version=4) files = cpp_hello_conan_files("Hello0", "0.1") tmp_client.save(files) tmp_client.run("export lasote/stable") errors = tmp_client.run("upload Hello0/0.1@lasote/stable -r normal_server --all") errors |= tmp_client.run("upload Hello0/0.1@lasote/stable -r the_last_server --all") self.assertFalse(errors) # Now with a conflictive client...try to look in servers self.client = TestClient(servers=self.servers, users=[("lasote", "mypass")], client_version=2) errors = self.client.run("search something -r the_last_server", ignore_error=True) self.assertIn("Your conan's client version is deprecated for the current remote (v10). Upgrade conan client.", self.client.user_io.out) self.assertTrue(errors) # Errors errors = self.client.run("install Hello0/0.1@lasote/stable --build missing", ignore_error=True) self.assertIn("Your conan's client version is deprecated for the current remote (v10). Upgrade conan client.", self.client.user_io.out) self.assertFalse(errors) # No Errors! because it finds the package in the second remote
def _test_with_conanfile(self, test_conanfile): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") print_build = 'self.output.warn("BUILD_TYPE=>%s" % self.settings.build_type)' files[CONANFILE] = files[CONANFILE].replace("def build(self):", 'def build(self):\n %s' % print_build) # Add build_type setting files[CONANFILE] = files[CONANFILE].replace(', "arch"', ', "arch", "build_type"') cmakelist = """PROJECT(MyHello) cmake_minimum_required(VERSION 2.8) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() ADD_EXECUTABLE(greet main.cpp) TARGET_LINK_LIBRARIES(greet ${CONAN_LIBS}) """ files["test_package/CMakeLists.txt"] = cmakelist files["test_package/conanfile.py"] = test_conanfile files["test_package/main.cpp"] = files["main.cpp"] client.save(files) client.run("export lasote/stable") error = client.run("test -s build_type=Release") self.assertFalse(error) self.assertIn('Hello Hello0', client.user_io.out) error = client.run("test -s Hello0:build_type=Debug -o Hello0:language=1") self.assertFalse(error) self.assertIn('Hola Hello0', client.user_io.out) self.assertIn('BUILD_TYPE=>Debug', client.user_io.out)
def scopes_test_package_test(self): client = TestClient() conanfile = """ from conans import ConanFile class HelloConan(ConanFile): name = "Hello" version = "0.1" def build(self): self.output.info("Scope: %s" % self.scope) """ test_conanfile = """ from conans import ConanFile, CMake import os class HelloReuseConan(ConanFile): requires = "Hello/0.1@lasote/stable" def test(self): self.conanfile_directory """ client.save({ "conanfile.py": conanfile, "test/conanfile.py": test_conanfile }) client.run("test_package --scope Hello:dev=True --build=missing") self.assertIn("Hello/0.1@lasote/stable: Scope: dev=True", client.user_io.out)
def change_option_txt_test(self): self._create("Hello0", "0.1") client = TestClient(base_folder=self.client.base_folder) files = {CONANFILE_TXT: """[requires] Hello0/0.1@lasote/stable [options] Hello0:language=1 """} client.save(files) client.run("install %s --build missing" % self.settings) info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("", conan_info.options.dumps()) self.assertIn("Hello0:language=1", conan_info.full_options.dumps()) self.assertIn("Hello0/0.1@lasote/stable:8b964e421a5b7e48b7bc19b94782672be126be8b", conan_info.full_requires.dumps()) files = {CONANFILE_TXT: """[requires] Hello0/0.1@lasote/stable [options] Hello0:language=0 """} client.save(files) client.run("install %s --build missing" % self.settings) info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("", conan_info.options.dumps()) self.assertIn("Hello0:language=0", conan_info.full_options.dumps()) self.assertIn("Hello0/0.1@lasote/stable:2e38bbc2c3ef1425197c8e2ffa8532894c347d26", conan_info.full_requires.dumps())
def copy_error_test(self): client = TestClient() conanfile = ''' from conans import ConanFile class HelloConan(ConanFile): name = "Hello" version = "0.1" exports = "*" def package(self): self.copy2("*.h", dst="include", src=["include","platform"]) ''' files = {"conanfile.py": conanfile, "test.txt": "Hello world"} client.save(files) client.run("export lasote/stable") client.run("install Hello/0.1@lasote/stable --build", ignore_error=True) self.assertIn( "Hello/0.1@lasote/stable: Error in package() method, line 9", client.user_io.out) self.assertIn( 'self.copy2("*.h", dst="include", src=["include","platform"]', client.user_io.out) self.assertIn("'HelloConan' object has no attribute 'copy2'", client.user_io.out)
def test_export_the_same_code(self): file_list = self._create_packages_and_builds() # Export the same conans conan2 = TestClient(self.conan.base_folder) files2 = cpp_hello_conan_files("Hello0", "0.1") conan2.save(files2) conan2.run("export lasote/stable") reg_path2 = conan2.paths.export(self.conan_ref) digest2 = FileTreeManifest.loads(load(conan2.paths.digestfile_conanfile(self.conan_ref))) self.assertNotIn('A new Conan version was exported', conan2.user_io.out) self.assertNotIn('Cleaning the old builds ...', conan2.user_io.out) self.assertNotIn('Cleaning the old packs ...', conan2.user_io.out) self.assertNotIn('All the previous packs were cleaned', conan2.user_io.out) self.assertIn('%s: conanfile.py exported to local storage' % str(self.conan_ref), self.conan.user_io.out) self.assertIn('%s: Folder: %s' % (str(self.conan_ref), reg_path2), self.conan.user_io.out) self.assertTrue(os.path.exists(reg_path2)) for name in files2.keys(): self.assertTrue(os.path.exists(os.path.join(reg_path2, name))) expected_sums = {'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': 'f21a98d974e9294b0d709070042c6e78', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, digest2.file_sums) for f in file_list: self.assertTrue(os.path.exists(f))
def test_path(self): base_folder = temp_folder() source_folder = os.path.join(base_folder, "source") current_folder = os.path.join(base_folder, "current") client = TestClient(current_folder=current_folder) files = cpp_hello_conan_files("Hello0", "0.1") conan_ref = ConanFileReference("Hello0", "0.1", "lasote", "stable") conanfile = files.pop("conanfile.py") client.save(files, path=source_folder) conanfile = conanfile.replace("exports = '*'", 'exports = "../source*"') client.save({"conanfile.py": conanfile}) client.run("export lasote/stable") reg_path = client.paths.export(conan_ref) manif = FileTreeManifest.loads(load(client.paths.digestfile_conanfile(conan_ref))) self.assertIn('%s: A new conanfile.py version was exported' % str(conan_ref), client.user_io.out) self.assertIn('%s: Folder: %s' % (str(conan_ref), reg_path), client.user_io.out) self.assertTrue(os.path.exists(reg_path)) for name in ['conanfile.py', 'conanmanifest.txt', 'source/main.cpp', 'source/executable', 'source/hello.cpp', 'source/CMakeLists.txt', 'source/helloHello0.h']: self.assertTrue(os.path.exists(os.path.join(reg_path, name))) expected_sums = {'source/hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'source/main.cpp': '0479f3c223c9a656a718f3148e044124', 'source/CMakeLists.txt': 'bc3405da4bb0b51a3b9f05aca71e58c8', 'conanfile.py': 'c0bb94a3da6eb978cb94f5faff037ed3', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, manif.file_sums)
def list_test(self): client = TestClient() create_profile(client.client_cache.profiles_path, "profile1") create_profile(client.client_cache.profiles_path, "profile2") create_profile(client.client_cache.profiles_path, "profile3") client.run("profile list") self.assertEqual(set(["profile1", "profile2", "profile3"]), set(str(client.user_io.out).splitlines()))
class InfoTest(unittest.TestCase): def _create(self, number, version, deps=None, export=True): files = cpp_hello_conan_files(number, version, deps) # To avoid building files = {CONANFILE: files[CONANFILE].replace("build(", "build2(")} self.client.save(files, clean_first=True) if export: self.client.run("export lasote/stable") expected_output = textwrap.dedent( """\ WARN: Conanfile doesn't have 'url'. It is recommended to add your repo URL as attribute WARN: Conanfile doesn't have a 'license'. It is recommended to add the package license as attribute""") self.assertIn(expected_output, self.client.user_io.out) files[CONANFILE] = files[CONANFILE].replace('version = "0.1"', 'version = "0.1"\n' ' url= "myurl"\n' ' license = "MIT"') self.client.save(files) if export: self.client.run("export lasote/stable") self.assertNotIn("WARN: Conanfile doesn't have 'url'", self.client.user_io.out) def reuse_test(self): self.client = TestClient() self._create("Hello0", "0.1") self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False) self.client.run("info") expected_output = textwrap.dedent( """\ Hello2/0.1@PROJECT URL: myurl License: MIT Requires: Hello1/0.1@lasote/stable Hello0/0.1@lasote/stable Remote: None URL: myurl License: MIT Updates: You have the latest version (None) Required by: Hello1/0.1@lasote/stable Hello1/0.1@lasote/stable Remote: None URL: myurl License: MIT Updates: You have the latest version (None) Required by: Hello2/0.1@PROJECT Requires: Hello0/0.1@lasote/stable""") self.assertIn(expected_output, self.client.user_io.out)
class BasicBuildTest(unittest.TestCase): def setUp(self): self.client = TestClient() self.command = os.sep.join([".", "bin", "say_hello"]) def _build(self, cmd, static, pure_c, use_cmake, lang): dll_export = self.client.default_compiler_visual_studio and not static files = cpp_hello_conan_files("Hello0", "0.1", dll_export=dll_export, pure_c=pure_c, use_cmake=use_cmake) self.client.save(files, clean_first=True) self.client.run(cmd) time.sleep(1) # necessary so the conaninfo.txt is flushed to disc self.client.run('build') ld_path = ("LD_LIBRARY_PATH=$(pwd)" if not static and not platform.system() == "Windows" else "") self.client.runner("%s %s" % (ld_path, self.command), cwd=self.client.current_folder) msg = "Hello" if lang == 0 else "Hola" self.assertIn("%s Hello0" % msg, self.client.user_io.out) conan_info_path = os.path.join(self.client.current_folder, CONANINFO) conan_info = ConanInfo.loads(load(conan_info_path)) self.assertTrue(conan_info.full_options.language == lang) if static: self.assertTrue(conan_info.full_options.static) else: self.assertFalse(conan_info.full_options.static) def build_cmake_test(self): for pure_c in (False, True): for cmd, lang, static in [("install", 0, True), ("install -o language=1", 1, True), ("install -o language=1 -o static=False", 1, False), ("install -o static=False", 0, False)]: self._build(cmd, static, pure_c, use_cmake=True, lang=lang) def build_default_test(self): "build default (gcc in nix, VS in win)" for pure_c in (False, True): for cmd, lang, static in [("install", 0, True), ("install -o language=1", 1, True), ("install -o language=1 -o static=False", 1, False), ("install -o static=False", 0, False)]: self._build(cmd, static, pure_c, use_cmake=False, lang=lang) def build_mingw_test(self): if platform.system() != "Windows": return not_env = os.system("g++ --version > nul") if not_env != 0: logger.error("This platform does not support G++ command") return install = "install -s compiler=gcc -s compiler.libcxx=libstdc++ -s compiler.version=4.9" for pure_c in (False, True): for cmd, lang, static in [(install, 0, True), (install + " -o language=1", 1, True), (install + " -o language=1 -o static=False", 1, False), (install + " -o static=False", 0, False)]: self._build(cmd, static, pure_c, use_cmake=False, lang=lang)
class OrderLibsTest(unittest.TestCase): def setUp(self): self.client = TestClient() def _export(self, name, deps=None, export=True): def _libs(): if name == "LibPNG": libs = '"m"' elif name == "SDL2": libs = '"m", "rt", "pthread", "dl"' else: libs = "" return libs deps = ", ".join(['"%s/1.0@lasote/stable"' % d for d in deps or []]) or '""' conanfile = """ from conans import ConanFile, CMake class HelloReuseConan(ConanFile): name = "%s" version = "1.0" requires = %s generators = "txt", "cmake" def package_info(self): self.cpp_info.libs = ["%s", %s] """ % ( name, deps, name, _libs(), ) files = {CONANFILE: conanfile} self.client.save(files, clean_first=True) if export: self.client.run("export lasote/stable") def reuse_test(self): self._export("ZLib") self._export("BZip2") self._export("SDL2", ["ZLib"]) self._export("LibPNG", ["ZLib"]) self._export("freeType", ["BZip2", "LibPNG"]) self._export("SDL2_ttf", ["freeType", "SDL2"]) self._export("MyProject", ["SDL2_ttf"], export=False) self.client.run("install . --build missing") self.assertIn("PROJECT: Generated conaninfo.txt", self.client.user_io.out) expected_libs = ["SDL2_ttf", "SDL2", "rt", "pthread", "dl", "freeType", "BZip2", "LibPNG", "m", "ZLib"] conanbuildinfo = load(os.path.join(self.client.current_folder, "conanbuildinfo.txt")) libs = os.linesep.join(expected_libs) self.assertIn(libs, conanbuildinfo) conanbuildinfo = load(os.path.join(self.client.current_folder, "conanbuildinfo.cmake")) libs = " ".join(expected_libs) self.assertIn(libs, conanbuildinfo)
def basic_test(self): hello_files = cpp_hello_conan_files("Hello") client = TestClient() client.save(hello_files) client.run("export lasote/stable") path = os.path.join(client.storage_folder, "Hello/0.1/lasote/stable") self.assertTrue(os.path.exists(path)) client.run("remove Hello* -f") path = os.path.join(client.storage_folder, "Hello") self.assertFalse(os.path.exists(path))
def reuse_test(self): conan_reference = ConanFileReference.loads("stringutil/0.1@lasote/stable") files = {'conanfile.py': stringutil_conanfile, 'reverse.go': reverse, 'reverse_test.go': reverse_test, 'reverse.txt': reverse, 'hello/helloreverse.txt': reverse} self.client.save(files) self.client.run("export lasote/stable") self.client.run("install %s --build missing" % str(conan_reference)) # Check compilation ok package_ids = self.client.paths.conan_packages(conan_reference) self.assertEquals(len(package_ids), 1) package_ref = PackageReference(conan_reference, package_ids[0]) self._assert_package_exists(package_ref, self.client.paths, files.keys()) # Upload conans self.client.run("upload %s" % str(conan_reference)) # Check that conans exists on server server_paths = self.servers["default"].paths conan_path = server_paths.export(conan_reference) self.assertTrue(os.path.exists(conan_path)) # Upload package self.client.run("upload %s -p %s" % (str(conan_reference), str(package_ids[0]))) # Check library on server self._assert_package_exists_in_server(package_ref, server_paths, files.keys()) # Now from other "computer" install the uploaded conans with same options (nothing) other_conan = TestClient(servers=self.servers, users=[("lasote", "mypass")]) other_conan.run("install %s --build missing" % str(conan_reference)) # Build should be empty build_path = other_conan.paths.build(package_ref) self.assertFalse(os.path.exists(build_path)) # Lib should exist self._assert_package_exists(package_ref, other_conan.paths, files.keys()) reuse_conan = TestClient(servers=self.servers, users=[("lasote", "mypass")]) files = {'conanfile.py': reuse_conanfile, 'src/hello/main.go': main} reuse_conan.save(files) reuse_conan.run("install --build missing") with CustomEnvPath(paths_to_add=['$GOPATH/bin'], var_to_add=[('GOPATH', reuse_conan.current_folder), ]): if platform.system() == "Windows": command = "hello" else: command = './hello' reuse_conan.runner('go install hello', reuse_conan.current_folder) reuse_conan.runner(command, os.path.join(reuse_conan.current_folder, 'bin')) self.assertIn("Hello, Go!", reuse_conan.user_io.out)
def new_without_test(self): """ Test that the user can be shown and changed, and it is reflected in the user cache localdb """ client = TestClient() client.run('new MyPackage/1.3@myuser/testing') root = client.current_folder self.assertTrue(os.path.exists(os.path.join(root, "conanfile.py"))) self.assertFalse(os.path.exists(os.path.join(root, "test_package/conanfile.py"))) self.assertFalse(os.path.exists(os.path.join(root, "test_package/CMakeLists.txt"))) self.assertFalse(os.path.exists(os.path.join(root, "test_package/example.cpp")))
def setUp(self): hello_files = cpp_hello_conan_files("Hello") test_conanfile_contents = hello_files[CONANFILE] self.server_folder = temp_folder() test_server = TestServer(users={"fenix": "mypass"}, base_path=self.server_folder) # exported users and passwords self.server = test_server servers = {"default": test_server} client = TestClient(servers=servers, users={"default": [("fenix", "mypass")]}) # Conans with and without packages created self.root_folder = {"H1": 'Hello/1.4.10/fenix/testing', "H2": 'Hello/2.4.11/fenix/testing', "B": 'Bye/0.14/fenix/testing', "O": 'Other/1.2/fenix/testing'} files = {} pack_refs = [] for key, folder in self.root_folder.items(): ref = ConanFileReference.loads(folder) files["%s/%s/conanfile.py" % (folder, EXPORT_FOLDER)] = test_conanfile_contents files["%s/%s/conanmanifest.txt" % (folder, EXPORT_FOLDER)] = "" files["%s/%s/conans.txt" % (folder, SRC_FOLDER)] = "" for pack_id in (1, 2): pack_id = "%s_%s" % (pack_id, key) pack_refs.append(PackageReference(ref, str(pack_id))) files["%s/%s/%s/conans.txt" % (folder, BUILD_FOLDER, pack_id)] = "" files["%s/%s/%s/conans.txt" % (folder, PACKAGES_FOLDER, pack_id)] = "" files["%s/%s/%s/%s" % (folder, PACKAGES_FOLDER, pack_id, CONANINFO)] = "" files["%s/%s/%s/%s" % (folder, PACKAGES_FOLDER, pack_id, CONAN_MANIFEST)] = "" client.save(files, client.client_cache.store) # Create the manifests to be able to upload for pack_ref in pack_refs: digest_path = client.client_cache.digestfile_package(pack_ref) expected_manifest = FileTreeManifest.create(os.path.dirname(digest_path)) files["%s/%s/%s/%s" % ("/".join(pack_ref.conan), PACKAGES_FOLDER, pack_ref.package_id, CONAN_MANIFEST)] = str(expected_manifest) client.save(files, client.client_cache.store) self.client = client for folder in self.root_folder.values(): client.run("upload %s --all" % folder.replace("/fenix", "@fenix")) self.assert_folders({"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]}, {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]}, {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]}, {"H1": True, "H2": True, "B": True, "O": True})