diff --git a/pyproject.toml b/pyproject.toml index 648e843..42cff7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "volttron-testing" -version = "0.5.0rc0" +version = "0.5.0rc1" description = "The volttron-testing library contains classes and utilities for interacting with a VOLTTRON instance." authors = ["VOLTTRON Team "] license = "Apache License 2.0" diff --git a/src/volttrontesting/platformwrapper.py b/src/volttrontesting/platformwrapper.py index 578f117..18d2890 100644 --- a/src/volttrontesting/platformwrapper.py +++ b/src/volttrontesting/platformwrapper.py @@ -666,8 +666,7 @@ def _setup_testing_environment(self): except CalledProcessError as e: print(f"Error:\n{e.output}") raise - print(output) - print("Woot env installed!") + self.logit(output) def startup_platform(self, timeout:int = 30): """ @@ -704,7 +703,7 @@ def capture_stdout(queue: Queue, process): if self.is_running(): raise PlatformWrapperError("Already running platform") - cmd = [self._volttron_exe, '-vv'] # , "-l", self._log_path] + cmd = [self._volttron_exe, '-vv', "-l", self._log_path] from pprint import pprint print('process environment: ') @@ -1422,7 +1421,7 @@ def cleanup(self): self.logit("Skipping cleanup") return - shutil.rmtree(self.volttron_home, ignore_errors=True) + self.__remove_environment_directory__() def shutdown_platform(self): @@ -1500,11 +1499,6 @@ def __str__(self): data.append('volttron_home: {}'.format(self.volttron_home)) return '\n'.join(data) - def cleanup(self): - if self.is_running(): - raise ValueError("Shutdown platform before cleaning directory.") - self.__remove_environment_directory__() - def restart_agent(self, agent_uuid: AgentUUID): cmd = f"vctl restart {agent_uuid}" self._virtual_env.run(cmd, capture=True, env=self._platform_environment) diff --git a/tests/test_platformwrapper.py b/tests/test_platformwrapper.py index 2ddb621..7290363 100644 --- a/tests/test_platformwrapper.py +++ b/tests/test_platformwrapper.py @@ -32,33 +32,36 @@ def test_can_enable_sys_queue(get_pyproject_toml): - options = create_server_options() - - p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, enable_sys_queue=True) + p = None + try: + options = create_server_options() - for data in p.pop_stdout_queue(): - assert data - p.shutdown_platform() + p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, enable_sys_queue=True) - p.cleanup() + for data in p.pop_stdout_queue(): + assert data + p.shutdown_platform() + finally: + p.cleanup() def test_value_error_raised_sys_queue(get_pyproject_toml): - options = create_server_options() - - p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml) - - with pytest.raises(ValueError): - for data in p.pop_stdout_queue(): - pass + p = None + try: + options = create_server_options() - with pytest.raises(ValueError): - for data in p.clear_stdout_queue(): - pass + p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml) - p.shutdown_platform() + with pytest.raises(ValueError): + for data in p.pop_stdout_queue(): + pass - p.cleanup() + with pytest.raises(ValueError): + for data in p.clear_stdout_queue(): + pass + finally: + p.shutdown_platform() + p.cleanup() def test_install_library(get_pyproject_toml): @@ -88,35 +91,72 @@ def test_will_update_environ(): # False ]) def test_can_create_platform_wrapper(auth_enabled: bool, get_pyproject_toml: Path): - options = create_server_options() - options.auth_enabled = auth_enabled - p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml) + p = None try: - assert p.is_running() - assert p.volttron_home.startswith("/tmp/tmp") - finally: - p.shutdown_platform() + options = create_server_options() + options.auth_enabled = auth_enabled + p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml) + try: + assert p.is_running() + assert p.volttron_home.startswith("/tmp/tmp") + finally: + p.shutdown_platform() - assert not p.is_running() - p.cleanup() + assert not p.is_running() + finally: + p.__remove_environment_directory__() def test_not_cleanup_works(get_pyproject_toml: Path): - options = create_server_options() - options.auth_enabled = True - p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True) + p = None try: - assert p.is_running() - assert p.volttron_home.startswith("/tmp/tmp") - agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10") - assert agent_uuid + options = create_server_options() + options.auth_enabled = True + p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True) + try: + assert p.is_running() + assert p.volttron_home.startswith("/tmp/tmp") + agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10") + assert agent_uuid + finally: + if p: + p.shutdown_platform() + assert Path(p.volttron_home).exists() + for d in p._added_from_github: + assert d.exists() + assert not p.is_running() + p.cleanup() finally: - if p: - p.shutdown_platform() - assert Path(p.volttron_home).exists() - for d in p._added_from_github: - assert d.exists() - assert not p.is_running() - p.cleanup() + p.__remove_environment_directory__() + +def test_not_cleanup_works_with_env_debug(get_pyproject_toml: Path, monkeypatch): + p = None + try: + monkeypatch.setenv("DEBUG", "1") + assert os.environ['DEBUG'] == "1" + + options = create_server_options() + options.auth_enabled = True + p = PlatformWrapper(options=options, project_toml_file=get_pyproject_toml, skip_cleanup=True) + try: + assert p.is_running() + assert p.volttron_home.startswith("/tmp/tmp") + agent_uuid = p.install_from_github(org="eclipse-volttron", repo="volttron-listener", branch="v10") + assert agent_uuid + finally: + if p: + p.shutdown_platform() + assert Path(p.volttron_home).exists() + for d in p._added_from_github: + assert d.exists() + assert not p.is_running() + # volttron.log is outside volttron home for these. + assert (Path(p.volttron_home).parent / "volttron.log").exists() + p.cleanup() + assert (Path(p.volttron_home).parent / "volttron.log").exists() + finally: + # Use the internal really clean up everything command. + p.__remove_environment_directory__() + def test_fixture_creation(volttron_instance): vi = volttron_instance