From 7be946b7f5a5d6b5e4cfee5b92c2df25b188d259 Mon Sep 17 00:00:00 2001 From: "C. Allwardt" <3979063+craig8@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:03:56 -0700 Subject: [PATCH] Add the tests --- tests/test_platformwrapper.py | 124 ++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 42 deletions(-) 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