def install_outdated_and_dep_test(self): # regression test for https://github.com/conan-io/conan/issues/1053 # A new recipe that depends on Hello0/0.1 new_client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], build=False) new_client.save(files) new_client.run("export lasote/stable") self.assertIn("A new conanfile.py version was exported", new_client.user_io.out) # It will retrieve from the remote Hello0 and build Hello1 new_client.run("install Hello1/0.1@lasote/stable --build missing") # Then modify REMOTE Hello0 recipe files (WITH THE OTHER CLIENT) files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = files["conanfile.py"] + "\n#MODIFIED RECIPE" self.client.save(files) self.client.run("export lasote/stable") self.assertIn("A new conanfile.py version was exported", self.client.user_io.out) self.client.run("install Hello0/0.1@lasote/stable --build missing") # Upload only the recipe, so the package is outdated in the server self.client.run("upload Hello0/0.1@lasote/stable") # Now, with the new_client, remove only the binary package from Hello0 rmdir(new_client.paths.packages(self.ref)) # And try to install Hello1 again, should not complain because the remote # binary is in the "same version" than local cached Hello0 new_client.run("install Hello1/0.1@lasote/stable --build outdated --build Hello1") self.assertIn("Downloading conan_package.tgz", new_client.user_io.out) self.assertIn("Hello1/0.1@lasote/stable: WARN: Forced build from source", new_client.user_io.out)
def test_cross_remotes(self): # Upload to alternative server Hello0 but Hello1 to the default files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False) self.client.save(files) self.client.run("export . lasote/stable") files = cpp_hello_conan_files("Hello1", "1.0", deps=["Hello0/1.0@lasote/stable"], build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("export . lasote/stable") self.client.run("install Hello1/1.0@lasote/stable --build missing") self.client.run("upload 'Hello0*' -c --all -r alternative") self.client.run("upload 'Hello1*' -c --all -r default") trace_file = os.path.join(temp_folder(), "conan_trace.log") with tools.environment_append({"CONAN_TRACE_FILE": trace_file}): # Will retrieve the Hello0 deps from the alternative self.client.run("install Hello1/1.0@lasote/stable --build") # Upload to the default, not matching the Hello0 remote self.client.run("upload 'Hello1*' -c --all -r default") data = get_build_info(trace_file).serialize() self.assertEquals(len(data["modules"]), 2) module = _get_module(data, "Hello1/1.0@lasote/stable") self.assertEquals(0, len(module["dependencies"]))
def install_from_remotes_test(self): for i in range(3): conan_reference = ConanFileReference.loads("Hello%d/0.1@lasote/stable" % i) files = cpp_hello_conan_files("Hello%d" % i, "0.1", build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("upload %s -r=remote%d" % (str(conan_reference), i)) self.client.run("info %s" % str(conan_reference)) self.assertIn("remote%d=http://" % i, self.client.user_io.out) # Now install it in other machine from remote 0 client2 = TestClient(servers=self.servers, users=self.users) files = cpp_hello_conan_files("HelloX", "0.1", deps=["Hello0/0.1@lasote/stable", "Hello1/0.1@lasote/stable", "Hello2/0.1@lasote/stable"]) files["conanfile.py"] = files["conanfile.py"].replace("def build(", "def build2(") client2.save(files) client2.run("install . --build=missing") self.assertIn("Hello0/0.1@lasote/stable from 'remote0'", client2.user_io.out) self.assertIn("Hello1/0.1@lasote/stable from 'remote1'", client2.user_io.out) self.assertIn("Hello2/0.1@lasote/stable from 'remote2'", client2.user_io.out) client2.run("info .") self.assertIn("Remote: remote0=http://", client2.user_io.out) self.assertIn("Remote: remote1=http://", client2.user_io.out) self.assertIn("Remote: remote2=http://", client2.user_io.out)
def test_test_framework(self): client = TestClient() files = cpp_hello_conan_files("Test0") client.save(files, clean_first=True) client.run("export . lasote/stable") files = cpp_hello_conan_files("Test1", deps=["Test0/0.1@lasote/stable"]) client.save(files, clean_first=True) client.run("export . lasote/stable") # client.run("install Test1/0.1@lasote/stable --build=missing") client.save({"conanfile.py": conanfile, "test.cpp": test, "CMakeLists.txt": cmake, "profile.txt": test_profile}, clean_first=True) client.run("export . lasote/stable") client.run("install MyLib/0.1@lasote/stable --build=missing") self.assertIn("MyLib/0.1@lasote/stable: Generating the package", client.user_io.out) self.assertNotIn("100% tests passed", client.user_io.out) self.assertNotIn("Test0/0.1@lasote/stable", client.user_io.out) self.assertNotIn("Test1/0.1@lasote/stable", client.user_io.out) client.run("install MyLib/0.1@lasote/stable -pr=./profile.txt --build") self.assertIn("MyLib/0.1@lasote/stable: Generating the package", client.user_io.out) self.assertIn("Test0/0.1@lasote/stable", client.user_io.out) self.assertIn("Test1/0.1@lasote/stable", client.user_io.out) self.assertIn("100% tests passed", client.user_io.out)
def large_project_test(self): client = TestClient() num = 250 deep = True # True for N ... -> 3 -> 2 -> 1 -> 0, False for N -> 0, 3-> 0, 2->0, 1->0 for i in range(num): if i == 0: files = cpp_hello_conan_files("Hello0", "0.1", build=False) else: if not deep: files = cpp_hello_conan_files("Hello%d" % i, "0.1", ["Hello0/0.1@lasote/stable"], build=False) else: files = cpp_hello_conan_files("Hello%d" % i, "0.1", ["Hello%s/0.1@lasote/stable" % (i-1)], build=False) client.save(files, clean_first=True) client.run("export lasote/stable") # Now lets depend on it if deep: files = cpp_hello_conan_files("HelloFinal", "0.1", ["Hello%s/0.1@lasote/stable" % (num - 1)], build=False) else: files = cpp_hello_conan_files("HelloFinal", "0.1", ["Hello%s/0.1@lasote/stable" % (i) for i in range(num)], build=False) client.save(files, clean_first=True) t1 = time.time() client.run("install --build") print("Final time with build %s" % (time.time() - t1)) t1 = time.time() client.run("install") print("Final time %s" % (time.time() - t1))
def install_outdated_dep_test(self): # A new recipe that depends on Hello0/0.1 new_client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], build=False) new_client.save(files) new_client.run("export . lasote/stable") self.assertIn("A new conanfile.py version was exported", new_client.user_io.out) # It will retrieve from the remote Hello0 and build Hello1 new_client.run("install Hello1/0.1@lasote/stable --build missing") # Then modify REMOTE Hello0 recipe files (WITH THE OTHER CLIENT) files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = files["conanfile.py"] + "\n#MODIFIED RECIPE" self.client.save(files) self.client.run("export . lasote/stable") self.assertIn("A new conanfile.py version was exported", self.client.user_io.out) self.client.run("install Hello0/0.1@lasote/stable --build missing") # Upload only the recipe, so the package is outdated in the server self.client.run("upload Hello0/0.1@lasote/stable") # Now, with the new_client, remove only the binary package from Hello0 rmdir(new_client.paths.packages(self.ref)) # And try to install Hello1 again, should not complain because the remote # binary is in the "same version" than local cached Hello0 new_client.run("install Hello1/0.1@lasote/stable --build outdated") self.assertIn("Downloading conan_package.tgz", new_client.user_io.out) self.assertIn("Hello0/0.1@lasote/stable: Package is up to date", new_client.user_io.out) # But if we remove the full Hello0 local package, will retrieve the updated # recipe and the outdated package new_client.run("remove Hello0* -f") new_client.run("install Hello1/0.1@lasote/stable --build outdated") self.assertIn("Hello0/0.1@lasote/stable: Outdated package!", new_client.user_io.out) self.assertIn("Hello0/0.1@lasote/stable: Building your package", new_client.user_io.out)
def update_not_date_test(self): # Regression for https://github.com/conan-io/conan/issues/949 files0 = cpp_hello_conan_files("Hello0", "1.0", build=False) files0["conanfile.py"] = files0["conanfile.py"].replace("settings = ", "# settings = ") self.client.save(files0) self.client.run("export lasote/stable") files1 = cpp_hello_conan_files("Hello1", "1.0", build=False, deps=["Hello0/1.0@lasote/stable"]) self.client.save(files1, clean_first=True) self.client.run("install --build") self.client.run("upload Hello0/1.0@lasote/stable --all") ref = ConanFileReference.loads("Hello0/1.0@lasote/stable") package_ref = PackageReference(ref, "55a3af76272ead64e6f543c12ecece30f94d3eda") recipe_manifest = self.client.client_cache.digestfile_conanfile(ref) package_manifest = self.client.client_cache.digestfile_package(package_ref) def timestamps(): recipe_timestamp = load(recipe_manifest).splitlines()[0] package_timestamp = load(package_manifest).splitlines()[0] return recipe_timestamp, package_timestamp initial_timestamps = timestamps() import time time.sleep(1) # Change and rebuild package files0["helloHello0.h"] = files0["helloHello0.h"] + " // useless comment" self.client.save(files0, clean_first=True) self.client.run("export lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") rebuild_timestamps = timestamps() self.assertNotEqual(rebuild_timestamps, initial_timestamps) # back to the consumer, try to update self.client.save(files1, clean_first=True) self.client.run("install --update") self.assertIn("ERROR: Current conanfile is newer than myremote's one", self.client.user_io.out) failed_update_timestamps = timestamps() self.assertEqual(rebuild_timestamps, failed_update_timestamps) # hack manifests, put old time for manifest_file in (recipe_manifest, package_manifest): manifest = load(manifest_file) lines = manifest.splitlines() lines[0] = "123" save(manifest_file, "\n".join(lines)) self.client.run("install --update") update_timestamps = timestamps() self.assertEqual(update_timestamps, initial_timestamps)
def dual_compiler_settings_and_env_test(self): def patch_conanfile(conanfile): return conanfile + ''' def build(self): import os self.output.warn("COMPILER: %s=>%s" % (self.name, self.settings.compiler)) self.output.warn("CXX: %s=>%s" % (self.name, os.environ["CXX"])) self.output.warn("CC: %s=>%s" % (self.name, os.environ["CC"])) ''' client = TestClient() files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False) files[CONANFILE] = patch_conanfile(files[CONANFILE]) client.save(files) client.run("export lasote/stable") files = cpp_hello_conan_files("Hello1", "1.0", deps=["Hello0/1.0@lasote/stable"], build=False) files[CONANFILE] = patch_conanfile(files[CONANFILE]) client.save(files) client.run("export lasote/stable") # Both with same settings client.run("install Hello1/1.0@lasote/stable --build -s compiler=gcc" " -s compiler.version=4.6 -s compiler.libcxx=libstdc++11" " -e CXX=/mycompilercxx -e CC=/mycompilercc") self.assertIn("COMPILER: Hello0=>gcc", client.user_io.out) self.assertIn("CXX: Hello0=>/mycompilercxx", client.user_io.out) self.assertIn("CC: Hello0=>/mycompilercc", client.user_io.out) self.assertIn("COMPILER: Hello1=>gcc", client.user_io.out) self.assertIn("CXX: Hello1=>/mycompilercxx", client.user_io.out) self.assertIn("CC: Hello1=>/mycompilercc", client.user_io.out) # Different for Hello0 client.run("install Hello1/1.0@lasote/stable --build -s compiler=gcc" " -s compiler.version=4.6 -s compiler.libcxx=libstdc++11" " -e CXX=/mycompilercxx -e CC=/mycompilercc" " -s Hello0:compiler=clang -s Hello0:compiler.version=3.7" " -s Hello0:compiler.libcxx=libstdc++" " -e Hello0:CXX=/othercompilercxx -e Hello0:CC=/othercompilercc") self.assertIn("COMPILER: Hello0=>clang", client.user_io.out) self.assertIn("CXX: Hello0=>/othercompilercxx", client.user_io.out) self.assertIn("CC: Hello0=>/othercompilercc", client.user_io.out) self.assertIn("COMPILER: Hello1=>gcc", client.user_io.out) self.assertIn("CXX: Hello1=>/mycompilercxx", client.user_io.out) self.assertIn("CC: Hello1=>/mycompilercc", client.user_io.out)
def reuse_test(self): conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1") client = TestClient() client.save(files) client.run("export lasote/stable") configs = [] # ("gcc", "4.8")] # Place to add different compilers if platform.system() == "Windows2": configs.append(("Visual Studio", "12")) for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.run("install %s --build missing" % str(conan_reference)) # Check compilation ok package_ids = client.paths.conan_packages(conan_reference) self.assertEquals(len(package_ids), len(configs)) for package_id in package_ids: package_ref = PackageReference(conan_reference, package_id) self._assert_library_exists(package_ref, client.paths) # Reuse them conan_reference = ConanFileReference.loads("Hello1/0.2@lasote/stable") files3 = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) client.current_folder = temp_folder() client.save(files3) for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.run('install') client.run('build') command = os.sep.join([".", "bin", "say_hello"]) client.runner(command, cwd=client.current_folder) self.assertIn("Hello Hello1", client.user_io.out) self.assertIn("Hello Hello0", client.user_io.out) new_conanfile = files3[CONANFILE].replace('"language": 0', '"language": 1') for compiler, compiler_version in configs: client.default_settings(compiler, compiler_version) client.save({CONANFILE: new_conanfile}) client.run('install') client.run('build') time.sleep(1) client.runner(command, cwd=client.current_folder) self.assertIn("Hola Hello1", client.user_io.out) self.assertIn("Hola Hello0", client.user_io.out)
def test_json_generation(self): files = cpp_hello_conan_files("CC", "1.0", build=False) self.client.save(files, clean_first=True) self.client.run("create . private_user/channel --json=myfile.json ") self.client.run('upload "*" -c --all') files = cpp_hello_conan_files("BB", "1.0", build=False) files["conanfile.py"] += """ def configure(self): self.options["CC"].static = False def build_requirements(self): self.build_requires("CC/1.0@private_user/channel") """ self.client.save(files, clean_first=True) self.client.run("create . private_user/channel --build missing") self.client.run('upload "*" -c --all') files = cpp_hello_conan_files("AA", "1.0", deps=["BB/1.0@private_user/channel"], build=False) self.client.save(files, clean_first=True) self.client.run("create . private_user/channel") self.client.run('upload "*" -c --all') save(os.path.join(self.client.client_cache.profiles_path, "mybr"), """ include(default) [build_requires] AA*: CC/1.0@private_user/channel """) files = cpp_hello_conan_files("PROJECT", "1.0", deps=["AA/1.0@private_user/channel"], build=False) self.client.save(files, clean_first=True) self.client.run("install . --profile mybr --json=myfile.json --build AA --build BB") my_json = load(os.path.join(self.client.current_folder, "myfile.json")) my_json = json.loads(my_json) self.assertTrue(my_json["installed"][0]["recipe"]["dependency"]) self.assertTrue(my_json["installed"][1]["recipe"]["dependency"]) self.assertTrue(my_json["installed"][2]["recipe"]["dependency"]) # Installed the build require CC with two options self.assertEquals(len(my_json["installed"][2]["packages"]), 2) self.assertEquals(my_json["installed"][2]["recipe"]["id"], "CC/1.0@private_user/channel") self.assertTrue(my_json["installed"][2]["recipe"]["cache"]) self.assertTrue(my_json["installed"][2]["packages"][0]["cache"]) self.assertTrue(my_json["installed"][2]["packages"][1]["cache"])
def upper_option_txt_test(self): self._create("Hello0", "0.1", no_config=True) self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True) files = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"]) files.pop(CONANFILE) files[CONANFILE_TXT] = """[requires] Hello1/0.1@lasote/stable [options] Hello0:language=1 Hello1:language=0 """ self.client.save(files, clean_first=True) self.client.run("install %s --build missing" % self.settings) info_path = os.path.join(self.client.current_folder, CONANINFO) conan_info = ConanInfo.load_file(info_path) self.assertEqual("", conan_info.options.dumps()) conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") hello0 = self.client.paths.package(PackageReference(conan_ref, "8b964e421a5b7e48b7bc19b94782672be126be8b")) hello0_info = os.path.join(hello0, CONANINFO) hello0_conan_info = ConanInfo.load_file(hello0_info) self.assertEqual(1, hello0_conan_info.options.language) package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"), "44671ecdd9c606eb7166f2197ab50be8d36a3c3b") hello1 = self.client.paths.package(package_ref1) hello1_info = os.path.join(hello1, CONANINFO) hello1_conan_info = ConanInfo.load_file(hello1_info) self.assertEqual(0, hello1_conan_info.options.language)
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 _create(self, client, number, version, deps=None, export=True, modifier=""): files = cpp_hello_conan_files(number, version, deps, build=False) # To avoid building files = {CONANFILE: files[CONANFILE].replace("config(", "config2(") + modifier} client.save(files, clean_first=True) if export: client.run("export lasote/stable")
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 _export_upload(self, name=0, version=None, deps=None, msg=None, static=True): files = cpp_hello_conan_files(name, version, deps, msg=msg, static=static, private_includes=True) conan_ref = ConanFileReference(name, version, "lasote", "stable") self.client.save(files, clean_first=True) self.client.run("export lasote/stable") self.client.run("upload %s" % str(conan_ref))
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_run_environment(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") files[CONANFILE] = files[CONANFILE].replace('self.copy(pattern="*.so", dst="lib", keep_path=False)', '''self.copy(pattern="*.so", dst="lib", keep_path=False) self.copy(pattern="*say_hello*", dst="bin", keep_path=False)''') client.save(files) client.run("export . lasote/stable") reuse = ''' from conans import ConanFile, RunEnvironment, tools class HelloConan(ConanFile): name = "Reuse" version = "0.1" build_policy = "missing" requires = "Hello0/0.1@lasote/stable" def build(self): run_env = RunEnvironment(self) with tools.environment_append(run_env.vars): self.run("say_hello") ''' client.save({"conanfile.py": reuse}, clean_first=True) client.run("install . --build missing") client.run("build .")
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 test_conanfile_not_found(self): """If package is OpenSSL is not openssl""" test_server = TestServer() self.servers = {"default": test_server} self.client = TestClient(servers=self.servers, users={"default":[("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello0", "0.1") self.client.save(files) self.client.run("export lasote/stable") self.assertRaises(Exception, self.client.run, "install hello0/0.1@lasote/stable") self.client.run("install Hello0/0.1@lasote/stable --build missing") self.client.run("upload Hello0/0.1@lasote/stable") # Now with requirements.txt (bug in server) self.client = TestClient(servers=self.servers, users={"default":[("lasote", "mypass")]}) self.client.save({"conanfile.txt": "[requires]\nHello0/0.1@lasote/stable\n[generators]\ntxt"}) self.client.run("install --build missing ") build_info = load(os.path.join(self.client.current_folder, "conanbuildinfo.txt")) self.assertIn("helloHello0", build_info) self.client = TestClient(servers=self.servers, users={"default":[("lasote", "mypass")]}) self.client.save({"conanfile.txt": "[requires]\nhello0/0.1@lasote/stable\n[generators]\ntxt"}) self.assertRaises(Exception, self.client.run, "install")
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 upload_newer_recipe_test(self): servers = {} test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"}) servers["default"] = test_server client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello0", "1.2.1", build=False) client.save(files) client.run("export frodo/stable") client.run("install Hello0/1.2.1@frodo/stable --build=missing") client.run("upload Hello0/1.2.1@frodo/stable --all") client2 = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) client2.save(files) client2.run("export frodo/stable") ref = ConanFileReference.loads("Hello0/1.2.1@frodo/stable") manifest = client2.client_cache.load_manifest(ref) manifest.time += 10 save(client2.client_cache.digestfile_conanfile(ref), str(manifest)) client2.run("install Hello0/1.2.1@frodo/stable --build=missing") client2.run("upload Hello0/1.2.1@frodo/stable --all") self.assertNotIn("conanfile", client2.user_io.out) self.assertIn("Package is up to date.", client2.user_io.out) self.assertIn("Uploading conanmanifest.txt", client2.user_io.out) # Now try again with the other client, which timestamp is older client.run("upload Hello0/1.2.1@frodo/stable --all") self.assertNotIn("conanfile", client2.user_io.out) self.assertIn("Package is up to date.", client2.user_io.out) self.assertIn("Uploading conanmanifest.txt", client.user_io.out)
def trace_command_test(self): from conans.build_info.command import run trace_file = os.path.join(temp_folder(), "conan_trace.log") # Generate some traces with tools.environment_append({"CONAN_TRACE_FILE": trace_file}): files = cpp_hello_conan_files("Hello0", "1.0", deps=[], build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install Hello0/1.0@lasote/stable --build") self.client.run("upload '*' --all -c") # Get json from file output = os.path.join(temp_folder(), "build_info.json") sys.argv = ['conan_build_info', trace_file, '--output', output] run() the_json = json.loads(load(output)) self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable") # Now get from stdout sys.argv = ['conan_build_info', trace_file] run() try: # in IDEs or with --nocapture it will fail stdout_value = sys.stdout.getvalue() except AttributeError: pass else: the_json = json.loads(stdout_value) self.assertTrue(the_json["modules"][0]["id"], "Hello0/1.0@lasote/stable")
def setUp(self): self.client = TestClient() files = cpp_hello_conan_files(name="MinGWBuild", version="0.1", build=False) self._patch_build_to_print_compiler(files) self.client.save(files) self.client.run("export . lasote/testing")
def test_override(self): files = cpp_hello_conan_files(name="VisualBuild", version="0.1", build=False, deps=["MinGWBuild/0.1@lasote/testing"]) self._patch_build_to_print_compiler(files) self.client.save(files) self.client.run("export . lasote/testing") self.client.run("install VisualBuild/0.1@lasote/testing --build missing -s compiler='Visual Studio' " "-s compiler.version=14 -s compiler.runtime=MD " "-s MinGWBuild:compiler='gcc' -s MinGWBuild:compiler.libcxx='libstdc++' " "-s MinGWBuild:compiler.version=4.8") self.assertIn("COMPILER=> MinGWBuild gcc", self.client.user_io.out) self.assertIn("COMPILER=> VisualBuild Visual Studio", self.client.user_io.out) # CHECK CONANINFO FILE packs_dir = self.client.paths.packages(ConanFileReference.loads("MinGWBuild/0.1@lasote/testing")) pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0]) conaninfo = load(os.path.join(pack_dir, CONANINFO)) self.assertIn("compiler=gcc", conaninfo) # CHECK CONANINFO FILE packs_dir = self.client.paths.packages(ConanFileReference.loads("VisualBuild/0.1@lasote/testing")) pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0]) conaninfo = load(os.path.join(pack_dir, CONANINFO)) self.assertIn("compiler=Visual Studio", conaninfo) self.assertIn("compiler.version=14", conaninfo)
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': '52546396c42f16be3daf72ecf7ab7143', 'conanfile.py': '355949fbf0b4fc32b8f1c5a338dfe1ae', 'executable': '68b329da9893e34099c7d8ad5cb9c940', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, manif.file_sums)
def not_reupload_test(self): """ Check that if the package has not been modified, it is not uploaded again """ servers = {} test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"}) servers["default"] = test_server client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello0", "1.2.1", build=False) client.save(files) client.run("export frodo/stable") client.run("install Hello0/1.2.1@frodo/stable --build=missing") client.run("upload Hello0/1.2.1@frodo/stable -r default --all") self.assertIn("Uploading conan_package.tgz", client.user_io.out) client.run("remove Hello0/1.2.1@frodo/stable -f") client.run("search") self.assertNotIn("Hello0/1.2.1@frodo/stable", client.user_io.out) client.run("install Hello0/1.2.1@frodo/stable") self.assertIn("Downloading conan_package.tgz", client.user_io.out) client.run("upload Hello0/1.2.1@frodo/stable -r default --all") self.assertIn("Uploaded conan recipe", client.user_io.out) self.assertNotIn("Uploading conan_package.tgz", client.user_io.out) self.assertIn("Package is up to date", client.user_io.out)
def fail_when_not_notfound_test(self): """ If a remote fails with a 404 it has to keep looking in the next remote, but if it fails by any other reason it has to stop """ servers = OrderedDict() servers["s0"] = TestServer() servers["s1"] = TestServer() servers["s2"] = TestServer() client = TestClient(servers=servers, users=self.users) files = cpp_hello_conan_files("MyLib", "0.1", build=False) client.save(files) client.run("create . lasote/testing") client.run("user lasote -p mypass -r s1") client.run("upload MyLib* -r s1 -c") servers["s1"].fake_url = "http://asdlhaljksdhlajkshdljakhsd" # Do not exist client2 = TestClient(servers=servers, users=self.users) err = client2.run("install MyLib/0.1@conan/testing --build=missing", ignore_error=True) self.assertTrue(err) self.assertIn("MyLib/0.1@conan/testing: Trying with 's0'...", client2.out) self.assertIn("MyLib/0.1@conan/testing: Trying with 's1'...", client2.out) self.assertIn("Unable to connect to s1=http://asdlhaljksdhlajkshdljakhsd", client2.out) # s2 is not even tried self.assertNotIn("MyLib/0.1@conan/testing: Trying with 's2'...", client2.out)
def upload_test(self): conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1", build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("upload %s" % str(conan_reference)) self.client.run("info %s" % str(conan_reference)) self.assertIn("remote0=http://", self.client.user_io.out) # The remote, once fixed does not change self.client.run("upload %s -r=remote1" % str(conan_reference)) self.client.run("info %s" % str(conan_reference)) self.assertIn("remote0=http://", self.client.user_io.out) # Now install it in other machine from remote 0 client2 = TestClient(servers=self.servers, users=self.users) client2.run("install %s --build=missing" % str(conan_reference)) client2.run("info %s" % str(conan_reference)) self.assertIn("remote0=http://", client2.user_io.out) # Now install it in other machine from remote 1 servers = self.servers.copy() servers.pop("remote0") client3 = TestClient(servers=servers, users=self.users) client3.run("install %s --build=missing" % str(conan_reference)) client3.run("info %s" % str(conan_reference)) self.assertIn("remote1=http://", client3.user_io.out)
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': '52546396c42f16be3daf72ecf7ab7143', 'conanfile.py': '3ac566eb5b2e4df4417003f0e606e237', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd'} self.assertEqual(expected_sums, manif.file_sums)
def test_basic(self): current_folder = temp_folder() source_folder = os.path.join(current_folder, "source") 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 _upload_some_packages(self, client): self.ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") self.files = cpp_hello_conan_files("Hello0", "0.1") # No build. self.files[CONANFILE] = self.files[CONANFILE].replace( "def build(self):", "def build(self):\n return\n") client.save(self.files) client.run("export . lasote/stable") client.run( "install Hello0/0.1@lasote/stable -s os=Windows --build missing") client.run( "install Hello0/0.1@lasote/stable -s os=Linux --build missing") client.run( "install Hello0/0.1@lasote/stable -s os=Linux -s compiler=gcc -s " "compiler.version=4.6 -s compiler.libcxx=libstdc++ --build missing" ) client.run("upload Hello0/0.1@lasote/stable --all") return os.listdir(self.client.client_cache.packages(self.ref))
def uploaded_chain_test(self): self._export_upload("Hello0", "0.1") self._export_upload("Hello1", "0.1", ["Hello0/0.1@lasote/stable"]) client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files2 = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], static=True) client.save(files2) client.run("install . --build missing") client.run("build .") command = os.sep.join([".", "bin", "say_hello"]) client.runner(command, cwd=client.current_folder) self.assertEqual(['Hello Hello2', 'Hello Hello1', 'Hello Hello0'], str(client.user_io.out).splitlines()[-3:])
def hello_conan_files(conan_reference, number=0, deps=None, language=0, lang='cpp'): """Generate hello_files, as described above, plus the necessary CONANFILE to manage it param number: integer, defining name of the conans Hello0, Hello1, HelloX param deps: [] list of integers, defining which dependencies this conans depends on param language: 0 = English, 1 = Spanish e.g. (3, [4, 7]) means that a Hello3 conans will be created, with message "Hello 3", that depends both in Hello4 and Hello7. The output of such a conans exe could be like: Hello 3, Hello 4, Hello7""" if lang == 'cpp': return cpp_hello_conan_files(conan_reference, number, deps, language) elif lang == 'go': return go_hello_conan_files(conan_reference, number, deps)
def basic_test(self): server = TestServer() servers = {"default": server} client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files() client.save(files) client.run("export . lasote/stable") ref = ConanFileReference.loads("Hello/0.1@lasote/stable") self.assertTrue(os.path.exists(client.paths.export(ref))) client.run("upload Hello/0.1@lasote/stable") client.run("remove Hello/0.1@lasote/stable -f") self.assertFalse(os.path.exists(client.paths.export(ref))) path = server.test_server.server_store.export(ref) tgz = os.path.join(path, "conan_export.tgz") save(tgz, "contents") # dummy content to break it, so the download decompress will fail client.run("install Hello/0.1@lasote/stable --build", ignore_error=True) self.assertIn("ERROR: Error while downloading/extracting files to", client.user_io.out) self.assertFalse(os.path.exists(client.paths.export(ref)))
def test_override_setting_with_env_variables(self): files = cpp_hello_conan_files(name="VisualBuild", version="0.1", build=False, deps=["MinGWBuild/0.1@lasote/testing"]) self._patch_build_to_print_compiler(files) self.client.save(files) self.client.run("export . lasote/testing") with tools.environment_append({ "CONAN_ENV_COMPILER": "Visual Studio", "CONAN_ENV_COMPILER_VERSION": "14", "CONAN_ENV_COMPILER_RUNTIME": "MD" }): self.client.run( "install VisualBuild/0.1@lasote/testing --build missing") self.assertIn("COMPILER=> MinGWBuild Visual Studio", self.client.user_io.out)
def test_combined(self): base_folder = temp_folder() source_folder = os.path.join(base_folder, "source") conanfile_folder = os.path.join(base_folder, "conan") 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") conanfile = files.pop("conanfile.py") client.save(files, path=source_folder) conanfile = conanfile.replace("exports = '*'", 'exports = "../source*"') client.save({"conanfile.py": conanfile}, path=conanfile_folder) client.run("export lasote/stable --path=../conan") 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': '52546396c42f16be3daf72ecf7ab7143', 'conanfile.py': '3ac566eb5b2e4df4417003f0e606e237', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, manif.file_sums)
def put_properties_test(self): wanted_vars = {"MyHeader1": "MyHeaderValue1;MyHeaderValue2", "Other": "Value"} class RequesterCheckHeaders(TestRequester): def put(self, url, **kwargs): for name, value in wanted_vars.items(): value1 = kwargs["headers"][name] if value1 != value: raise Exception() return super(RequesterCheckHeaders, self).put(url, **kwargs) self.client = TestClient(requester_class=RequesterCheckHeaders, servers=self.servers, users={"default": [("lasote", "mypass")]}) _create_property_files(self.client, wanted_vars) files = cpp_hello_conan_files("Hello0", "0.1", build=False) self.client.save(files) self.client.run("export . lasote/stable") self.client.run("upload Hello0/0.1@lasote/stable -c")
def upload_login_prompt_disabled_user_not_authenticated_test(self): """ When a user is not authenticated, uploads should fail when login prompt has been disabled. """ files = cpp_hello_conan_files("Hello0", "1.2.1", build=False) client = self._client() client.save(files) client.run("config set general.non_interactive=True") client.run("create . user/testing") client.run("user -c") client.run("user lasote") error = client.run("upload Hello0/1.2.1@user/testing", ignore_error=True) self.assertTrue(error) self.assertIn('ERROR: Conan interactive mode disabled', client.out) self.assertNotIn("Uploading conanmanifest.txt", client.out) self.assertNotIn("Uploading conanfile.py", client.out) self.assertNotIn("Uploading conan_export.tgz", client.out) self.assertNotIn("Please enter a password for \"lasote\" account:", client.out)
def upload_only_tgz_if_needed_test(self): ref = ConanFileReference.loads("Hello0/0.1@lasote/stable") files = cpp_hello_conan_files("Hello0", "0.1", need_patch=True, build=False) files["lib/another_export_file.lib"] = "to compress" self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install %s --build missing" % str(ref)) # Upload conans self.client.run("upload %s" % str(ref)) self.assertIn("Compressing recipe", str(self.client.user_io.out)) # Not needed to tgz again self.client.run("upload %s" % str(ref)) self.assertNotIn("Compressing recipe", str(self.client.user_io.out)) # Check that conans exists on server server_paths = self.servers["default"].server_store conan_path = server_paths.conan_revisions_root(ref) self.assertTrue(os.path.exists(conan_path)) package_ids = self.client.cache.package_layout(ref).conan_packages() pref = PackageReference(ref, package_ids[0]) # Upload package self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) self.assertIn("Compressing package", str(self.client.user_io.out)) # Not needed to tgz again self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) self.assertNotIn("Compressing package", str(self.client.user_io.out)) # If we install the package again will be removed and re tgz self.client.run("install %s --build missing" % str(ref)) # Upload package self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0]))) self.assertNotIn("Compressing package", str(self.client.user_io.out)) # Check library on server self._assert_library_exists_in_server(pref, server_paths)
def conan_test_test(self): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1") test_conanfile = ''' from conans import ConanFile, CMake import os class HelloReuseConan(ConanFile): settings = "os", "compiler", "build_type", "arch" requires = "Hello0/0.1@ lasote/stable" generators = "cmake" def build(self): cmake = CMake(self.settings) self.run('cmake "%s" %s' % (self.conanfile_directory, cmake.command_line)) self.run("cmake --build . %s" % cmake.build_config) def test(self): # equal to ./bin/greet, but portable win: .\bin\greet self.run(os.sep.join([".","bin", "greet"])) ''' 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 build_type=Release -o Hello0:language=1") self.assertFalse(error) self.assertIn('Hola Hello0', client.user_io.out)
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 test_upload_key_error(self): files = cpp_hello_conan_files("Hello0", "1.2.1", build=False) server1 = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"}) server2 = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"}) servers = OrderedDict() servers["server1"] = server1 servers["server2"] = server2 client = TestClient(servers=servers) client.save(files) client.run("create . user/testing") client.run("user lasote -p mypass") client.run("user lasote -p mypass -r server2") client.run("upload Hello0/1.2.1@user/testing --all -r server1") client.run("remove * --force") client.run("install Hello0/1.2.1@user/testing -r server1") client.run("remote remove server1") client.run("upload Hello0/1.2.1@user/testing --all -r server2") self.assertNotIn("ERROR: 'server1'", client.out)
def test_reuse_uploaded_tgz(self): # Download packages from a remote, then copy to another channel # and reupload them. Because they have not changed, the tgz is not created again # UPLOAD A PACKAGE ref = 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(ref)) self.client.run("upload %s --all" % str(ref)) self.assertIn("Compressing recipe", self.client.out) self.assertIn("Compressing package", self.client.out) # UPLOAD TO A DIFFERENT CHANNEL WITHOUT COMPRESS AGAIN self.client.run("copy %s lasote/testing --all" % str(ref)) self.client.run("upload Hello0/0.1@lasote/testing --all") self.assertNotIn("Compressing recipe", self.client.out) self.assertNotIn("Compressing package", self.client.out)
def skip_upload_test(self): """ Check that the option --dry does not upload anything """ servers = {} test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")], users={"lasote": "mypass"}) servers["default"] = test_server client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello0", "1.2.1", build=False) client.save(files) client.run("export frodo/stable") client.run("install Hello0/1.2.1@frodo/stable --build=missing") client.run( "upload Hello0/1.2.1@frodo/stable -r default --all --skip_upload") # dry run should not upload self.assertNotIn("Uploading conan_package.tgz", client.user_io.out) # but dry run should compress self.assertIn("Compressing recipe...", client.user_io.out) self.assertIn("Compressing package...", client.user_io.out) client.run("search -r default") # after dry run nothing should be on the server ... self.assertNotIn("Hello0/1.2.1@frodo/stable", client.user_io.out) # now upload, the stuff should NOT be recompressed client.run("upload Hello0/1.2.1@frodo/stable -r default --all") # check for upload message self.assertIn("Uploading conan_package.tgz", client.user_io.out) # check if compressed files are re-used self.assertNotIn("Compressing recipe...", client.user_io.out) self.assertNotIn("Compressing package...", client.user_io.out) # now it should be on the server client.run("search -r default") self.assertIn("Hello0/1.2.1@frodo/stable", client.user_io.out)
def install_profile_env_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = conanfile_scope_env create_profile(self.client.cache.profiles_path, "envs", settings={}, env=[("A_VAR", "A_VALUE"), ("PREPEND_VAR", ["new_path", "other_path"])], package_env={"Hello0": [("OTHER_VAR", "2")]}) self.client.save(files) self.client.run("export . lasote/stable") self.client.run( "install Hello0/0.1@lasote/stable --build missing -pr envs") self._assert_env_variable_printed( "PREPEND_VAR", os.pathsep.join(["new_path", "other_path"])) self.assertEqual(1, str(self.client.out).count( "PREPEND_VAR=new_path")) # prepended once self._assert_env_variable_printed("A_VAR", "A_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override with package var self.client.run("install Hello0/0.1@lasote/stable --build " "-pr envs -e Hello0:A_VAR=OTHER_VALUE") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override package var with package var self.client.run("install Hello0/0.1@lasote/stable --build -pr envs " "-e Hello0:A_VAR=OTHER_VALUE -e Hello0:OTHER_VAR=3") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "3") # Pass a variable with "=" symbol self.client.run( "install Hello0/0.1@lasote/stable --build -pr envs " "-e Hello0:A_VAR=Valuewith=equal -e Hello0:OTHER_VAR=3") self._assert_env_variable_printed("A_VAR", "Valuewith=equal") self._assert_env_variable_printed("OTHER_VAR", "3")
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': 'bd569d8f69284ce8127fee724dac2a70', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, manif.file_sums)
def install_profile_package_settings_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) self.client.save(files) # Create a profile and use it profile_settings = OrderedDict([("os", "Windows"), ("compiler", "Visual Studio"), ("compiler.version", "12"), ("compiler.runtime", "MD"), ("arch", "x86")]) # Use package settings in profile tmp_settings = OrderedDict() tmp_settings["compiler"] = "gcc" tmp_settings["compiler.libcxx"] = "libstdc++11" tmp_settings["compiler.version"] = "4.8" package_settings = {"*@lasote/*": tmp_settings} _create_profile(self.client.cache.profiles_path, "myprofile", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run("install . lasote/testing -pr myprofile") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=gcc", info) self.assertIn("compiler.libcxx=libstdc++11", info) self.assertIn("compiler.version=4.8", info) package_settings = {"*@other/*": tmp_settings} _create_profile(self.client.cache.profiles_path, "myprofile", settings=profile_settings, package_settings=package_settings) # Try to override some settings in install command self.client.run("install . lasote/testing -pr myprofile") info = load(os.path.join(self.client.current_folder, "conaninfo.txt")) self.assertIn("compiler=Visual Studio", info) self.assertIn("compiler.runtime=MD", info) self.assertIn("compiler.version=12", info) self.assertNotIn("gcc", info) self.assertNotIn("libcxx", info)
def _export_upload(self, name=0, version=None, deps=None, msg=None, static=True, build=True, upload=True): files = cpp_hello_conan_files(name, version, deps, msg=msg, static=static, private_includes=True, build=build, cmake_targets=False) ref = ConanFileReference(name, version, "lasote", "stable") self.client.save(files, clean_first=True) self.client.run("export . lasote/stable") if upload: self.client.run("upload %s" % str(ref))
def test_conanfile_not_found(self): """If package is OpenSSL is not openssl""" test_server = TestServer( [("*/*@*/*", "*")], # read permissions [], # write permissions users={"lasote": "mypass"}) # exported users and passwords self.servers = {"default": test_server} self.client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) files = cpp_hello_conan_files("Hello0", "0.1") self.client.save(files) self.client.run("export lasote/stable") self.assertRaises(Exception, self.client.run, "install hello0/0.1@lasote/stable") self.client.run("install Hello0/0.1@lasote/stable --build missing") self.client.run("upload Hello0/0.1@lasote/stable") # Now with requirements.txt (bug in server) self.client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) self.client.save({ "conanfile.txt": "[requires]\nHello0/0.1@lasote/stable\n[generators]\ntxt" }) self.client.run("install --build missing ") build_info = load( os.path.join(self.client.current_folder, "conanbuildinfo.txt")) self.assertIn("helloHello0", build_info) self.client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]}) self.client.save({ "conanfile.txt": "[requires]\nhello0/0.1@lasote/stable\n[generators]\ntxt" }) self.assertRaises(Exception, self.client.run, "install")
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: 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_path2), self.conan.user_io.out) self.assertTrue(os.path.exists(reg_path2)) for name in list(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': '0f623a95e7262a618ad140eb2f959c5f', 'executable': '68b329da9893e34099c7d8ad5cb9c940', 'helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, digest2.file_sums) for f in file_list: self.assertTrue(os.path.exists(f))
def install_outdated_test(self): # If we try to install the same package with --build oudated it's already ok self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertIn("Hello0/0.1@lasote/stable: Package is up to date", self.client.user_io.out) # Then we can export a modified recipe and try to install without --build outdated files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = files["conanfile.py"] + "\n#Otherline" self.client.save(files) self.client.run("export lasote/stable") self.client.run("install Hello0/0.1@lasote/stable") self.assertIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertNotIn("Package is up to date", self.client.user_io.out) self.assertNotIn("Outdated package!", self.client.user_io.out) # Try now with the --build outdated self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertNotIn("Package is up to date", self.client.user_io.out) self.assertIn("Outdated package!", self.client.user_io.out) self.assertIn("Building your package", self.client.user_io.out) # Remove all local references, export again (the modified version not uploaded) # and try to install, it will discard the remote package too self.client.run("remove Hello0* -f") self.client.save(files) self.client.run("export lasote/stable") self.client.run("remote add_ref Hello0/0.1@lasote/stable default") self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertIn("Downloading conan_package.tgz", self.client.user_io.out) self.assertNotIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertNotIn("Package is up to date", self.client.user_io.out) self.assertIn("Outdated package!", self.client.user_io.out) self.assertIn("Building your package", self.client.user_io.out)
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 = """set(CMAKE_CXX_COMPILER_WORKS 1) set(CMAKE_CXX_ABI_COMPILED 1) project(MyHello CXX) 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("create lasote/stable") error = client.run("test test_package -s build_type=Release") self.assertFalse(error) self.assertNotIn("WARN: conanbuildinfo.txt file not found", client.user_io.out) self.assertNotIn("WARN: conanenv.txt file not found", client.user_io.out) self.assertIn('Hello Hello0', client.user_io.out) error = client.run( "test test_package -s Hello0:build_type=Debug -o Hello0:language=1 --build missing" ) self.assertFalse(error) self.assertIn('Hola Hello0', client.user_io.out) self.assertIn('BUILD_TYPE=>Debug', client.user_io.out)
def matrix_params_test(self): test_server = TestServer(server_capabilities=[MATRIX_PARAMS, ]) servers = {"default": test_server} wanted_vars = {"key0": "value", "key1": "with space", "key2": "with/slash", "key3": "with.dot", "key4": "with;semicolon", "key5": "with~virgul", "key6": "with#hash" } class RequesterCheckArtifactProperties(TestRequester): def put(self_requester, url, **kwargs): # Check headers self.assertListEqual(list(kwargs["headers"].keys()), ["X-Checksum-Sha1", "User-Agent"]) # Check matrix params m = re.match(r"^[^;\s]+;(?P<matrix_params>[^/]+)/.*", url) mp = m.group("matrix_params") values = [it.split("=") for it in mp.split(';')] values = {key: unquote(value) for (key, value) in values} for name, value in wanted_vars.items(): value1 = values[name] self.assertEqual(value1, value) slice_start, slice_end = m.span(1) url = url[: slice_start-1] + url[slice_end:] # matrix params are not implemented for conan-server return super(RequesterCheckArtifactProperties, self_requester).put(url, **kwargs) client = TestClient(requester_class=RequesterCheckArtifactProperties, servers=servers, users={"default": [("lasote", "mypass")]}) _create_property_files(client, wanted_vars) files = cpp_hello_conan_files("Hello0", "0.1", build=False) client.save(files) client.run("export . lasote/stable") client.run("upload Hello0/0.1@lasote/stable -c")
def test_export_the_same_code(self): file_list = self._create_packages_and_builds() # Export the same conans # Do not adjust cpu_count, it is reusing a cache conan2 = TestClient(self.conan.base_folder, cpu_count=False) files2 = cpp_hello_conan_files("Hello0", "0.1") conan2.save(files2) conan2.run("export . lasote/stable") reg_path2 = conan2.client_cache.export(self.conan_ref) digest2 = FileTreeManifest.load( conan2.client_cache.export(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: 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_path2), self.conan.user_io.out) self.assertTrue(os.path.exists(reg_path2)) for name in list(files2.keys()): self.assertTrue(os.path.exists(os.path.join(reg_path2, name))) expected_sums = { 'hello.cpp': '4f005274b2fdb25e6113b69774dac184', 'main.cpp': '0479f3c223c9a656a718f3148e044124', 'CMakeLists.txt': '10d907c160c360b28f6991397a5aa9b4', 'conanfile.py': '355949fbf0b4fc32b8f1c5a338dfe1ae', 'executable': '68b329da9893e34099c7d8ad5cb9c940', '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") 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.cache.package_layout(ref).export() manif = FileTreeManifest.load( client.cache.package_layout(ref).export()) self.assertIn('%s: A new conanfile.py version was exported' % str(ref), client.out) self.assertIn('%s: Folder: %s' % (str(ref), reg_path), client.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': '10d907c160c360b28f6991397a5aa9b4', 'conanfile.py': '3ac566eb5b2e4df4417003f0e606e237', 'source/executable': '68b329da9893e34099c7d8ad5cb9c940', 'source/helloHello0.h': '9448df034392fc8781a47dd03ae71bdd' } self.assertEqual(expected_sums, manif.file_sums)
def build(tester, cmd, static, pure_c, use_cmake, lang): client = TestClient() files = cpp_hello_conan_files("Hello0", "0.1", 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 "") if platform.system() == "Darwin": ld_path += ' DYLD_LIBRARY_PATH="%s"' % os.path.join(client.current_folder, 'lib') command = os.sep.join([".", "bin", "say_hello"]) client.run_command("%s %s" % (ld_path, command)) msg = "Hello" if lang == 0 else "Hola" tester.assertIn("%s Hello0" % msg, client.out) conan_info_path = os.path.join(client.current_folder, CONANINFO) conan_info = ConanInfo.loads(load(conan_info_path)) tester.assertTrue(conan_info.full_options.language == lang) if static: tester.assertTrue(conan_info.full_options.static) else: tester.assertFalse(conan_info.full_options.static)
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 install_profile_env_test(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] = conanfile_scope_env self._create_profile("envs", settings={}, env=[("A_VAR", "A_VALUE")], package_env={"Hello0": [("OTHER_VAR", 2)]}) self.client.save(files) self.client.run("export lasote/stable") self.client.run("install Hello0/0.1@lasote/stable --build missing -pr envs") self._assert_env_variable_printed("A_VAR", "A_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override with package var self.client.run("install Hello0/0.1@lasote/stable --build -pr envs -e Hello0:A_VAR=OTHER_VALUE") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "2") # Override package var with package var self.client.run("install Hello0/0.1@lasote/stable --build -pr envs -e Hello0:A_VAR=OTHER_VALUE -e Hello0:OTHER_VAR=3") self._assert_env_variable_printed("A_VAR", "OTHER_VALUE") self._assert_env_variable_printed("OTHER_VAR", "3")
def install_outdated_test(self): # If we try to install the same package with --build oudated it's already ok self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertIn("Hello0/0.1@lasote/stable: Package is up to date", self.client.user_io.out) # Then we can export a modified recipe and try to install without --build outdated files = cpp_hello_conan_files("Hello0", "0.1", build=False) files["conanfile.py"] += "\n#Otherline" self.client.save(files) self.client.run("export . lasote/stable") self.client.run("install Hello0/0.1@lasote/stable") self.assertIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertNotIn("Package is up to date", self.client.user_io.out) self.assertNotIn("Outdated package!", self.client.user_io.out) # Try now with the --build outdated self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertNotIn("Package is up to date", self.client.user_io.out) self.assertIn("Outdated package!", self.client.user_io.out) self.assertIn("Building your package", self.client.user_io.out) # Remove all local references, export again (the modified version not uploaded) # and try to install, it will discard the remote package too self.client.run("remove Hello0* -f") self.client.save(files) self.client.run("export . lasote/stable") self.client.run("remote add_ref Hello0/0.1@lasote/stable default") self.client.run("install Hello0/0.1@lasote/stable --build outdated") self.assertNotIn("Hello0/0.1@lasote/stable: Already installed!", self.client.user_io.out) self.assertNotIn("Package is up to date", self.client.user_io.out) # With revisions it looks in the server a package for the changed local recipe and it # doesn't find it, so there is no Outdated package alert, just building if not self.client.revisions: self.assertIn("Outdated package!", self.client.user_io.out) self.assertIn("Building your package", self.client.user_io.out)
def _create(self, number, version, deps=None, deps_dev=None, export=True): files = cpp_hello_conan_files(number, version, deps, build=False) files[CONANFILE] = files[CONANFILE].replace("config(", "configure(") if deps_dev: files[CONANFILE] = files[CONANFILE].replace( "exports = '*'", """exports = '*' dev_requires=%s """ % ",".join('"%s"' % d for d in deps_dev)) self.client.save(files, clean_first=True) if export: self.client.run("export . lasote/stable") expected_output = textwrap.dedent("""\ [HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'url'. It is recommended to add it as attribute [HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'license'. It is recommended to add it as attribute [HOOK - attribute_checker.py] pre_export(): WARN: Conanfile doesn't have 'description'. It is recommended to add it as attribute """) self.assertIn(expected_output, self.client.out) if number != "Hello2": files[CONANFILE] = files[CONANFILE].replace( 'version = "0.1"', 'version = "0.1"\n' ' url= "myurl"\n' ' license = "MIT"\n' ' description = "blah"') else: files[CONANFILE] = files[CONANFILE].replace( 'version = "0.1"', 'version = "0.1"\n' ' url= "myurl"\n' ' license = "MIT", "GPL"\n' ' description = """Yo no creo en brujas,\n' ' pero que las hay,\n' ' las hay"""') self.client.save(files) if export: self.client.run("export . lasote/stable") self.assertNotIn("WARN: Conanfile doesn't have 'url'", self.client.out)