Skip to content

Commit

Permalink
new test cases in pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansurf committed May 25, 2024
1 parent 990aac0 commit 572bc25
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 63 deletions.
9 changes: 9 additions & 0 deletions src/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
ocean["ocean_data"] = ocean_data
ocean["uv_index"] = uv_index

data_dict = {
"Location : ": city,
"Height: ": ocean_data[0],
"Direction: ": ocean_data[1],
"Period: ": ocean_data[2],
"UV Index: ": uv_index,
}


def main():
"""
Expand All @@ -89,6 +97,7 @@ def main():
print("\n")
forecast = api.forecast(lat, long, ocean["decimal"], ocean["forecast_days"])
helper.print_forecast(ocean, forecast)
return data_dict


main()
60 changes: 60 additions & 0 deletions src/tests/test_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
QA tests
Make sure pytest is installed: pip install pytest
Run pytest: pytest
"""

import sys

sys.path.append("../backend")

import unittest
from unittest.mock import patch
import io
import threading
import requests
import time
import subprocess
import os
from main import main
from helper import extract_decimal
from api import get_coordinates, get_uv, ocean_information


def test_invalid_input():
with patch("sys.stdout", new=io.StringIO()) as fake_stdout:
extract_decimal(["decimal=NotADecimal"])
printed_output = fake_stdout.getvalue().strip()
assert(
printed_output == "Invalid value for decimal. Please provide an integer."
)

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():
"""
Main() returns a dictionary of: location, height, period, etc.
This functions checks if the dictionary is returned and is populated
"""
data_dict = main()
time.sleep(5)
assert(len(data_dict) >= 5)
63 changes: 0 additions & 63 deletions src/tests/tests.py

This file was deleted.

0 comments on commit 572bc25

Please sign in to comment.