Skip to content

Commit

Permalink
Merge pull request #138 from ryansurf/more_tests
Browse files Browse the repository at this point in the history
more tests!
  • Loading branch information
ryansurf authored Aug 21, 2024
2 parents d2fda6c + 858a3df commit 4b42956
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
34 changes: 34 additions & 0 deletions tests/test_art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
QA tests for art.py
Make sure pytest is installed: pip install pytest
Run pytest: pytest
"""

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.

# Call the function
# Color is invalid, should default to blue
art.print_wave(1, 0, "sdfsd")

# 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 "[0;34m" in output, "Blue color code not found in output"
assert output, "print_wave() did not print anything"
20 changes: 20 additions & 0 deletions tests/test_gpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
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
24 changes: 20 additions & 4 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import io
from unittest.mock import patch

from src import cli
from src.helper import extract_decimal
from src import cli, helper


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
Expand All @@ -26,7 +25,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


Expand All @@ -43,3 +42,20 @@ 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

0 comments on commit 4b42956

Please sign in to comment.