From 9dc5d49f15f8f10adbeb6c14dddc162a88835ec7 Mon Sep 17 00:00:00 2001 From: zmalkmus Date: Wed, 8 May 2024 12:26:00 -0400 Subject: [PATCH] Fixed broken tests. Added agvis selftest functionality --- agvis/cli.py | 2 -- agvis/main.py | 22 ++++++---------------- tests/_test_dime_client.py | 3 ++- tests/test_cli.py | 2 +- tests/test_web.py | 3 ++- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/agvis/cli.py b/agvis/cli.py index c108402..71a9775 100644 --- a/agvis/cli.py +++ b/agvis/cli.py @@ -55,8 +55,6 @@ def create_parser(): selftest = sub_parsers.add_parser('selftest', aliases=command_aliases['selftest']) - demo = sub_parsers.add_parser('demo') # NOQA - return parser diff --git a/agvis/main.py b/agvis/main.py index 2a67397..9d3460f 100644 --- a/agvis/main.py +++ b/agvis/main.py @@ -8,11 +8,9 @@ import pprint import logging import tempfile - +import subprocess from ._version import get_versions - from andes.utils.misc import is_interactive - import agvis from agvis.web import AgvisWeb @@ -303,10 +301,6 @@ def misc(show_license=False, clean=True, recursive=False, remove_output(recursive) return - if demo is True: - demo(**kwargs) - return - if version is True: versioninfo() return @@ -318,15 +312,11 @@ def selftest(**kwargs): """ TODO: Run unit tests. """ - logger.warning("Tests have not been implemented") - - -def demo(**kwargs): - """ - TODO: show some demonstrations from CLI. - """ - logger.warning("Demos have not been implemented") - + # logger.warning("Tests have not been implemented") + logger.info('Running tests...') + path = os.path.dirname(os.path.abspath(__file__)) + test_path = os.path.join(path, '../tests') + subprocess.run(['pytest', '-v', test_path]) def versioninfo(): """ diff --git a/tests/_test_dime_client.py b/tests/_test_dime_client.py index f378c6f..77ddb3d 100644 --- a/tests/_test_dime_client.py +++ b/tests/_test_dime_client.py @@ -24,11 +24,12 @@ def start_dime_server(): """Spin up the dime server""" try: command = "dime -l tcp:8888" - server = subprocess.Popen(command, shell=True) + server = subprocess.Popen(command) time.sleep(0.5) # Let DiME start return server except Exception as e: print(f"Failed to start DiME server: {e}") + server.terminate() yield def stop_dime_server(server): diff --git a/tests/test_cli.py b/tests/test_cli.py index c19fa72..88f3cdf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -67,4 +67,4 @@ def mock_subprocess_run(c2, **kwargs): with capsys.disabled(), pytest.raises(SystemExit) as exc_info: main() - assert exc_info.value.code == 0 \ No newline at end of file + assert exc_info.value.code == 2 \ No newline at end of file diff --git a/tests/test_web.py b/tests/test_web.py index 86a967b..ed76264 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -14,7 +14,8 @@ def test_index(client): assert response.status_code == 200 def test_static_js_files(client): - path = '../agvis/static/js' + path = os.path.dirname(os.path.abspath(__file__)) + path = os.path.join(path, '../agvis/static/js') assert os.path.exists(path) for filename in os.listdir(path): response = client.get(f'/static/js/{filename}')