Пример #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"])
                   })
Пример #2
0
    def test_5(self):
        """Test control flow using externally-set env vars."""
        def _rex():
            if defined("EXT") and env.EXT == "alpha":
                env.EXT_FOUND = 1
                env.EXT.append("beta")  # will still overwrite
            else:
                env.EXT_FOUND = 0
                if undefined("EXT"):
                    info("undefined working as expected")

        # with EXT undefined
        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('EXT_FOUND', '0'),
                       Info("undefined working as expected")
                   ],
                   expected_output={'EXT_FOUND': '0'})

        # with EXT defined
        self._test(
            func=_rex,
            env={"EXT": "alpha"},
            expected_actions=[Setenv('EXT_FOUND', '1'),
                              Setenv('EXT', 'beta')],
            expected_output={
                'EXT_FOUND': '1',
                'EXT': 'beta'
            })
Пример #3
0
    def test_4(self):
        """Test control flow using internally-set env vars."""
        def _rex():
            env.FOO = "foo"
            setenv("BAH", "bah")
            env.EEK = "foo"

            if env.FOO == "foo":
                env.FOO_VALID = 1
                info("FOO validated")

            if env.FOO == env.EEK:
                comment("comparison ok")

        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('FOO', 'foo'),
                       Setenv('BAH', 'bah'),
                       Setenv('EEK', 'foo'),
                       Setenv('FOO_VALID', '1'),
                       Info('FOO validated'),
                       Comment('comparison ok')
                   ],
                   expected_output={
                       'FOO': 'foo',
                       'BAH': 'bah',
                       'EEK': 'foo',
                       'FOO_VALID': '1'
                   })
Пример #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"])
Пример #5
0
    def _test_rextest_package(self, version):
        pkg = VersionedObject("rextest-%s" % version)

        cmds = [Setenv('REZ_USED_REQUEST', str(pkg)),
                Setenv('REZ_USED_RESOLVE', str(pkg))]
        cmds += self._get_rextest_commands(pkg)

        self._test_package(pkg, {}, cmds)
        # first prepend should still override
        self._test_package(pkg, {"REXTEST_DIRS": "TEST"}, cmds)
Пример #6
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"])
                   })
Пример #7
0
    def test_2(self):
        """Test simple setenvs and assignments."""
        def _rex():
            env.FOO = "foo"
            setenv("BAH", "bah")
            env.EEK = env.FOO

        self._test(func=_rex,
                   env={},
                   expected_actions = [
                       Setenv('FOO', 'foo'),
                       Setenv('BAH', 'bah'),
                       Setenv('EEK', 'foo')],
                   expected_output = {
                       'FOO': 'foo',
                       'EEK': 'foo',
                       'BAH': 'bah'})
Пример #8
0
    def test_6(self):
        """Test variable expansion."""
        def _rex():
            env.FOO = "foo"
            env.DOG = "$FOO"  # this will convert to '${FOO}'
            env.BAH = "${FOO}"
            env.EEK = "${BAH}"
            if env.BAH == "foo" and getenv("EEK") == "foo":
                info("expansions visible in control flow")

            if defined("EXT") and getenv("EXT") == "alpha":
                env.FEE = "${EXT}"

        # with EXT undefined
        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('FOO', 'foo'),
                       Setenv('DOG', '${FOO}'),
                       Setenv('BAH', '${FOO}'),
                       Setenv('EEK', '${BAH}'),
                       Info('expansions visible in control flow')
                   ],
                   expected_output={
                       'FOO': 'foo',
                       'DOG': 'foo',
                       'BAH': 'foo',
                       'EEK': 'foo'
                   })

        # with EXT defined
        self._test(func=_rex,
                   env={"EXT": "alpha"},
                   expected_actions=[
                       Setenv('FOO', 'foo'),
                       Setenv('DOG', '${FOO}'),
                       Setenv('BAH', '${FOO}'),
                       Setenv('EEK', '${BAH}'),
                       Info('expansions visible in control flow'),
                       Setenv('FEE', '${EXT}')
                   ],
                   expected_output={
                       'FOO': 'foo',
                       'DOG': 'foo',
                       'FEE': 'foo',
                       'BAH': 'foo',
                       'EEK': 'foo',
                       'FEE': 'alpha'
                   })
Пример #9
0
    def _get_rextest_commands(self, pkg):
        verstr = str(pkg.version)
        base = os.path.join(self.packages_path, "rextest", verstr)

        major_version = str(pkg.version[0] if len(pkg.version) >= 1 else '')
        minor_version = str(pkg.version[1] if len(pkg.version) >= 2 else '')
        patch_version = str(pkg.version[2] if len(pkg.version) >= 3 else '')

        cmds = [Setenv('REZ_REXTEST_VERSION', verstr),
                Setenv('REZ_REXTEST_MAJOR_VERSION', major_version),
                Setenv('REZ_REXTEST_MINOR_VERSION', minor_version),
                Setenv('REZ_REXTEST_PATCH_VERSION', patch_version),
                Setenv('REZ_REXTEST_BASE', base),
                Setenv('REZ_REXTEST_ROOT', base),
                # from package...
                Setenv('REXTEST_ROOT', base),
                Setenv('REXTEST_VERSION', verstr),
                Setenv('REXTEST_MAJOR_VERSION', str(pkg.version[0])),
                Setenv('REXTEST_DIRS', "/".join([base, "data"])),
                Alias('rextest', 'foobar')]
        return cmds
Пример #10
0
 def _get_rextest_commands(self, pkg):
     verstr = str(pkg.version)
     base = os.path.join(self.packages_path, "rextest", verstr)
     cmds = [
         Setenv('REZ_REXTEST_VERSION', verstr),
         Setenv('REZ_REXTEST_BASE', base),
         Setenv('REZ_REXTEST_ROOT', base),
         Setenv('REXTEST_ROOT', base),
         Setenv('REXTEST_VERSION', verstr),
         Setenv('REXTEST_MAJOR_VERSION', str(pkg.version[0])),
         Setenv('REXTEST_DIRS', "/".join([base, "data"])),
         Alias('rextest', 'foobar')
     ]
     return cmds
Пример #11
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'
                   })
Пример #12
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)