Exemple #1
0
    def test_repr(self):
        utils.init()
        utils.flake_cmd(prop=False, glob=False)
        utils.mypy_cmd(prop=False, glob=False)
        e = utils.env()
        assert re.match(
            (r"# Variables\n"
             r"root: Field = PosixPath\('.*'\)\n"
             r"stage: Field = 'test'\n"
             r"envo_stage: Field = 'test'\n"
             r"pythonpath: Field = .*\n"
             r"# context\n"
             r"# command\n"
             r"""flake\(test_arg: str = ""\) -> str   {glob=False, prop=False}\n"""
             r"""mypy\(test_arg: str = ""\) -> None   {glob=False, prop=False}\n"""
             r"# precmd\n"
             r"# onstdout\n"
             r"# onstderr\n"
             r"# postcmd\n"
             r"# onload\n"
             r"# oncreate\n"
             r"# ondestroy\n"
             r"# onunload"),
            repr(e),
        )

        utils.init()
        utils.flake_cmd(prop=True, glob=False)
        utils.mypy_cmd(prop=True, glob=False)
        e = utils.env()
        assert re.match(
            (r"# Variables\n"
             r"root: Field = PosixPath\('.*'\)\n"
             r"stage: Field = 'test'\n"
             r"envo_stage: Field = 'test'\n"
             r"pythonpath: Field = .*\n"
             r"# context\n"
             r"# command\n"
             r"""flake\(test_arg: str = ""\) -> str   {glob=False, prop=True}\n"""
             r"""mypy\(test_arg: str = ""\) -> None   {glob=False, prop=True}\n"""
             r"# precmd\n"
             r"# onstdout\n"
             r"# onstderr\n"
             r"# postcmd\n"
             r"# onload\n"
             r"# oncreate\n"
             r"# ondestroy\n"
             r"# onunload"),
            repr(e),
        )

        utils.init()
        utils.mypy_cmd(prop=True, glob=False)
Exemple #2
0
    def test_property_cmd_no_ret(self, capsys):
        utils.init()
        utils.mypy_cmd(prop=True, glob=False)

        e = utils.env()
        assert repr(e.mypy) == "\b"
        assert capsys.readouterr().out == "Mypy all good\n"
Exemple #3
0
    def test_parents_basic_functionality(self, init_child_env):
        sandbox_dir = Path(".").absolute()
        child_dir = sandbox_dir / "child"

        utils.replace_in_code('name = "sandbox"', 'name = "pa"')
        utils.add_declaration("test_parent_var: str")
        utils.add_definition('self.test_parent_var = "test_parent_value"')

        utils.replace_in_code('name = "child"',
                              'name = "ch"',
                              file=child_dir / "env_comm.py")
        utils.add_declaration(
            "test_var: str",
            file=child_dir / "env_comm.py",
        )
        utils.add_definition(
            'self.test_var = "test_value"',
            file=child_dir / "env_comm.py",
        )

        child_env = utils.env(child_dir)

        assert child_env.get_parent() is not None
        assert child_env.test_var == "test_value"
        assert child_env.get_parent().test_parent_var == "test_parent_value"
        assert child_env.get_parent().get_name() == "pa"

        child_env.activate()
        assert os.environ["PA_TESTPARENTVAR"] == "test_parent_value"
        assert os.environ["CH_TESTVAR"] == "test_value"
Exemple #4
0
    def test_property_cmd(self, capsys):
        utils.init()
        utils.flake_cmd(prop=True, glob=False)

        e = utils.env()
        assert repr(e.flake) == "Flake return value"
        assert capsys.readouterr().out == "Flake all good\n"
Exemple #5
0
    def test_parents_variables_passed_through(self, init_child_env):
        sandbox_dir = Path(".").absolute()
        child_dir = sandbox_dir / "child"

        utils.replace_in_code('name = "sandbox"', 'name = "pa"')
        utils.add_declaration("path: Raw[str]")
        utils.add_definition("""
            import os
            self.path = os.environ["PATH"]
            self.path = "/parent_bin_dir:" + self.path
            """)

        utils.replace_in_code('name = "child"',
                              'name = "ch"',
                              file=child_dir / "env_comm.py")
        utils.add_declaration(
            "path: Raw[str]",
            file=child_dir / "env_comm.py",
        )
        utils.add_definition(
            """
            import os
            self.path = os.environ["PATH"]
            self.path = "/child_bin_dir:" + self.path
            """,
            file=child_dir / "env_comm.py",
        )

        child_env = utils.env(child_dir)
        child_env.activate()

        assert "child_bin_dir" in os.environ["PATH"]
        assert "parent_bin_dir" in os.environ["PATH"]
Exemple #6
0
    def test_raw(self):
        utils.add_declaration("""
            class Python(envo.BaseEnv):
                version: Raw[str]

            python: Python
            """)
        utils.add_definition(
            'self.python = self.Python(version="3.8.2")',
            file=Path("env_test.py"),
        )

        utils.add_declaration("version: Raw[str]")

        utils.add_definition(
            """
            self.python = self.Python(version="3.8.2")
            self.version = self.python.version + ".1"
            """,
            file=Path("env_test.py"),
        )

        e = utils.env()
        e.activate()
        assert os.environ["VERSION"] == "3.8.2.1"
Exemple #7
0
    def test_nested_raw(self):
        utils.add_declaration("value: Raw[str]")
        utils.add_definition("self.value = 'test_value'")

        e = utils.env()
        e.activate()
        assert os.environ["VALUE"] == "test_value"
Exemple #8
0
    def test_call_cmd(self, capsys):
        utils.init()
        utils.flake_cmd(prop=False, glob=False)

        e = utils.env()
        assert e.flake() == "Flake return value"
        assert capsys.readouterr().out == "Flake all good\n"
Exemple #9
0
    def test_verify_variable_undeclared(self):
        utils.add_definition("self.test_var = 12")

        e = utils.env()

        with pytest.raises(envo.EnvoError) as exc:
            e.activate()

        assert str(exc.value) == ('Variable "sandbox.test_var" is undeclared!')
Exemple #10
0
    def test_verify_unset_variable(self):
        utils.add_declaration("test_var: int")

        e = utils.env()

        with pytest.raises(envo.EnvoError) as exc:
            e.activate()

        assert str(exc.value) == ('Variable "sandbox.test_var" is unset!')
Exemple #11
0
    def test_verify_property(self):
        utils.add_declaration("value: str")
        utils.add_definition("self.value = 'test_value'")
        utils.add_command("""
            @property
            def prop(self) -> str:
                return self.value + "_modified"
            """)

        e = utils.env()

        assert e.prop == "test_value_modified"
Exemple #12
0
    def test_get_full_name(self, init_child_env):
        sandbox_dir = Path(".").absolute()
        child_dir = sandbox_dir / "child"

        utils.replace_in_code('name = "sandbox"', 'name = "pa"')
        utils.replace_in_code('name = "child"',
                              'name = "ch"',
                              file=child_dir / "env_comm.py")

        child_env = utils.env(child_dir)

        assert child_env.get_full_name() == "pa.ch"
Exemple #13
0
    def test_venv_addon(self):
        from tests.unit.utils import shell, env

        command("test", "--init=venv")

        shell()
        env = env()

        assert hasattr(env, "venv")
        env.activate()
        assert "SANDBOX_VENV_BIN" in os.environ
        assert f"{Path('.').absolute()}/.venv/bin" in os.environ["PATH"]

        flake8()
        mypy()
Exemple #14
0
    def test_venv_addon(self):
        Path("env_comm.py").unlink()
        Path("env_test.py").unlink()
        Path(".venv/lib/python3.8/site-packages").mkdir(parents=True)

        utils.command("test --init=venv")

        e = utils.env()

        assert hasattr(e, "venv")
        e.activate()
        assert "SANDBOX_VENV_BIN" in os.environ
        assert f"{Path('.').absolute()}/.venv/bin" in os.environ["PATH"]

        utils.flake8()
        utils.mypy()
Exemple #15
0
    def test_nested(self):
        utils.add_declaration("""
            class Python(envo.BaseEnv):
                version: str

            python: Python
            """)
        utils.add_definition(
            'self.python = self.Python(version="3.8.2")',
            file=Path("env_test.py"),
        )

        e = utils.env()
        e.activate()

        assert os.environ["SANDBOX_STAGE"] == "test"
        assert os.environ["SANDBOX_PYTHON_VERSION"] == "3.8.2"
Exemple #16
0
def env() -> Env:
    return utils.env()
Exemple #17
0
def env() -> Env:
    from tests.unit.utils import env

    return env()