From 63319c7e579db5ab81da688f4926bbba82ac5097 Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Wed, 21 Aug 2024 13:16:20 -0700 Subject: [PATCH 1/3] more tests! --- tests/test_art.py | 30 ++++++++++++++++++++++++++++++ tests/test_gpt.py | 19 +++++++++++++++++++ tests/test_helper.py | 24 +++++++++++++++++++++--- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 tests/test_art.py diff --git a/tests/test_art.py b/tests/test_art.py new file mode 100644 index 0000000..e99450a --- /dev/null +++ b/tests/test_art.py @@ -0,0 +1,30 @@ +""" +QA tests for art.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +""" + +import sys +import io +from src import art + +def test_print_wave(): + """ + Testing the print_wave() function + Uses sys & io to capture printed output + """ + # Capture the output + captured_output = io.StringIO() # Create StringIO object + sys.stdout = captured_output # Redirect stdout. + + # Call the function + art.print_wave(1, 0, "blue") + + # Reset redirect. + sys.stdout = sys.__stdout__ + + # Now captured_output.getvalue() contains the printed content + output = captured_output.getvalue() + + # Perform assertions based on expected output + assert output != "", "print_wave() did not print anything" \ No newline at end of file diff --git a/tests/test_gpt.py b/tests/test_gpt.py index e69de29..3292319 100644 --- a/tests/test_gpt.py +++ b/tests/test_gpt.py @@ -0,0 +1,19 @@ +""" +QA tests for gpt.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +""" + +from src import gpt + +def test_simple_gpt(): + """ + Testing the simple_gpt function + Calls the simple gpt and asks it to output + "gpt works". If anything else is outputted, we can + assume an error has occured + """ + surf_summary = "Please only output: 'gpt works!' " + gpt_prompt = "This is for testing purposes" + gpt_response = gpt.simple_gpt(surf_summary, gpt_prompt) + assert "gpt works" in gpt_response diff --git a/tests/test_helper.py b/tests/test_helper.py index f048576..6287cf2 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -8,7 +8,7 @@ from unittest.mock import patch from src import cli -from src.helper import extract_decimal +from src import helper def test_invalid_input(): @@ -16,7 +16,7 @@ def test_invalid_input(): Test if decimal input prints proper invalid input message """ with patch("sys.stdout", new=io.StringIO()) as fake_stdout: - extract_decimal(["decimal=NotADecimal"]) + helper.extract_decimal(["decimal=NotADecimal"]) printed_output = fake_stdout.getvalue().strip() expected = "Invalid value for decimal. Please provide an integer." assert printed_output == expected @@ -26,7 +26,7 @@ def test_default_input(): """ Test that when no decimal= in args, 1 is the default """ - decimal = extract_decimal([]) + decimal = helper.extract_decimal([]) assert 1 == decimal @@ -43,3 +43,21 @@ def test_json_output(): json_output = cli.run(36.95, -121.97, ["", "json"]) assert type(json_output["Lat"]) in {int, float} assert isinstance(json_output["Location"], str) + +def test_print_gpt(): + """ + Tests the simple_gpt() + """ + surf_data = { + "Location": "test", + "Height": "test", + "Swell Direction": "test", + "Period": "test", + "Unit": "test" + } + gpt_prompt = "Please output 'gpt works'" + gpt_info = [None, ""] + gpt_response = helper.print_gpt(surf_data, gpt_prompt, gpt_info) + assert "gpt works" in gpt_response + + From 03a1de2b6564fb17e67648912d02413539ac2828 Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Wed, 21 Aug 2024 13:21:29 -0700 Subject: [PATCH 2/3] lint fixes --- tests/test_art.py | 14 ++++++++------ tests/test_gpt.py | 1 + tests/test_helper.py | 8 +++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/test_art.py b/tests/test_art.py index e99450a..4d9c4f9 100644 --- a/tests/test_art.py +++ b/tests/test_art.py @@ -4,27 +4,29 @@ Run pytest: pytest """ -import sys import io +import sys + from src import art + def test_print_wave(): """ Testing the print_wave() function Uses sys & io to capture printed output """ # Capture the output - captured_output = io.StringIO() # Create StringIO object - sys.stdout = captured_output # Redirect stdout. + captured_output = io.StringIO() # Create StringIO object + sys.stdout = captured_output # Redirect stdout. # Call the function art.print_wave(1, 0, "blue") # Reset redirect. - sys.stdout = sys.__stdout__ + sys.stdout = sys.__stdout__ # Now captured_output.getvalue() contains the printed content output = captured_output.getvalue() - + # Perform assertions based on expected output - assert output != "", "print_wave() did not print anything" \ No newline at end of file + assert output diff --git a/tests/test_gpt.py b/tests/test_gpt.py index 3292319..c683423 100644 --- a/tests/test_gpt.py +++ b/tests/test_gpt.py @@ -6,6 +6,7 @@ from src import gpt + def test_simple_gpt(): """ Testing the simple_gpt function diff --git a/tests/test_helper.py b/tests/test_helper.py index 6287cf2..15319ea 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -7,8 +7,7 @@ import io from unittest.mock import patch -from src import cli -from src import helper +from src import cli, helper def test_invalid_input(): @@ -44,6 +43,7 @@ def test_json_output(): assert type(json_output["Lat"]) in {int, float} assert isinstance(json_output["Location"], str) + def test_print_gpt(): """ Tests the simple_gpt() @@ -53,11 +53,9 @@ def test_print_gpt(): "Height": "test", "Swell Direction": "test", "Period": "test", - "Unit": "test" + "Unit": "test", } gpt_prompt = "Please output 'gpt works'" gpt_info = [None, ""] gpt_response = helper.print_gpt(surf_data, gpt_prompt, gpt_info) assert "gpt works" in gpt_response - - From 858a3df62714ed91da29476cc47395a4260b27be Mon Sep 17 00:00:00 2001 From: Ryan Frederich Date: Wed, 21 Aug 2024 13:24:46 -0700 Subject: [PATCH 3/3] another test added --- tests/test_art.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_art.py b/tests/test_art.py index 4d9c4f9..5819053 100644 --- a/tests/test_art.py +++ b/tests/test_art.py @@ -20,7 +20,8 @@ def test_print_wave(): sys.stdout = captured_output # Redirect stdout. # Call the function - art.print_wave(1, 0, "blue") + # Color is invalid, should default to blue + art.print_wave(1, 0, "sdfsd") # Reset redirect. sys.stdout = sys.__stdout__ @@ -29,4 +30,5 @@ def test_print_wave(): output = captured_output.getvalue() # Perform assertions based on expected output - assert output + assert "[0;34m" in output, "Blue color code not found in output" + assert output, "print_wave() did not print anything"