Пример #1
0
    def test_config_hooks(self):
        # Make sure the conan.conf hooks information is appended
        folder = temp_folder(path_with_spaces=False)
        conan_conf = textwrap.dedent("""
            [hooks]
            foo
            custom/custom
            """)
        save_files(folder, {"config/conan.conf": conan_conf})
        client = TestClient()
        client.run('config install "%s"' % folder)
        self.assertIn("Processing conan.conf", client.out)
        content = load(client.cache.conan_conf_path)
        self.assertEqual(1, content.count("foo"))
        self.assertEqual(1, content.count("custom/custom"))

        config = ConanClientConfigParser(client.cache.conan_conf_path)
        hooks = config.get_item("hooks")
        self.assertIn("foo", hooks)
        self.assertIn("custom/custom", hooks)
        self.assertIn("attribute_checker", hooks)
        client.run('config install "%s"' % folder)
        self.assertIn("Processing conan.conf", client.out)
        content = load(client.cache.conan_conf_path)
        self.assertEqual(1, content.count("foo"))
        self.assertEqual(1, content.count("custom/custom"))
Пример #2
0
 def test_proxies(self):
     tmp_dir = temp_folder()
     save(os.path.join(tmp_dir, CONAN_CONF), "")
     config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF))
     self.assertEqual(None, config.proxies)
     save(os.path.join(tmp_dir, CONAN_CONF), "[proxies]")
     config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF))
     self.assertNotIn("no_proxy", config.proxies)
     save(os.path.join(tmp_dir, CONAN_CONF), "[proxies]\nno_proxy=localhost")
     config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF))
     self.assertEqual(config.proxies["no_proxy"], "localhost")
Пример #3
0
    def conan_config(self):
        if not self._conan_config:
            if not os.path.exists(self.conan_conf_path):
                save(self.conan_conf_path, normalize(default_client_conf))

            self._conan_config = ConanClientConfigParser(self.conan_conf_path)
        return self._conan_config
Пример #4
0
 def test_quotes(self):
     tmp_dir = temp_folder()
     save(os.path.join(tmp_dir, CONAN_CONF), default_client_conf)
     save(os.path.join(tmp_dir, DEFAULT_PROFILE_NAME), default_profile)
     config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF))
     self.assertEqual(config.env_vars["CONAN_TRACE_FILE"],
                      "Path/with/quotes")
Пример #5
0
    def setUpClass(cls):
        if not cls.server:
            cls.server = TestServerLauncher(
                server_capabilities=['ImCool', 'TooCool'])
            cls.server.start()

            filename = os.path.join(temp_folder(), "conan.conf")
            save(filename, "")
            config = ConanClientConfigParser(filename)
            requester = ConanRequester(config, requests)
            client_factory = RestApiClientFactory(TestBufferConanOutput(),
                                                  requester=requester,
                                                  config=config)
            localdb = LocalDBMock()

            mocked_user_io = UserIO(out=TestBufferConanOutput())
            mocked_user_io.get_username = Mock(return_value="private_user")
            mocked_user_io.get_password = Mock(return_value="private_pass")

            cls.auth_manager = ConanApiAuthManager(client_factory,
                                                   mocked_user_io, localdb)
            cls.remote = Remote("myremote",
                                "http://127.0.0.1:%s" % str(cls.server.port),
                                True, True)
            cls.auth_manager._authenticate(cls.remote,
                                           user="******",
                                           password="******")
            cls.api = client_factory.new(cls.remote, localdb.access_token,
                                         localdb.refresh_token, {})
Пример #6
0
    def env_setting_override_test(self):
        tmp_dir = temp_folder()
        save(os.path.join(tmp_dir, CONAN_CONF), default_client_conf)
        config = ConanClientConfigParser(os.path.join(tmp_dir, CONAN_CONF))

        # If I don't specify an ENV for compiler, the subsettings are kept,
        # except the compiler version that I'm overriding
        with tools.environment_append({"CONAN_ENV_COMPILER_VERSION": "4.6"}):
            settings = config.settings_defaults
            self.assertEquals(settings.as_list(),
                              [("arch", "x86_64"), ("build_type", "Release"),
                               ("compiler", "gcc"),
                               ("compiler.libcxx", "libstdc++"),
                               ("compiler.version", "4.6"), ("os", "Linux")])
        with tools.environment_append({}):
            settings = config.settings_defaults
            self.assertEquals(settings.as_list(),
                              [("arch", "x86_64"), ("build_type", "Release"),
                               ("compiler", "gcc"),
                               ("compiler.libcxx", "libstdc++"),
                               ("compiler.version", "4.9"), ("os", "Linux")])

        # If compiler is overwritten compiler subsettings are not assigned
        with tools.environment_append({"CONAN_ENV_COMPILER": "Visual Studio"}):
            settings = config.settings_defaults
            self.assertEquals(settings.as_list(),
                              [("arch", "x86_64"), ("build_type", "Release"),
                               ("compiler", "Visual Studio"), ("os", "Linux")])

        with tools.environment_append({
                "CONAN_ENV_COMPILER": "Visual Studio",
                "CONAN_ENV_COMPILER_VERSION": "14",
                "CONAN_ENV_COMPILER_RUNTIME": "MDd"
        }):
            settings = config.settings_defaults
            self.assertEquals(
                dict(settings.as_list()),
                dict([("arch", "x86_64"), ("build_type", "Release"),
                      ("compiler", "Visual Studio"),
                      ("compiler.version", "14"), ("compiler.runtime", "MDd"),
                      ("os", "Linux")]))

        # Specified settings are applied in order (first fake and then fake.setting)
        with tools.environment_append({
                "CONAN_ENV_FAKE": "Fake1",
                "CONAN_ENV_FAKE_SETTING": "Fake"
        }):
            settings = config.settings_defaults
            self.assertEquals(
                dict(settings.as_list()),
                dict([("arch", "x86_64"), ("build_type", "Release"),
                      ("compiler", "gcc"), ("compiler.libcxx", "libstdc++"),
                      ("compiler.version", "4.9"), ("os", "Linux"),
                      ("fake", "Fake1"), ("fake.setting", "Fake")]))
Пример #7
0
 def test_cache_config(self):
     file_path = os.path.join(temp_folder(), "whatever_cacert")
     save(file_path, "")
     conan_conf = os.path.join(temp_folder(), "conan.conf")
     save(conan_conf, normalize(default_client_conf))
     replace_in_file(conan_conf,
                     "# cacert_path",
                     "cacert_path={}".format(file_path),
                     output=TestBufferConanOutput())
     config = ConanClientConfigParser(conan_conf)
     mocked_requester = MockRequesterGet()
     requester = ConanRequester(config, mocked_requester)
     requester.get(url="bbbb", verify=True)
     self.assertEqual(mocked_requester.verify, file_path)
Пример #8
0
    def conan_config(self):
        def generate_default_config_file():
            default_settings = detect_defaults_settings(self._output)
            default_setting_values = Values.from_list(default_settings)
            client_conf = default_client_conf + default_setting_values.dumps()
            save(self.conan_conf_path, normalize(client_conf))

        if not self._conan_config:
            if not os.path.exists(self.conan_conf_path):
                generate_default_config_file()

            self._conan_config = ConanClientConfigParser(self.conan_conf_path)

        return self._conan_config
Пример #9
0
    def setUpClass(cls):
        if not cls.server:
            cls.server = TestServerLauncher(
                server_capabilities=['ImCool', 'TooCool'])
            cls.server.start()

            filename = os.path.join(temp_folder(), "conan.conf")
            save(filename, "")
            config = ConanClientConfigParser(filename)
            requester = ConanRequester(config, requests)
            cls.api = RestApiClient(TestBufferConanOutput(),
                                    requester=requester,
                                    revisions_enabled=False)
            cls.api.remote_url = "http://127.0.0.1:%s" % str(cls.server.port)

            # Authenticate user
            token = cls.api.authenticate("private_user", "private_pass")
            cls.api.token = token
Пример #10
0
 def config(self):
     if not self._config:
         self.initialize_config()
         self._config = ConanClientConfigParser(self.conan_conf_path)
     return self._config
Пример #11
0
 def _check(self, install_path):
     settings_path = self.client.client_cache.settings_path
     self.assertEqual(load(settings_path).splitlines(), settings_yml.splitlines())
     registry_path = self.client.client_cache.registry
     registry = RemoteRegistry(registry_path, TestBufferConanOutput())
     self.assertEqual(registry.remotes,
                      [Remote("myrepo1", "https://myrepourl.net", False),
                       Remote("my-repo-2", "https://myrepo2.com", True),
                       ])
     self.assertEqual(registry.refs, {"MyPkg/0.1@user/channel": "my-repo-2"})
     self.assertEqual(sorted(os.listdir(self.client.client_cache.profiles_path)),
                      sorted(["default", "linux", "windows"]))
     self.assertEqual(load(os.path.join(self.client.client_cache.profiles_path, "linux")).splitlines(),
                      linux_profile.splitlines())
     self.assertEqual(load(os.path.join(self.client.client_cache.profiles_path, "windows")).splitlines(),
                      win_profile.splitlines())
     conan_conf = ConanClientConfigParser(self.client.client_cache.conan_conf_path)
     self.assertEqual(conan_conf.get_item("log.run_to_output"), "False")
     self.assertEqual(conan_conf.get_item("log.run_to_file"), "False")
     self.assertEqual(conan_conf.get_item("log.level"), "10")
     self.assertEqual(conan_conf.get_item("general.compression_level"), "6")
     self.assertEqual(conan_conf.get_item("general.sysrequires_sudo"), "True")
     self.assertEqual(conan_conf.get_item("general.cpu_count"), "1")
     self.assertEqual(conan_conf.get_item("general.config_install"), install_path)
     self.assertEqual(conan_conf.get_item("proxies.no_proxy"), "mylocalhost")
     self.assertEqual(conan_conf.get_item("proxies.https"), "None")
     self.assertEqual(conan_conf.get_item("proxies.http"), "http://*****:*****@10.10.1.10:3128/")
     self.assertEqual("#Custom pylint",
                      load(os.path.join(self.client.client_cache.conan_folder, "pylintrc")))
Пример #12
0
 def test_log_level_names_env_var_invalid(self):
     with environment_append({"CONAN_LOGGING_LEVEL": "WakaWaka"}):
         save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf)
         config = ConanClientConfigParser(
             os.path.join(self.tmp_dir, CONAN_CONF))
         self.assertEqual(logging.CRITICAL, config.logging_level)
Пример #13
0
 def config_rm(self, item):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     config_parser.rm_item(item)
     self._client_cache.invalidate()
Пример #14
0
 def _check(self, install_path):
     settings_path = self.client.client_cache.settings_path
     self.assertEqual(load(settings_path).splitlines(), settings_yml.splitlines())
     registry_path = self.client.client_cache.registry
     registry = RemoteRegistry(registry_path, TestBufferConanOutput())
     self.assertEqual(registry.remotes,
                      [Remote("myrepo1", "https://myrepourl.net", False),
                       Remote("my-repo-2", "https://myrepo2.com", True),
                       ])
     self.assertEqual(registry.refs, {"MyPkg/0.1@user/channel": "my-repo-2"})
     self.assertEqual(sorted(os.listdir(self.client.client_cache.profiles_path)),
                      sorted(["default", "linux", "windows"]))
     self.assertEqual(load(os.path.join(self.client.client_cache.profiles_path, "linux")).splitlines(),
                      linux_profile.splitlines())
     self.assertEqual(load(os.path.join(self.client.client_cache.profiles_path, "windows")).splitlines(),
                      win_profile.splitlines())
     conan_conf = ConanClientConfigParser(self.client.client_cache.conan_conf_path)
     self.assertEqual(conan_conf.get_item("log.run_to_output"), "False")
     self.assertEqual(conan_conf.get_item("log.run_to_file"), "False")
     self.assertEqual(conan_conf.get_item("log.level"), "10")
     self.assertEqual(conan_conf.get_item("general.compression_level"), "6")
     self.assertEqual(conan_conf.get_item("general.sysrequires_sudo"), "True")
     self.assertEqual(conan_conf.get_item("general.cpu_count"), "1")
     self.assertEqual(conan_conf.get_item("general.config_install"), install_path)
     self.assertEqual(conan_conf.get_item("proxies.no_proxy"), "mylocalhost")
     self.assertEqual(conan_conf.get_item("proxies.https"), "None")
     self.assertEqual(conan_conf.get_item("proxies.http"), "http://*****:*****@10.10.1.10:3128/")
     self.assertEqual("#Custom pylint",
                      load(os.path.join(self.client.client_cache.conan_folder, "pylintrc")))
     self.assertEqual("",
                      load(os.path.join(self.client.client_cache.conan_folder, "python",
                                        "__init__.py")))
Пример #15
0
 def test_log_level_numbers_env_var_debug(self):
     with environment_append({"CONAN_LOGGING_LEVEL": "10"}):
         save(os.path.join(self.tmp_dir, CONAN_CONF), default_client_conf)
         config = ConanClientConfigParser(
             os.path.join(self.tmp_dir, CONAN_CONF))
         self.assertEqual(logging.DEBUG, config.logging_level)
Пример #16
0
 def test_log_level_numbers_invalid(self):
     save(os.path.join(self.tmp_dir, CONAN_CONF),
          default_client_conf_log.format("level = wakawaka"))
     config = ConanClientConfigParser(os.path.join(self.tmp_dir,
                                                   CONAN_CONF))
     self.assertEqual(logging.CRITICAL, config.logging_level)
Пример #17
0
 def test_log_level_numbers_debug(self):
     save(os.path.join(self.tmp_dir, CONAN_CONF),
          default_client_conf_log.format("level = 10"))
     config = ConanClientConfigParser(os.path.join(self.tmp_dir,
                                                   CONAN_CONF))
     self.assertEqual(logging.DEBUG, config.logging_level)
Пример #18
0
 def config_get(self, item):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     self._user_io.out.info(config_parser.get_item(item))
     return config_parser.get_item(item)
Пример #19
0
 def config_set(self, item, value):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     config_parser.set_item(item, value)
     self._client_cache.invalidate()
Пример #20
0
 def config_rm(self, item):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     config_parser.rm_item(item)
Пример #21
0
 def config_set(self, item, value):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     config_parser.set_item(item, value)
Пример #22
0
 def test_log_level_names_critical(self):
     save(os.path.join(self.tmp_dir, CONAN_CONF),
          default_client_conf_log.format("level = Critical"))
     config = ConanClientConfigParser(os.path.join(self.tmp_dir,
                                                   CONAN_CONF))
     self.assertEqual(logging.CRITICAL, config.logging_level)
Пример #23
0
 def _check(self, params):
     typ, uri, verify, args = [p.strip() for p in params.split(",")]
     configs = json.loads(load(self.client.cache.config_install_file))
     config = _ConfigOrigin(configs[-1])  # Check the last one
     self.assertEqual(config.type, typ)
     self.assertEqual(config.uri, uri)
     self.assertEqual(str(config.verify_ssl), verify)
     self.assertEqual(str(config.args), args)
     settings_path = self.client.cache.settings_path
     self.assertEqual(
         load(settings_path).splitlines(), settings_yml.splitlines())
     cache_remotes = self.client.cache.registry.load_remotes()
     self.assertEqual(list(cache_remotes.values()), [
         Remote("myrepo1", "https://myrepourl.net", False, False),
         Remote("my-repo-2", "https://myrepo2.com", True, False),
     ])
     self.assertEqual(sorted(os.listdir(self.client.cache.profiles_path)),
                      sorted(["default", "linux", "windows"]))
     self.assertEqual(
         load(os.path.join(self.client.cache.profiles_path,
                           "linux")).splitlines(),
         linux_profile.splitlines())
     self.assertEqual(
         load(os.path.join(self.client.cache.profiles_path,
                           "windows")).splitlines(),
         win_profile.splitlines())
     conan_conf = ConanClientConfigParser(self.client.cache.conan_conf_path)
     self.assertEqual(conan_conf.get_item("log.run_to_output"), "False")
     self.assertEqual(conan_conf.get_item("log.run_to_file"), "False")
     self.assertEqual(conan_conf.get_item("log.level"), "10")
     self.assertEqual(conan_conf.get_item("general.compression_level"), "6")
     self.assertEqual(
         conan_conf.get_item("general.default_package_id_mode"),
         "full_package_mode")
     self.assertEqual(conan_conf.get_item("general.sysrequires_sudo"),
                      "True")
     self.assertEqual(conan_conf.get_item("general.cpu_count"), "1")
     with six.assertRaisesRegex(self, ConanException,
                                "'config_install' doesn't exist"):
         conan_conf.get_item("general.config_install")
     self.assertEqual(conan_conf.get_item("proxies.https"), "None")
     self.assertEqual(conan_conf.get_item("proxies.http"),
                      "http://*****:*****@10.10.1.10:3128/")
     self.assertEqual(
         "#Custom pylint",
         load(os.path.join(self.client.cache_folder, "pylintrc")))
     self.assertEqual(
         "",
         load(
             os.path.join(self.client.cache_folder, "python",
                          "__init__.py")))
     self.assertEqual(
         "#hook dummy",
         load(os.path.join(self.client.cache_folder, "hooks", "dummy")))
     self.assertEqual(
         "#hook foo",
         load(os.path.join(self.client.cache_folder, "hooks", "foo.py")))
     self.assertEqual(
         "#hook custom",
         load(
             os.path.join(self.client.cache_folder, "hooks", "custom",
                          "custom.py")))
     self.assertFalse(
         os.path.exists(
             os.path.join(self.client.cache_folder, "hooks", ".git")))
     self.assertFalse(
         os.path.exists(os.path.join(self.client.cache_folder, ".git")))
Пример #24
0
 def config_get(self, item):
     config_parser = ConanClientConfigParser(self._client_cache.conan_conf_path)
     self._user_io.out.info(config_parser.get_item(item))
     return config_parser.get_item(item)