def test(self, build_type=None, target=None, output_on_failure=False): if not self._conanfile.should_test: return if not target: target = "RUN_TESTS" if self._is_multiconfiguration else "test" env = {'CTEST_OUTPUT_ON_FAILURE': '1' if output_on_failure else '0'} if self._parallel: env['CTEST_PARALLEL_LEVEL'] = str(cpu_count(self._conanfile.output)) with tools.environment_append(env): self._build(build_type=build_type, target=target)
def test_config_home_custom_home_dir(): """ config home MUST accept CONAN_USER_HOME as custom home path """ cache_folder = os.path.join(temp_folder(), "custom") with environment_append({"CONAN_USER_HOME": cache_folder}): client = TestClient(cache_folder=cache_folder) client.run("config home") assert cache_folder in client.out client.run("config home --json home.json") _assert_dict_subset({"home": cache_folder}, json.loads(client.load("home.json")))
def test_no_credentials_only_url_skip_check(self): self.save_conanfile(self.conanfile) with tools.environment_append({"CONAN_PASSWORD": "******", "CONAN_UPLOAD_ONLY_WHEN_STABLE": "1"}): mp = ConanMultiPackager(username="******", out=self.output.write, channel="my_channel", ci_manager=self.ci_manager, upload="https://api.bintray.com/conan/conan-community/conan",) mp.add({}, {}, {}) mp.run() self.assertIn("Skipping upload, not stable channel", self.output)
def test_recipe_modes(self): configs = [] mode = "semver_mode" configs.append((mode, "liba/1.1.1@user/testing", "8ecbf93ba63522ffb32573610c80ab4dcb399b52")) configs.append((mode, "liba/1.1.2@user/testing", "8ecbf93ba63522ffb32573610c80ab4dcb399b52")) configs.append((mode, "liba/1.2.1@other/stable", "8ecbf93ba63522ffb32573610c80ab4dcb399b52")) mode = "patch_mode" configs.append((mode, "liba/1.1.1@user/testing", "bd664570d5174c601d5d417bc19257c4dba48f2e")) configs.append((mode, "liba/1.1.2@user/testing", "fb1f766173191d44b67156c6b9ac667422e99286")) configs.append((mode, "liba/1.1.1@other/stable", "bd664570d5174c601d5d417bc19257c4dba48f2e")) mode = "full_recipe_mode" configs.append((mode, "liba/1.1.1@user/testing", "9cbe703e1dee73a2a6807f71d8551c5f1e1b08fd")) configs.append((mode, "liba/1.1.2@user/testing", "42a9ff9024adabbd54849331cf01be7d95139948")) configs.append((mode, "liba/1.1.1@user/stable", "b41d6c026473cffed4abded4b0eaa453497be1d2")) def _assert_recipe_mode(ref_arg, package_id_arg): libb_ref = ConanFileReference.loads("libb/0.1@user/testing") self._cache_recipe( ref_arg, GenConanfile().with_name("liba").with_version("0.1.1")) self._cache_recipe( libb_ref, GenConanfile().with_name("libb").with_version( "0.1").with_require(ref_arg)) deps_graph = self.build_graph(GenConanfile().with_name( "app").with_version("0.1").with_require(libb_ref)) self.assertEqual(3, len(deps_graph.nodes)) app = deps_graph.root libb = app.dependencies[0].dst liba = libb.dependencies[0].dst self.assertEqual(liba.package_id, "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9") self.assertEqual(libb.package_id, package_id_arg) for package_id_mode, ref, package_id in configs: self.cache.config.set_item("general.default_package_id_mode", package_id_mode) _assert_recipe_mode(ConanFileReference.loads(ref), package_id) for package_id_mode, ref, package_id in configs: with environment_append( {"CONAN_DEFAULT_PACKAGE_ID_MODE": package_id_mode}): _assert_recipe_mode(ConanFileReference.loads(ref), package_id)
def test_vcvars_with_store_echo(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "WindowsStore" settings.os.version = "8.1" settings.compiler = "Visual Studio" settings.compiler.version = "14" cmd = tools.vcvars_command(settings, output=self.output) self.assertIn("store 8.1", cmd) with tools.environment_append({"VisualStudioVersion": "14"}): cmd = tools.vcvars_command(settings, output=self.output) self.assertEqual("echo Conan:vcvars already set", cmd)
def test_build_folder_handling(self): conanfile = GenConanfile().with_name("Hello").with_version("0.1") test_conanfile = GenConanfile().with_test("pass") client = TestClient() default_build_dir = os.path.join(client.current_folder, "test_package", "build") # Test the default behavior. client.save( { "conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile }, clean_first=True) client.run("create . lasote/stable") self.assertTrue(os.path.exists(default_build_dir)) # Test if the specified build folder is respected. client.save( { "conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile }, clean_first=True) client.run("create -tbf=build_folder . lasote/stable") self.assertTrue( os.path.exists(os.path.join(client.current_folder, "build_folder"))) self.assertFalse(os.path.exists(default_build_dir)) # Test if using a temporary test folder can be enabled via the environment variable. client.save( { "conanfile.py": conanfile, "test_package/conanfile.py": test_conanfile }, clean_first=True) with tools.environment_append({"CONAN_TEMP_TEST_FOLDER": "True"}): client.run("create . lasote/stable") self.assertFalse(os.path.exists(default_build_dir)) # # Test if using a temporary test folder can be enabled via the config file. client.run('config set general.temp_test_folder=True') client.run("create . lasote/stable") self.assertFalse(os.path.exists(default_build_dir)) # Test if the specified build folder is respected also when the use of # temporary test folders is enabled in the config file. client.run("create -tbf=test_package/build_folder . lasote/stable") self.assertTrue( os.path.exists( os.path.join(client.current_folder, "test_package", "build_folder"))) self.assertFalse(os.path.exists(default_build_dir))
def test_env_path_order(self): client = TestClient() with tools.environment_append({"SOME_VAR": ["INITIAL VALUE"]}): conanfile = """from conans import ConanFile import os class MyPkg(ConanFile): def build(self): self.output.info("PKG VARS: %s" % os.getenv("SOME_VAR")) def package_info(self): self.env_info.SOME_VAR.append("OTHER_VALUE") """ client.save({"conanfile.py": conanfile}) client.run("create . Pkg/0.1@lasote/testing") self.assertIn("Pkg/0.1@lasote/testing: PKG VARS: INITIAL VALUE", client.out) conanfile = """from conans import ConanFile import os class MyTest(ConanFile): requires = "Pkg/0.1@lasote/testing" def build(self): self.output.info("TEST VARS: %s" % os.getenv("SOME_VAR")) def package_info(self): self.env_info.SOME_VAR.extend(["OTHER_VALUE2", "OTHER_VALUE3"]) """ client.save({"conanfile.py": conanfile}) client.run("create . Test/0.1@lasote/testing") # FIXME: Note that these values are os.pathsep (; or :) self.assertIn( "Test/0.1@lasote/testing: TEST VARS: OTHER_VALUE%sINITIAL VALUE" % os.pathsep, client.out) conanfile = """from conans import ConanFile import os class MyTest(ConanFile): requires = "Test/0.1@lasote/testing" def build(self): self.output.info("PROJECT VARS: %s" % os.getenv("SOME_VAR")) """ client.save({"conanfile.py": conanfile}) client.run("create . project/0.1@lasote/testing") self.assertIn( "project/0.1@lasote/testing: PROJECT VARS: " + os.pathsep.join([ "OTHER_VALUE2", "OTHER_VALUE3", "OTHER_VALUE", "INITIAL VALUE" ]), client.out) client.run( "create . project/0.1@lasote/testing -e SOME_VAR=[WHAT]") self.assertIn( "project/0.1@lasote/testing: PROJECT VARS: " + os.pathsep.join([ "WHAT", "OTHER_VALUE2", "OTHER_VALUE3", "OTHER_VALUE", "INITIAL VALUE" ]), client.out)
def verbosity_env_test(self): settings = MockSettings({ "build_type": "Debug", "compiler": "Visual Studio", "arch": "x86_64" }) with tools.environment_append({"CONAN_MSBUILD_VERBOSITY": "detailed"}): conanfile = MockConanfile(settings) msbuild = MSBuild(conanfile) command = msbuild.get_command("projecshould_flags_testt_file.sln") self.assertIn('/verbosity:detailed', command)
def test_previous_env(self): settings = MockSettings({ "arch": "x86", "os": "Linux", "compiler": "gcc" }) conanfile = MockConanfile(settings) with tools.environment_append({"CPPFLAGS": "MyCppFlag"}): be = AutoToolsBuildEnvironment(conanfile) self.assertEqual(be.vars["CPPFLAGS"], "MyCppFlag")
def test_no_credentials_only_url(self): self.save_conanfile(self.conanfile) with tools.environment_append({"CONAN_PASSWORD": "******"}): mp = ConanMultiPackager( username="******", out=self.output.write, ci_manager=self.ci_manager, upload="https://api.bintray.com/conan/conan-community/conan") with self.assertRaisesRegexp(ConanException, "Wrong user or password"): mp.run()
def test_config_user_home_short_path(): """ When general.user_home_short is configured, short_paths MUST obey its path """ short_folder = os.path.join(temp_folder(), "short").replace("\\", "/") with environment_append({"CONAN_USER_HOME_SHORT": ""}): client = TestClient() client.run( "config set general.user_home_short='{}'".format(short_folder)) client.save({"conanfile.py": GenConanfile().with_short_paths(True)}) client.run("create . foobar/0.1.0@user/testing") assert client.cache.config.short_paths_home == short_folder
def build_folder_handling_test(self): test_conanfile = ''' from conans import ConanFile class TestConanLib(ConanFile): def test(self): pass ''' # Create a package which can be tested afterwards. client = TestClient() client.save({CONANFILE: conanfile}, clean_first=True) client.run("create . lasote/stable") # Test the default behavior. default_build_dir = os.path.join(client.current_folder, "test_package", "build") client.save({"test_package/conanfile.py": test_conanfile}, clean_first=True) client.run("test test_package Hello/0.1@lasote/stable") self.assertTrue(os.path.exists(default_build_dir)) # Test if the specified build folder is respected. client.save({"test_package/conanfile.py": test_conanfile}, clean_first=True) client.run( "test -tbf=build_folder test_package Hello/0.1@lasote/stable") self.assertTrue( os.path.exists(os.path.join(client.current_folder, "build_folder"))) self.assertFalse(os.path.exists(default_build_dir)) # Test if using a temporary test folder can be enabled via the environment variable. client.save({"test_package/conanfile.py": test_conanfile}, clean_first=True) with tools.environment_append({"CONAN_TEMP_TEST_FOLDER": "True"}): client.run("test test_package Hello/0.1@lasote/stable") self.assertFalse(os.path.exists(default_build_dir)) # Test if using a temporary test folder can be enabled via the config file. client.run('config set general.temp_test_folder=True') client.run("test test_package Hello/0.1@lasote/stable") self.assertFalse(os.path.exists(default_build_dir)) # Test if the specified build folder is respected also when the use of # temporary test folders is enabled in the config file. client.run( "test -tbf=test_package/build_folder test_package Hello/0.1@lasote/stable" ) self.assertTrue( os.path.exists( os.path.join(client.current_folder, "test_package", "build_folder"))) self.assertFalse(os.path.exists(default_build_dir))
def test_upload_only_stable(self): self.save_conanfile(self.conanfile) with tools.environment_append({ "CONAN_PASSWORD": "******", "CONAN_SKIP_CHECK_CREDENTIALS": "1" }): mp = ConanMultiPackager( username="******", out=self.output.write, ci_manager=self.ci_manager, upload="https://api.bintray.com/conan/conan-community/conan") mp.run() # No builds to upload so no raises
def run(self, *args, **kwargs): # path_to_conanfile and path_from_conanfile_to_root must be opposite ones. self.assertEqual( os.path.normpath( os.path.join(self.path_to_conanfile, self.path_from_conanfile_to_root)), '.') with environment_append({ 'CONAN_USERNAME': "******", "CONAN_CHANNEL": "channel" }): super(TestWorkflow, self).run(*args, **kwargs)
def environment_test(self): env = {"PROMPT": "old_PROMPT", "OLD_PS1": "old_OLD_PS1", "PS1": "old_PS1", "BASE_LIST": "old_BASE_LIST", "BASE_VAR": "old_BASE_VAR", "CPPFLAGS": "old_CPPFLAGS", "LD_LIBRARY_PATH": "old_LD_LIBRARY_PATH", "SPECIAL_VAR": "old_SPECIAL_VAR", "BCKW_SLASH": "old_BCKW_SLASH"} with tools.environment_append(env): self.basic_test(posix_empty_vars=False)
def env_setting_override_test(self): tmp_dir = temp_folder() out = MockOut() cache = ClientCache(tmp_dir, None, out) base_settings = OrderedDict( detect_defaults_settings(out, profile_path="~/.conan/profiles/default")) with tools.environment_append({"CONAN_ENV_COMPILER_VERSION": "4.6"}): expected = copy.copy(base_settings) expected["compiler.version"] = "4.6" self.assertEqual(cache.default_profile.settings, expected) tmp_dir = temp_folder() cache = ClientCache(tmp_dir, None, out) with tools.environment_append({}): self.assertEqual(cache.default_profile.settings, base_settings) tmp_dir = temp_folder() cache = ClientCache(tmp_dir, None, out) # If compiler is overwritten compiler subsettings are not assigned with tools.environment_append({"CONAN_ENV_COMPILER": "Visual Studio"}): expected = copy.copy(base_settings) expected["compiler"] = "Visual Studio" self.assertEqual(cache.default_profile.settings, expected) tmp_dir = temp_folder() cache = ClientCache(tmp_dir, None, out) with tools.environment_append({ "CONAN_ENV_COMPILER": "Visual Studio", "CONAN_ENV_COMPILER_VERSION": "14", "CONAN_ENV_COMPILER_RUNTIME": "MDd" }): expected = copy.copy(base_settings) expected["compiler"] = "Visual Studio" expected["compiler.runtime"] = "MDd" expected["compiler.version"] = "14" self.assertEqual(cache.default_profile.settings, expected)
def test_short_paths_home_set_acl(self): """ When CONAN_USER_HOME_SHORT is living in NTFS file systems, current user needs to be granted with full control permission to avoid access problems when cygwin/msys2 windows subsystems are mounting/using that folder. """ if platform.system() != "Windows": return folder = temp_folder( False) # Creates a temporary folder in %HOME%\appdata\local\temp out = subprocess.check_output("wmic logicaldisk %s get FileSystem" % os.path.splitdrive(folder)[0]) if "NTFS" not in str(out): return short_folder = os.path.join(folder, ".cnacls") self.assertFalse(os.path.exists(short_folder), "short_folder: %s shouldn't exists" % short_folder) os.makedirs(short_folder) current_domain = os.environ['USERDOMAIN'] current_user = os.environ['USERNAME'] # Explicitly revoke full control permission to current user cmd = r'cacls %s /E /R "%s\%s"' % (short_folder, current_domain, current_user) try: subprocess.check_output(cmd, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: raise Exception("Error %s setting ACL to short_folder: '%s'." "Please check that cacls.exe exists" % (e, short_folder)) # Run conan export in using short_folder with tools.environment_append({"CONAN_USER_HOME_SHORT": short_folder}): client = TestClient(base_folder=folder) client.save({CONANFILE: conanfile_py.replace("False", "True")}) client.run("export . %s" % self.user_channel) # Retrieve ACLs from short_folder try: short_folder_acls = subprocess.check_output( "cacls %s" % short_folder, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: raise Exception("Error %s getting ACL from short_folder: '%s'." % (e, short_folder)) # Check user has full control user_acl = "%s\\%s:(OI)(CI)F" % (current_domain, current_user) self.assertIn(user_acl.encode(), short_folder_acls)
def configure(self, args=None, defs=None, source_dir=None, build_dir=None, source_folder=None, build_folder=None, cache_build_folder=None, pkg_config_paths=None): # TODO: Deprecate source_dir and build_dir in favor of xxx_folder if not self._conanfile.should_configure: return args = args or [] defs = defs or {} source_dir, self.build_dir = self._get_dirs(source_folder, build_folder, source_dir, build_dir, cache_build_folder) mkdir(self.build_dir) arg_list = join_arguments([ self.command_line, args_to_string(args), defs_to_string(defs), args_to_string([source_dir]) ]) if pkg_config_paths: pkg_env = { "PKG_CONFIG_PATH": os.pathsep.join( get_abs_path(f, self._conanfile.install_folder) for f in pkg_config_paths) } else: # If we are using pkg_config generator automate the pcs location, otherwise it could # read wrong files set_env = "pkg_config" in self._conanfile.generators \ and "PKG_CONFIG_PATH" not in os.environ pkg_env = { "PKG_CONFIG_PATH": self._conanfile.install_folder } if set_env else {} with tools.environment_append(pkg_env): command = "cd %s && %s %s" % (args_to_string( [self.build_dir]), self._cmake_program, arg_list) if platform.system( ) == "Windows" and self.generator == "MinGW Makefiles": with tools.remove_from_path("sh"): self._run(command) else: self._run(command)
def test_error_on_override(self): """ Given a conflict in dependencies that is overridden by the consumer project, instead of silently output a message, the user can force an error using the env variable 'CONAN_ERROR_ON_OVERRIDE' """ with environment_append({'CONAN_ERROR_ON_OVERRIDE': "True"}): self._export("Hello3", "0.1", ["Hello1/0.1@lasote/stable", "Hello2/0.1@lasote/stable", "Hello0/0.1@lasote/stable"], export=False) self.client.run("install . --build missing", assert_error=True) self.assertIn("ERROR: Hello2/0.1@lasote/stable: requirement Hello0/0.2@lasote/stable" " overridden by Hello3/0.1 to Hello0/0.1@lasote/stable", self.client.out)
def test_environ_removed(self): client = TestClient() conf = """ [proxies] no_proxy_match=MyExcludedUrl* """ save(client.cache.conan_conf_path, conf) requester = ConanRequester(client.cache.config) def verify_env(url, **kwargs): self.assertFalse("HTTP_PROXY" in os.environ) self.assertFalse("http_proxy" in os.environ) with tools.environment_append({"http_proxy": "my_system_proxy"}): requester._http_requester.get = verify_env requester.get("MyUrl") self.assertEqual(os.environ["http_proxy"], "my_system_proxy") with tools.environment_append({"HTTP_PROXY": "my_system_proxy"}): requester._http_requester.get = verify_env requester.get("MyUrl") self.assertEqual(os.environ["HTTP_PROXY"], "my_system_proxy")
def test_no_credentials_but_skip(self): with tools.environment_append({"CONAN_NON_INTERACTIVE": "1"}): self.save_conanfile(self.conanfile) mp = ConanMultiPackager(username="******", out=self.output.write, ci_manager=self.ci_manager, upload=("https://uilianr.jfrog.io/artifactory/api/conan/public-conan", True, "my_upload_remote"), skip_check_credentials=True) mp.add({}, {}, {}) with self.assertRaisesRegexp(ConanException, "Errors uploading some packages"): mp.run() self.assertIn("Uploading packages for", self.output) self.assertIn("Credentials not specified but 'skip_check_credentials' activated", self.output)
def test_no_credentials_but_skip(self): with tools.environment_append({"CONAN_NON_INTERACTIVE": "1"}): self.save_conanfile(self.conanfile) mp = ConanMultiPackager(username="******", out=self.output.write, ci_manager=self.ci_manager, upload=("https://api.bintray.com/conan/conan-community/conan", True, "my_upload_remote"), skip_check_credentials=True) mp.add({}, {}, {}) with self.assertRaisesRegexp(ConanException, "Conan interactive mode disabled"): mp.run() self.assertIn("Uploading packages for", self.output) self.assertIn("Credentials not specified but 'skip_check_credentials' activated", self.output)
def test_profile_template(): client = TestClient() tpl = textwrap.dedent(""" [settings] os = {{ {"Darwin": "Macos"}.get(platform.system(), platform.system()) }} build_type = {{ os.getenv("MY_BUILD_TYPE") }} """) client.save({"conanfile.py": GenConanfile(), "profile1.jinja": tpl}) with environment_append({"MY_BUILD_TYPE": "Debug"}): client.run("install . -pr=profile1.jinja") current_os = {"Darwin": "Macos"}.get(platform.system(), platform.system()) assert "os={}".format(current_os) assert "build_type=Debug"
def test_environ_kept(self): client = TestClient() conf = """ [proxies] """ save(client.cache.conan_conf_path, conf) requester = ConanRequester(client.cache.config) def verify_env(url, **kwargs): self.assertTrue("HTTP_PROXY" in os.environ) with tools.environment_append({"HTTP_PROXY": "my_system_proxy"}): requester._http_requester.get = verify_env requester.get("MyUrl")
def test_requester_timeout(self): client = TestClient(requester_class=MyRequester) conf = """ [general] request_timeout=2 """ save(client.cache.conan_conf_path, conf) self.assertEqual(client.requester.get("MyUrl"), 2.0) with tools.environment_append({"CONAN_REQUEST_TIMEOUT": "4.3"}): client = TestClient(requester_class=MyRequester) self.assertEqual(client.requester.get("MyUrl"), 4.3)
def test_vcvars_filter_known_paths(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "Windows" settings.compiler = "Visual Studio" settings.compiler.version = "15" settings.arch = "x86" settings.arch_build = "x86_64" with tools.environment_append({"PATH": ["custom_path", "WindowsFake"]}): tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=True, output=self.output) with tools.environment_append(tmp): self.assertNotIn("custom_path", os.environ["PATH"]) self.assertIn("WindowsFake", os.environ["PATH"]) tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=False, output=self.output) with tools.environment_append(tmp): self.assertIn("custom_path", os.environ["PATH"]) self.assertIn("WindowsFake", os.environ["PATH"])
def test_profile(): myprofile = textwrap.dedent(""" # define MyVar1 =MyValue1 # append MyVar2+=MyValue2 # multiple append works MyVar2+=MyValue2_2 # prepend MyVar3=+MyValue3 # unset MyVar4=! # Empty MyVar5= # PATHS # define MyPath1=(path)/my/path1 # append MyPath2+=(path)/my/path2 # multiple append works MyPath2+=(path)/my/path2_2 # prepend MyPath3=+(path)/my/path3 # unset MyPath4=! # PER-PACKAGE mypkg*:MyVar2=MyValue2 """) profile_env = ProfileEnvironment.loads(myprofile) env = profile_env.get_profile_env("") env = env.vars(ConanFileMock()) with environment_append({ "MyVar1": "$MyVar1", "MyVar2": "$MyVar2", "MyVar3": "$MyVar3", "MyVar4": "$MyVar4" }): assert env.get("MyVar1") == "MyValue1" assert env.get("MyVar2", "$MyVar2") == '$MyVar2 MyValue2 MyValue2_2' assert env.get("MyVar3", "$MyVar3") == 'MyValue3 $MyVar3' assert env.get("MyVar4") == "" assert env.get("MyVar5") == '' env = profile_env.get_profile_env("mypkg1/1.0") env = env.vars(ConanFileMock()) assert env.get("MyVar1") == "MyValue1" assert env.get("MyVar2", "$MyVar2") == 'MyValue2'
def run_in_bash_test(self): class MockConanfile(object): def __init__(self): self.output = namedtuple("output", "info")(lambda x: None) # @UnusedVariable self.env = {"PATH": "/path/to/somewhere"} class MyRun(object): def __call__(self, command, output, log_filepath=None, cwd=None, subprocess=False): # @UnusedVariable self.command = command self._conan_runner = MyRun() conanfile = MockConanfile() with patch.object(OSInfo, "bash_path", return_value='bash'): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn("bash", conanfile._conan_runner.command) self.assertIn("--login -c", conanfile._conan_runner.command) self.assertIn("^&^& a_command.bat ^", conanfile._conan_runner.command) with tools.environment_append({"CONAN_BASH_PATH": "path\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin") self.assertIn('path\\to\\mybash.exe --login -c', conanfile._conan_runner.command) with tools.environment_append({"CONAN_BASH_PATH": "path with spaces\\to\\mybash.exe"}): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", with_login=False) self.assertIn('"path with spaces\\to\\mybash.exe" -c', conanfile._conan_runner.command) # try to append more env vars conanfile = MockConanfile() with patch.object(OSInfo, "bash_path", return_value='bash'): tools.run_in_windows_bash(conanfile, "a_command.bat", subsystem="cygwin", env={"PATH": "/other/path", "MYVAR": "34"}) self.assertIn('^&^& PATH=\\^"/cygdrive/other/path:/cygdrive/path/to/somewhere:$PATH\\^" ' '^&^& MYVAR=34 ^&^& a_command.bat ^', conanfile._conan_runner.command)
def test_dont_upload_non_built_packages(self): ts = TestServer(users={"user": "******"}) tc = TestClient(servers={"default": ts}, users={"default": [("user", "password")]}) tc.save({"conanfile.py": self.conanfile}) with environment_append({ "CONAN_UPLOAD": ts.fake_url, "CONAN_LOGIN_USERNAME": "******", "CONAN_PASSWORD": "******", "CONAN_USERNAME": "******" }): mulitpackager = get_patched_multipackager( tc, exclude_vcvars_precommand=True) mulitpackager.add({}, {"shared": True}) mulitpackager.add({}, {"shared": False}) mulitpackager.run() self.assertIn("Uploading package 1/2", tc.out) self.assertIn("Uploading package 2/2", tc.out) # With the same cache and server try to rebuild them with policy missing mulitpackager = get_patched_multipackager( tc, build_policy="missing", exclude_vcvars_precommand=True) mulitpackager.add({}, {"shared": True}) mulitpackager.add({}, {"shared": False}) mulitpackager.run() self.assertIn( "Skipping upload for 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", tc.out) self.assertIn( "Skipping upload for 2a623e3082a38f90cd2c3d12081161412de331b0", tc.out) self.assertNotIn("HALLO", tc.out) # Without any build policy they get built mulitpackager = get_patched_multipackager( tc, exclude_vcvars_precommand=True) mulitpackager.add({}, {"shared": True}) mulitpackager.add({}, {"shared": False}) mulitpackager.run() self.assertNotIn( "Skipping upload for 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", tc.out) self.assertNotIn( "Skipping upload for 2a623e3082a38f90cd2c3d12081161412de331b0", tc.out) self.assertIn("Uploading package 1/2", tc.out) self.assertIn("Uploading package 2/2", tc.out) self.assertIn("HALLO", tc.out)
def test_existing_upload_repo(self): self.api.remote_add("my_upload_repo", "https://api.bintray.com/conan/conan-community/conan") self.save_conanfile(self.conanfile) with tools.environment_append({"CONAN_PASSWORD": "******"}): mp = ConanMultiPackager(username="******", out=self.output.write, ci_manager=self.ci_manager, upload=["https://api.bintray.com/conan/conan-community/conan", False, "othername"]) mp.add({}, {}, {}) with self.assertRaisesRegexp(ConanException, "Wrong user or password"): mp.run() # The upload repo is kept because there is already an url # FIXME: Probaby we should rename if name is different (Conan 1.3) self.assertIn("Remote for URL 'https://api.bintray.com/conan/conan-community/conan' " "already exist, keeping the current remote and its name", self.output)