def test_exceptions(self): with pytest.raises(CommandError) as e: run(""" echo "test1" echo "throws error" && missing_command echo "test2" """) assert "missing_command: command not found" in str(e.value)
def __init__(self) -> None: self.stage = "local" self.emoji = "🐣" super().__init__() self.photos = HmletEnv.Photos(address="hmlet.photos.local") self.minio = HmletEnv.Minio(address="hmlet.minio.local") self.aux = AuxEnv( ) # Auxiliary cluster's registry is used for caching and CI images self.registry = HmletEnv.Registry(address="hmlet.registry.local", username="******", password="******") try: # TODO: Add timeout to this result = run(f"""kubectl describe nodes {self.device.name}""") ip_phrase = re.search(r"InternalIP: .*", "\n".join(result)).group(0) ip = ip_phrase.split(":")[1].strip() self.device.ip = ip self.registry.ip = ip except CommandError: self.device.ip = "" self.registry.ip = ""
def __init__(self) -> None: self.stage = "local" self.emoji = "🐣" super().__init__() self.keycloak = CitygrovesEnv.Keycloak( address="citygroves.keycloak.local") self.backend = CitygrovesEnv.Backend( address="citygroves.backend.local") self.frontend = CitygrovesEnv.Frontend( address="citygroves.frontend.local") self.appgen = CitygrovesEnv.Appgen(address="citygroves.appgen.local") self.aux = AuxEnv() self.registry = CitygrovesEnv.Registry( address="citygroves.registry.local", username="******", password="******") try: # TODO: Add timeout to this result = run(f"""kubectl describe nodes {self.device.name}""") ip_phrase = re.search(r"InternalIP: .*", "\n".join(result)).group(0) ip = ip_phrase.split(":")[1].strip() self.device.ip = ip self.registry.ip = ip except CommandError: self.device.ip = ""
def test_multine_command(self): result = run(""" export VAR1=123 echo "test \\ blabla" echo "test\\ $VAR1" """) assert len(result) == 2 assert result[0] == 'test blabla' assert result[1] == 'test123'
def test_run_multiple_results(self, capsys): result = run(""" export VAR1=123 echo "test" echo "test$VAR1" """) assert len(result) == 2 assert result[0] == 'test' assert result[1] == 'test123' assert capsys.readouterr().out == ""
def test_shell(env): run("./shell.py --dry-run")
def test_ignore_errors(self): result = run("""non_existend_command""", ignore_errors=True) assert len(result) == 1 assert "non_existend_command: command not found" in result[0]
def test_run_simple_echo_print(self, capsys): result = run('echo "test"', print_output=True) assert capsys.readouterr().out == "test\r\n" assert result[0] == 'test'
def test_run_simple_echo(self, capsys): result = run('echo "test"') assert len(result) == 1 assert result[0] == 'test' assert capsys.readouterr().out == ""