Beispiel #1
0
    def test_1(self):
        """Test just the root config file."""

        # do a full validation of a config
        c = Config([self.root_config_file], locked=True)
        c.validate_data()

        # check a few expected settings
        c = Config([self.root_config_file], locked=True)
        self._test_basic(c)
        self.assertEqual(c.warn_all, False)
        self.assertEqual(c.build_directory, "build")

        # check user path expansion
        self.assertEqual(c.local_packages_path,
                         os.path.expanduser(os.path.join("~", "packages")))

        # check access to plugins settings common to a plugin type
        self.assertEqual(c.plugins.release_vcs.tag_name, '{qualified_name}')

        # check access to plugins settings
        self.assertEqual(c.plugins.release_hook.emailer.smtp_port, 25)

        # check system attribute expansion
        expected_value = "*****@*****.**" % system.user
        self.assertEqual(c.plugins.release_hook.emailer.sender, expected_value)

        # check that an env-var override doesn't affect locked config
        os.environ["REZ_WARN_NONE"] = "true"
        self.assertEqual(c.warn_none, False)

        self._test_overrides(c)
Beispiel #2
0
    def test_5(self):
        """Test misconfigurations."""

        # overrides set to bad types
        overrides = {
            "build_directory": [],
            "plugins": {
                "release_hook": {
                    "emailer": {
                        "recipients": 42
                    }
                }
            }
        }
        c = Config([self.root_config_file], overrides=overrides, locked=False)
        with self.assertRaises(ConfigurationError):
            _ = c.build_directory
        with self.assertRaises(ConfigurationError):
            _ = c.plugins.release_hook.emailer.recipients

        # missing keys
        conf = os.path.join(self.config_path, "test1.yaml")
        c = Config([conf], locked=True)

        with self.assertRaises(ConfigurationError):
            _ = c.debug_all  # noqa
Beispiel #3
0
    def test_4(self):
        """Test package config overrides."""
        conf = os.path.join(self.config_path, "test2.py")
        config2 = Config([self.root_config_file, conf])

        with _replace_config(config2):
            pkg = get_developer_package(self.config_path)
            c = pkg.config
            self._test_basic(c)

            # check overrides from package.py are working
            os.environ["REZ_BUILD_DIRECTORY"] = "foo"  # should have no effect
            self.assertEqual(c.build_directory, "weeble")
            self.assertEqual(c.plugins.release_vcs.tag_name, "tag")

            # check list modification is working
            self.assertEqual(c.release_hooks, ["foo", "bah"])

            # check list modification within plugin settings is working
            self.assertEqual(c.plugins.release_hook.emailer.recipients,
                             ["*****@*****.**", "*****@*****.**"])

            # check system expansion in package overridden setting works
            expected_value = "*****@*****.**" % system.user
            self.assertEqual(c.plugins.release_hook.emailer.sender, expected_value)

            # check env-var expansion in package overridden setting works
            os.environ["FUNK"] = "dude"
            expected_value = ["FOO", "BAH_dude", "EEK"]
            self.assertEqual(c.parent_variables, expected_value)

            self._test_overrides(c)
Beispiel #4
0
    def setUpClass(cls):
        packages_path = cls.data_path("solver", "packages")
        cls.settings = dict(
            packages_path=[packages_path],
            package_filter=None)

        cls.config = Config([get_module_root_config()], locked=True)
Beispiel #5
0
    def setUpClass(cls):
        path = os.path.dirname(__file__)
        packages_path = os.path.join(path, "data", "solver", "packages")
        cls.settings = dict(
            packages_path=[packages_path],
            package_filter=None)

        cls.config = Config([get_module_root_config()], locked=True)
Beispiel #6
0
    def test_2(self):
        """Test a config with an overriding file."""
        conf = os.path.join(self.config_path, "test1.yaml")
        c = Config([self.root_config_file, conf], locked=True)
        self._test_basic(c)

        # check overrides in test1.yaml are being used
        self.assertEqual(c.warn_all, True)
        self.assertEqual(c.plugins.release_vcs.tag_name, "foo")
        self.assertEqual(c.plugins.release_hook.emailer.sender, "santa.claus")

        self._test_overrides(c)
Beispiel #7
0
    def test_7(self):
        """Test path list environment variable with whitespace."""
        c = Config([self.root_config_file], locked=False)

        # test basic env-var override
        packages_path = [
            "c:/foo bar/baz", "c:/foo 2 bar/baz", r"c:\foo bar\baz",
            "/home/foo bar/baz", r"/home/foo\ bar/baz"
        ]
        os.environ["REZ_PACKAGES_PATH"] = os.pathsep.join(packages_path)

        self.assertEqual(c.packages_path, packages_path)
Beispiel #8
0
    def test_1(self):
        """Test just the root config file."""

        # do a full validation of a config
        c = Config([self.root_config_file], locked=True)
        c.validate_data()

        # check a few expected settings
        c = Config([self.root_config_file], locked=True)
        self._test_basic(c)
        self.assertEqual(c.warn_all, False)
        self.assertEqual(c.build_directory, "build")

        # check user path expansion
        self.assertEqual(c.local_packages_path,
                         os.path.expanduser(os.path.join("~", "packages")))

        # check access to plugins settings common to a plugin type
        self.assertEqual(c.plugins.release_vcs.tag_name, '{qualified_name}')

        # check access to plugins settings
        self.assertEqual(c.plugins.release_hook.emailer.smtp_port, 25)

        # check system attribute expansion
        expected_value = "*****@*****.**" % system.user
        self.assertEqual(c.plugins.release_hook.emailer.sender, expected_value)

        # check that an env-var override doesn't affect locked config
        os.environ["REZ_WARN_NONE"] = "true"
        self.assertEqual(c.warn_none, False)

        self._test_overrides(c)
Beispiel #9
0
    def test_8(self):
        """Test CLI dict/list value JSON round trip."""
        import json
        import rez.cli._main

        cli_file = rez.cli._main.__file__

        # python /path/to/rez/cli/_main.py config ...
        config_args = [os.sys.executable, cli_file, "config"]

        c = Config([self.root_config_file], locked=True)
        env = {
            key: value
            for key, value in os.environ.items() if not key.startswith("REZ_")
        }

        env.update({"REZ_DISABLE_HOME_CONFIG": "1"})

        test_configs = {
            "packages_path":
            ["/foo bar/baz", "/foo bar/baz hey", "/home/foo bar/baz"],
            "platform_map": {
                "foo": {
                    "bar": "baz"
                }
            },
        }
        for config_key, test_value in test_configs.items():
            try:
                # Test fetching default value
                stdout = subprocess.check_output(
                    config_args + ["--json", config_key],
                    env=env,
                )
                self.assertEqual(
                    six.ensure_str(stdout).strip(),
                    six.ensure_str(json.dumps(getattr(c, config_key))),
                )

                # Test setting via env var and fetching custom value
                test_json_value = six.ensure_str(json.dumps(test_value))
                env["REZ_%s_JSON" % config_key.upper()] = test_json_value
                stdout = subprocess.check_output(
                    config_args + ["--json", config_key],
                    env=env,
                )
                self.assertEqual(stdout.decode().strip(), test_json_value)
            except subprocess.CalledProcessError as error:
                print(error.stdout)
                raise
Beispiel #10
0
    def test_3(self):
        """Test environment variable config overrides."""
        c = Config([self.root_config_file], locked=False)

        # test basic env-var override
        os.environ["REZ_WARN_ALL"] = "1"
        self.assertEqual(c.warn_all, True)
        self._test_basic(c)

        # test env-var override that contains a system expansion
        REZ_TMPDIR_ = os.environ.get("REZ_TMPDIR")
        os.environ["REZ_TMPDIR"] = "/tmp/{system.user}"
        expected_value = "/tmp/%s" % system.user
        self.assertEqual(c.tmpdir, expected_value)
        if REZ_TMPDIR_:
            os.environ["REZ_TMPDIR"] = REZ_TMPDIR_
        else:
            del os.environ["REZ_TMPDIR"]
        c._uncache("tmpdir")

        # _test_overrides overrides this value, so here we're making sure
        # that an API override takes precedence over an env-var override
        os.environ["BUILD_DIRECTORY"] = "flaabs"
        self._test_overrides(c)
Beispiel #11
0
    def test_3(self):
        """Test environment variable config overrides."""
        c = Config([self.root_config_file], locked=False)

        # test basic env-var override
        os.environ["REZ_WARN_ALL"] = "1"
        self.assertEqual(c.warn_all, True)
        self._test_basic(c)

        # test env-var override that contains a system expansion
        REZ_TMPDIR_ = os.environ.get("REZ_TMPDIR")
        os.environ["REZ_TMPDIR"] = "/tmp/{system.user}"
        expected_value = "/tmp/%s" % system.user
        self.assertEqual(c.tmpdir, expected_value)
        if REZ_TMPDIR_:
            os.environ["REZ_TMPDIR"] = REZ_TMPDIR_
        else:
            del os.environ["REZ_TMPDIR"]
        c._uncache("tmpdir")

        # _test_overrides overrides this value, so here we're making sure
        # that an API override takes precedence over an env-var override
        os.environ["BUILD_DIRECTORY"] = "flaabs"
        self._test_overrides(c)