def test_save(self): from envo.comm.test_utils import spawn comm_file = Path("env_comm.py") comm_file.write_text(comm_file.read_text().replace( "# Declare your variables here", "test_var: str")) comm_file.write_text(comm_file.read_text().replace( "# Define your variables here", 'self.test_var = "test_value"')) s = spawn("envo test --save") s.expect(r"Saved envs to \.env_test") s.expect(pexpect.EOF) dot_env = Path(".env_test") assert dot_env.exists() # remove PYTHONPATH since it'll be different depending on the machine content = dot_env.read_text() content = re.sub(r'PYTHONPATH.*"', "", content, 1) content = re.sub(r'SANDBOX_ROOT.*"', "", content, 1) content = content.replace("\n\n", "\n") if content.startswith("\n"): content = content[1:] if content.endswith("\n"): content = content[:-1] assert (content == 'SANDBOX_STAGE="test"\n' 'ENVO_STAGE="test"\n' 'SANDBOX_TESTVAR="test_value"')
def test_child_parent_prompt(self, init_child_env): from envo.comm.test_utils import spawn os.chdir("child") s = spawn("envo test") s.expect(r"🛠\(sandbox.child\).*".encode("utf-8"))
def test_init(self, envo_prompt, init_child_env): from envo.comm.test_utils import spawn os.chdir("child") s = spawn("envo test") nested_prompt = envo_prompt.replace(b"sandbox", b"sandbox.child") s.expect(nested_prompt)
def test_same_child_names(self, init_2_same_childs): from envo.comm.test_utils import spawn root_dir = Path(".").absolute() os.chdir(root_dir / "sandbox/sandbox") s = spawn("envo test") s.sendline('"sandbox.sandbox.sandbox" in $PROMPT') s.expect("True")
def test_child_importable(self, envo_prompt, init_child_env): from envo.comm.test_utils import spawn Path("__init__.py").touch() os.chdir("child") Path("__init__.py").touch() s = spawn("envo test") nested_prompt = envo_prompt.replace(b"sandbox", b"sandbox.child") s.expect(nested_prompt) test_script = Path("test_script.py") content = "from env_test import Env\n" content += "env = Env()\n" content += 'print("ok")\n' test_script.write_text(content) s.sendline("python3 test_script.py") s.expect("ok")
def test_hot_reload(self, envo_prompt, init_child_env): from envo.comm.test_utils import spawn os.chdir("child") s = spawn("envo test") nested_prompt = envo_prompt.replace(b"sandbox", b"sandbox.child") s.expect(nested_prompt) child_file = Path("env_comm.py") content = child_file.read_text() content = content.replace("child", "ch") child_file.write_text(content) new_prompt1 = nested_prompt.replace(b"child", b"ch") s.expect(new_prompt1) parent_file = Path("../env_comm.py") content = parent_file.read_text() content = content.replace("sandbox", "sb") parent_file.write_text(content) new_prompt2 = new_prompt1.replace(b"sandbox", b"sb") s.expect(new_prompt2)