From 83768f0d744b5a38a376c570a913da70cc12733f Mon Sep 17 00:00:00 2001 From: ryansurf Date: Thu, 30 May 2024 15:14:00 -0700 Subject: [PATCH] Seperated tests into specific files --- src/helper.py | 2 +- tests/test_api.py | 25 +++++++++++++++++ tests/test_cli.py | 21 +++++++++++++++ tests/test_code.py | 64 -------------------------------------------- tests/test_gpt.py | 0 tests/test_helper.py | 27 +++++++++++++++++++ tests/test_server.py | 0 7 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 tests/test_api.py create mode 100644 tests/test_cli.py delete mode 100644 tests/test_code.py create mode 100644 tests/test_gpt.py create mode 100644 tests/test_helper.py create mode 100644 tests/test_server.py diff --git a/src/helper.py b/src/helper.py index 65fe3b6..58b82b3 100644 --- a/src/helper.py +++ b/src/helper.py @@ -176,7 +176,7 @@ def json_output(data_dict): If JSON=TRUE in .args, we print and return the JSON data """ json_out = json.dumps(data_dict, indent=4) - print(json_out) + # print(json_out) return data_dict diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..5650f3e --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,25 @@ +""" +QA tests for api.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +""" + +from src.api import get_coordinates, get_uv, ocean_information + +def test_get_coordinates(): + coordinates = get_coordinates(["loc=santa_cruz"]) + lat = coordinates[0] + long = coordinates[1] + assert isinstance(lat, (int, float)) + assert isinstance(long, (int, float)) + +def test_get_uv(): + uv = get_uv(37, 122, 2) + assert isinstance(uv, (int, float)) + +def test_ocean_information(): + ocean = ocean_information(37, 122, 2) + assert isinstance(ocean[0], (int, float)) + assert isinstance(ocean[1], (int, float)) + assert isinstance(ocean[2], (int, float)) + diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..b5ef8bf --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,21 @@ +""" +QA tests for cli.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +""" +from src import cli +import time + + +def test_cli_output(): + """ + Main() returns a dictionary of: location, height, period, etc. + This functions checks if the dictionary is returned and is populated + """ + # Hardcode lat and long for location. + # If not, when test are ran in Github Actions + # We get an error(because server probably isn't near ocean) + expected = 5 + data_dict = cli.run(36.95, -121.97) + time.sleep(5) + assert len(data_dict) >= expected diff --git a/tests/test_code.py b/tests/test_code.py deleted file mode 100644 index 7fd8686..0000000 --- a/tests/test_code.py +++ /dev/null @@ -1,64 +0,0 @@ -""" -QA tests -Make sure pytest is installed: pip install pytest -Run pytest: pytest -""" - -import io -import time -from unittest.mock import patch - -from src import cli -from src.api import get_coordinates, get_uv, ocean_information -from src.helper import extract_decimal - - -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"]) - printed_output = fake_stdout.getvalue().strip() - expected = "Invalid value for decimal. Please provide an integer." - assert printed_output == expected - - -def test_default_input(): - decimal = extract_decimal([]) - assert 1 == decimal - - -def test_get_coordinates(): - coordinates = get_coordinates(["loc=santa_cruz"]) - lat = coordinates[0] - long = coordinates[1] - assert isinstance(lat, (int, float)) - assert isinstance(long, (int, float)) - - -def test_get_uv(): - uv = get_uv(37, 122, 2) - assert isinstance(uv, (int, float)) - - -def test_ocean_information(): - ocean = ocean_information(37, 122, 2) - assert isinstance(ocean[0], (int, float)) - assert isinstance(ocean[1], (int, float)) - assert isinstance(ocean[2], (int, float)) - - -def test_main_output(): - """ - Main() returns a dictionary of: location, height, period, etc. - This functions checks if the dictionary is returned and is populated - """ - # Hardcode lat and long for location. - # If not, when test are ran in Github Actions - # We get an error(because server probably isn't near ocean) - expected = 5 - data_dict = cli.run(36.95, -121.97) - print(data_dict) - time.sleep(5) - assert len(data_dict) >= expected diff --git a/tests/test_gpt.py b/tests/test_gpt.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_helper.py b/tests/test_helper.py new file mode 100644 index 0000000..fc717b1 --- /dev/null +++ b/tests/test_helper.py @@ -0,0 +1,27 @@ +""" +QA tests for helper.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +""" + +import io +from unittest.mock import patch + +from src.helper import extract_decimal + +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"]) + printed_output = fake_stdout.getvalue().strip() + expected = "Invalid value for decimal. Please provide an integer." + assert printed_output == expected + +def test_default_input(): + """ + Test that when no decimal= in args, 1 is the default + """ + decimal = extract_decimal([]) + assert 1 == decimal \ No newline at end of file diff --git a/tests/test_server.py b/tests/test_server.py new file mode 100644 index 0000000..e69de29