def test_init_untouched_if_exists(self): file = Path("__init__.py") file.touch() file.write_text("a = 1") command("test", "--init") assert file.read_text() == "a = 1"
def test_cant_find_env(self): utils.command("prod") assert re.match(r".*Couldn.*find.*env", str(self.mock_logger_error.call_args_list[0].args)) self.mock_logger_error = None
def test_existing_init_py_recovered(self, init): init_file = Path("__init__.py") init_file.touch() init_file.write_text("import flask") command("test") assert init_file.read_text() == "import flask" assert not Path("__init__.py.tmp").exists()
def test_parents_variables_passed_through(self, child_env): os.chdir(test_root) child_dir = Path(".").absolute() / "parent_env/child_env" os.chdir(str(child_dir)) command("test") assert "child_bin_dir" in os.environ["PATH"] assert "parent_bin_dir" in os.environ["PATH"]
def test_save(self, init, caplog, capsys): command("test", "--save") assert len(caplog.messages) == 1 assert caplog.messages[0] == "Saved envs to .env_test 💾" assert Path(".env_test").exists() captured = capsys.readouterr() assert captured.out == "" assert captured.err == ""
def test_init_weird_dir_name(self, dir_name): env_dir = Path(dir_name) env_dir.mkdir() os.chdir(str(env_dir)) command("test", "--init") assert Path("env_comm.py").exists() assert Path("env_test.py").exists() command("test") flake8()
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()
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()
def test_parents_basic_functionality(self, child_env): os.chdir(test_root) parent_dir = Path(".").absolute() / "parent_env" child_dir = Path(".").absolute() / "parent_env/child_env" os.chdir(str(child_dir)) command("test") assert child_env.get_parent() is not None assert child_env.test_var == "test_var_value" assert child_env.get_parent().test_parent_var == "test_value" assert child_env.get_parent().get_name() == "pa" assert os.environ["PA_TESTPARENTVAR"] == "test_value" assert os.environ["CH_TESTVAR"] == "test_var_value" assert (child_dir / Path("__init__.py")).exists() assert not (child_dir / Path("__init__.py.tmp")).exists() assert (parent_dir / Path("__init__.py")).exists() assert not (parent_dir / Path("__init__.py.tmp")).exists() flake8() os.chdir(str(parent_dir))
def init() -> None: utils.command("--init")
def test_shell(self): utils.command("test")
def test_init_py_created(self, init, mocker): mocker.patch("envo.scripts.Path.unlink") command("test") assert Path("__init__.py").exists()
def test_get_current_stage(self, init, env_comm): command("local", "--init") command("stage", "--init") command("local") assert env_comm.get_current_stage().meta.stage == "local"
def test_dry_run(self, init, capsys, caplog): command("test", "--dry-run") captured = capsys.readouterr() assert captured.out != "" assert len(caplog.messages) == 0
def test_shell_module_with_the_same_name(self, init): Path("sandbox").mkdir() Path("sandbox/__init__.py").touch() command("test")
def test_shell(self, init): command("test")
def test_version(self, caplog): command("--version") assert caplog.messages[0] == "1.2.3" assert len(caplog.messages) == 1
def test_get_current_stage(self, env_comm): utils.command("local --init") utils.command("stage --init") utils.command("local") assert env_comm.get_current_env().meta.stage == "local"