Beispiel #1
0
    def test_8(self):
        """Custom environment variable separators."""

        config.override("env_var_separators", {"FOO": ",", "BAH": " "})

        def _rex():
            appendenv("FOO", "test1")
            env.FOO.append("test2")
            env.FOO.append("test3")

            env.BAH.prepend("A")
            prependenv("BAH", "B")
            env.BAH.append("C")

        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('FOO', 'test1'),
                       Appendenv('FOO', 'test2'),
                       Appendenv('FOO', 'test3'),
                       Setenv('BAH', 'A'),
                       Prependenv('BAH', 'B'),
                       Appendenv('BAH', 'C')
                   ],
                   expected_output={
                       'FOO': ",".join(["test1", "test2", "test3"]),
                       'BAH': " ".join(["B", "A", "C"])
                   })
Beispiel #2
0
    def test_2(self):
        """Resolve a package with a dependency, see that their commands are
        concatenated as expected."""
        pkg = VersionedObject("rextest2-2")
        base = os.path.join(self.packages_path, "rextest", "1.3")
        base2 = os.path.join(self.packages_path, "rextest2", "2")

        cmds = [
            Setenv('REZ_USED_REQUEST', "rextest2-2"),
            Setenv('REZ_USED_RESOLVE', "rextest-1.3 rextest2-2"),
            # rez's rextest vars
            Setenv('REZ_REXTEST_VERSION', "1.3"),
            Setenv('REZ_REXTEST_BASE', base),
            Setenv('REZ_REXTEST_ROOT', base),
            # rez's rextest2 vars
            Setenv('REZ_REXTEST2_VERSION', '2'),
            Setenv('REZ_REXTEST2_BASE', base2),
            Setenv('REZ_REXTEST2_ROOT', base2),
            # rextest's commands
            Setenv('REXTEST_ROOT', base),
            Setenv('REXTEST_VERSION', "1.3"),
            Setenv('REXTEST_MAJOR_VERSION', "1"),
            Setenv('REXTEST_DIRS', "/".join([base, "data"])),
            Alias('rextest', 'foobar'),
            # rextext2's commands
            Appendenv('REXTEST_DIRS', "/".join([base2, "data2"])),
            Setenv('REXTEST2_REXTEST_VER', '1.3'),
            Setenv('REXTEST2_REXTEST_BASE',
                   os.path.join(self.packages_path, "rextest", "1.3"))
        ]

        self._test_package(pkg, {}, cmds)
        # first prepend should still override
        self._test_package(pkg, {"REXTEST_DIRS": "TEST"}, cmds)
Beispiel #3
0
    def test_9(self):
        """Test literal and expandable strings."""
        def _rex():
            env.A = "hello"
            env.FOO = expandable("$A")  # will convert to '${A}'
            env.BAH = expandable("${A}")
            env.EEK = literal("$A")

        def _rex2():
            env.BAH = "omg"
            env.FOO.append("$BAH")
            env.FOO.append(literal("${BAH}"))
            env.FOO.append(expandable("like, ").l("$SHE said, ").e("$BAH"))

        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('A', 'hello'),
                       Setenv('FOO', '${A}'),
                       Setenv('BAH', '${A}'),
                       Setenv('EEK', '$A')
                   ],
                   expected_output={
                       'A': 'hello',
                       'FOO': 'hello',
                       'BAH': 'hello',
                       'EEK': '$A'
                   })

        self._test(func=_rex2,
                   env={},
                   expected_actions=[
                       Setenv('BAH', 'omg'),
                       Setenv('FOO', '${BAH}'),
                       Appendenv('FOO', '${BAH}'),
                       Appendenv('FOO', 'like, $SHE said, ${BAH}')
                   ],
                   expected_output={
                       'BAH':
                       'omg',
                       'FOO':
                       os.pathsep.join(['omg', '${BAH}', 'like']) +
                       ', $SHE said, omg'
                   })
Beispiel #4
0
    def test_3(self):
        """Test appending/prepending."""
        def _rex():
            appendenv("FOO", "test1")
            env.FOO.append("test2")
            env.FOO.append("test3")

            env.BAH.prepend("A")
            prependenv("BAH", "B")
            env.BAH.append("C")

        # no parent variables enabled
        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('FOO', 'test1'),
                       Appendenv('FOO', 'test2'),
                       Appendenv('FOO', 'test3'),
                       Setenv('BAH', 'A'),
                       Prependenv('BAH', 'B'),
                       Appendenv('BAH', 'C')
                   ],
                   expected_output={
                       'FOO': os.pathsep.join(["test1", "test2", "test3"]),
                       'BAH': os.pathsep.join(["B", "A", "C"])
                   })

        # FOO and BAH enabled as parent variables, but not present
        expected_actions = [
            Appendenv('FOO', 'test1'),
            Appendenv('FOO', 'test2'),
            Appendenv('FOO', 'test3'),
            Prependenv('BAH', 'A'),
            Prependenv('BAH', 'B'),
            Appendenv('BAH', 'C')
        ]

        self._test(func=_rex,
                   env={},
                   expected_actions=expected_actions,
                   expected_output={
                       'FOO': os.pathsep.join(["", "test1", "test2", "test3"]),
                       'BAH': os.pathsep.join(["B", "A", "", "C"])
                   },
                   parent_variables=["FOO", "BAH"])

        # FOO and BAH enabled as parent variables, and present
        self._test(func=_rex,
                   env={
                       "FOO": "tmp",
                       "BAH": "Z"
                   },
                   expected_actions=expected_actions,
                   expected_output={
                       'FOO':
                       os.pathsep.join(["tmp", "test1", "test2", "test3"]),
                       'BAH': os.pathsep.join(["B", "A", "Z", "C"])
                   },
                   parent_variables=["FOO", "BAH"])
Beispiel #5
0
    def test_1(self):
        """Test simple use of every available action."""
        def _rex():
            shebang()
            setenv("FOO", "foo")
            setenv("BAH", "bah")
            getenv("BAH")
            unsetenv("BAH")
            unsetenv("NOTEXIST")
            prependenv("A", "/tmp")
            prependenv("A", "/data")
            appendenv("B", "/tmp")
            appendenv("B", "/data")
            defined("BAH")
            undefined("BAH")
            defined("NOTEXIST")
            undefined("NOTEXIST")
            alias("thing", "thang")
            info("that's interesting")
            error("oh noes")
            command("runme --with --args")
            source("./script.src")

        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Shebang(),
                       Setenv('FOO', 'foo'),
                       Setenv('BAH', 'bah'),
                       Unsetenv('BAH'),
                       Unsetenv('NOTEXIST'),
                       Setenv('A', '/tmp'),
                       Prependenv('A', '/data'),
                       Setenv('B', '/tmp'),
                       Appendenv('B', '/data'),
                       Alias('thing', 'thang'),
                       Info("that's interesting"),
                       Error('oh noes'),
                       Command('runme --with --args'),
                       Source('./script.src')
                   ],
                   expected_output={
                       'FOO': 'foo',
                       'A': os.pathsep.join(["/data", "/tmp"]),
                       'B': os.pathsep.join(["/tmp", "/data"])
                   })