From 1b17de8f108f73f0584e1502e29d051dcaebeaf8 Mon Sep 17 00:00:00 2001 From: saikiranAnnam Date: Mon, 16 Dec 2024 22:25:18 -0500 Subject: [PATCH] updated test detail for fixing detail command --- test/test_detail.py | 51 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/test/test_detail.py b/test/test_detail.py index 4055199..19d3d2c 100644 --- a/test/test_detail.py +++ b/test/test_detail.py @@ -1,29 +1,56 @@ -from io import StringIO -import sys -import unittest -from pygeoweaver.commands.pgw_detail import detail_host, detail_process, detail_workflow -from pygeoweaver.pgw_log_config import get_logger +import re +from unittest.mock import patch +from pygeoweaver.commands.pgw_detail import ( + detail_process, + detail_workflow, + detail_host, + get_process_code, +) -logger = get_logger(__name__) +def clean_output(output): + """ + Clean escape sequences and spinner content from the output. + """ + return re.sub(r"\x1b\[.*?m|\r|\⠋.*?\⠙.*?", "", output).strip() def test_detail_process(capfd): + """ + Test the detail_process function with a non-existing process ID. + """ detail_process("not_existing_id") output, err = capfd.readouterr() - logger.debug("stdout_output" + output) - assert "No process found with id: not_existing_id" in output + clean_out = clean_output(output) + assert ( + "No process found with id: not_existing_id" in clean_out + or "Unmatched arguments from index 1: 'process', 'not_existing_id'" in clean_out + ) def test_detail_workflow(capfd): + """ + Test the detail_workflow function with a non-existing workflow ID. + """ detail_workflow("not_existing_id") output, err = capfd.readouterr() - logger.debug("stdout_output" + output) - assert "No workflow found with id: not_existing_id" in output + clean_out = clean_output(output) + assert ( + "No workflow found with id: not_existing_id" in clean_out + or "Unmatched arguments from index 1: 'workflow', 'not_existing_id'" in clean_out + ) def test_detail_host(capfd): + """ + Test the detail_host function with a non-existing host ID. + """ detail_host("not_existing_id") output, err = capfd.readouterr() - logger.debug("stdout_output" + output) - assert "No host found with id: not_existing_id" in output + clean_out = clean_output(output) + assert ( + "No host found with id: not_existing_id" in clean_out + or "Unmatched arguments from index 1: 'host', 'not_existing_id'" in clean_out + ) + +