def test_graph_dot(self): table_template_path = os.path.join(self.t.cache_folder, 'templates', INFO_GRAPH_DOT) save(table_template_path, content='{{ base_template_path }}') self.t.run("info {}@ --graph=output.dot".format(self.app_ref)) content = self.t.load("output.dot") self.assertEqual( os.path.join(self.t.cache_folder, 'templates', 'output'), content)
def test_table_html(self): table_template_path = os.path.join(self.t.cache_folder, 'templates', SEARCH_TABLE_HTML) save(table_template_path, content='{{ base_template_path }}') self.t.run("search {}@ --table=output.html".format(self.lib_ref)) content = self.t.load("output.html") self.assertEqual( os.path.join(self.t.cache_folder, 'templates', 'output'), content)
def patch_default_base_profile(conan_api, profile_abs_path): """If we have a profile including default, but the users default in config is that the default is other, we have to change the include""" text = tools.load(profile_abs_path) if "include(default)" in text: # User didn't specified a custom profile default_profile_name = os.path.basename( conan_api._client_cache.default_profile_path) if not os.path.exists(conan_api._client_cache.default_profile_path): conan_api.create_profile(default_profile_name, detect=True) if default_profile_name != "default": # User have a different default profile name # https://github.com/conan-io/conan-package-tools/issues/121 text = text.replace("include(default)", "include(%s)" % default_profile_name) tools.save(profile_abs_path, text)
def pic_client_certs_test(self): class MyRequester(object): def __init__(*args, **kwargs): pass def get(self, _, **kwargs): return kwargs.get("cert", None) client = TestClient(requester_class=MyRequester) self.assertIsNone(client.requester.get("url")) config = client.cache.config tools.save(config.client_cert_path, "Fake cert") self.assertEqual(client.requester.get("url"), client.cache.config.client_cert_path) tools.save(config.client_cert_path, "Fake cert") tools.save(config.client_cert_key_path, "Fake key") self.assertEqual( client.requester.get("url"), (config.client_cert_path, config.client_cert_key_path)) # assert that the cacert file is created self.assertTrue(os.path.exists(config.cacert_path))
def curdir_test(self): tmp_folder = temp_folder() conanfile = """from conans import ConanFile class Pkg(ConanFile): name = "lib" version = "1.0" """ tools.save(os.path.join(tmp_folder, "conanfile.py"), conanfile) with tools.chdir(tmp_folder): # Needed to not write in the real computer cache with tools.environment_append({"CONAN_USER_HOME": tmp_folder}): api, _, _ = ConanAPIV1.factory() api.create(".", name="lib", version="1.0", user="******", channel="channel") self.assertEqual(tmp_folder, os.getcwd()) api.create(".", name="lib", version="1.0", user="******", channel="channel2") self.assertEqual(tmp_folder, os.getcwd())
def pic_client_certs_test(self): client = TestClient(requester_class=self.MyHttpRequester) self.assertIsNone(client.requester.get("url")) config = client.cache.config tools.save(config.client_cert_path, "Fake cert") self.assertEqual(client.requester.get("url"), client.cache.config.client_cert_path) tools.save(config.client_cert_path, "Fake cert") tools.save(config.client_cert_key_path, "Fake key") self.assertEqual( client.requester.get("url"), (config.client_cert_path, config.client_cert_key_path)) # assert that the cacert file is created self.assertTrue(os.path.exists(config.cacert_path))
def run(self, *args, **kwargs): default_profile_path = os.path.join(temp_folder(), "default.profile") save(default_profile_path, self.default_profile) with environment_append( {"CONAN_DEFAULT_PROFILE_PATH": default_profile_path}): unittest.TestCase.run(self, *args, **kwargs)
def package(self): # Extract the License/s from the header to a file with tools.chdir(self.ZIP_FOLDER_NAME): tmp = tools.load("zlib.h") license_contents = tmp[2:tmp.find("*/", 1)] tools.save("LICENSE", license_contents) # Copy the license files self.copy("LICENSE", src=self.ZIP_FOLDER_NAME, dst=".") # Copy pc file self.copy("*.pc", dst="", keep_path=False) # Copying zlib.h, zutil.h, zconf.h self.copy("*.h", "include", "%s" % self.ZIP_FOLDER_NAME, keep_path=False) self.copy("*.h", "include", "%s" % "_build", keep_path=False) # Copying static and dynamic libs if tools.os_info.is_windows: if self.options.shared: build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build") self.copy(pattern="*.dll", dst="bin", src=build_dir, keep_path=False) build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build/lib") self.copy(pattern="*zlibd.lib", dst="lib", src=build_dir, keep_path=False) self.copy(pattern="*zlib.lib", dst="lib", src=build_dir, keep_path=False) self.copy(pattern="*zlib.dll.a", dst="lib", src=build_dir, keep_path=False) else: build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build/lib") # MinGW self.copy(pattern="libzlibstaticd.a", dst="lib", src=build_dir, keep_path=False) self.copy(pattern="libzlibstatic.a", dst="lib", src=build_dir, keep_path=False) # Visual Studio self.copy(pattern="zlibstaticd.lib", dst="lib", src=build_dir, keep_path=False) self.copy(pattern="zlibstatic.lib", dst="lib", src=build_dir, keep_path=False) lib_path = os.path.join(self.package_folder, "lib") suffix = "d" if self.settings.build_type == "Debug" else "" if self.settings.compiler == "Visual Studio": current_lib = os.path.join(lib_path, "zlibstatic%s.lib" % suffix) os.rename(current_lib, os.path.join(lib_path, "zlib%s.lib" % suffix)) elif self.settings.compiler == "gcc": current_lib = os.path.join(lib_path, "libzlibstatic.a") os.rename(current_lib, os.path.join(lib_path, "libzlib.a")) else: build_dir = os.path.join(self.ZIP_FOLDER_NAME) if self.options.shared: if self.settings.os == "Macos": self.copy(pattern="*.dylib", dst="lib", src=build_dir, keep_path=False) else: self.copy(pattern="*.so*", dst="lib", src=build_dir, keep_path=False) else: self.copy(pattern="*.a", dst="lib", src=build_dir, keep_path=False)