Skip to content

Commit

Permalink
Add the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Oct 29, 2024
1 parent 57ad3b2 commit 7be946b
Showing 1 changed file with 82 additions and 42 deletions.
124 changes: 82 additions & 42 deletions tests/test_platformwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7be946b

Please sign in to comment.