diff --git a/README.md b/README.md index 2ce4564..1937fa6 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,14 @@ Wave Period: 9.8 | show_rain_sum / srs | Show the rain sum | | show_precipitation_prob / spp | Show the max precipitation chance | | hide_uv / huv | Hide uv index | +| show_past_uv | Show past uv index | +| hide_past_uv | Hide past uv index | +| show_height_history | Show past wave height index | +| hide_height_history | Hide past wave height index | +| show_direction_history | Show past wave direction index | +| hide_direction_history | Hide past wave direction index | +| show_period_history | Show past wave period index | +| hide_period_history | Hide past wave period index | | hide_height / hh | Hide surf height | | hide_direction / hdir | Hide Swell direction | | hide_period / hp | Hide swell period | @@ -73,6 +81,7 @@ Wave Period: 9.8 * `curl localhost:8000` * `curl localhost:8000?location=new_york,hide_height,hide_wave,show_large_wave` * `curl localhost:8000?fc=3,hdate,loc=trestles` +* `curl localhost:8000?show_past_uv,show_height_history,show_direction_history,show_period_history` **For detailed information you can access the [help](https://github.com/ryansurf/cli-surf/blob/main/help.txt) page** diff --git a/src/helper.py b/src/helper.py index dae382f..38b0388 100644 --- a/src/helper.py +++ b/src/helper.py @@ -66,17 +66,21 @@ def set_output_values(args, arguments_dictionary): # noqa "show_large_wave": ("show_large_wave", 1), "slw": ("show_large_wave", 1), "hide_uv": ("show_uv", 0), - "show_past_uv": ("show_past_uv", 1), "huv": ("show_uv", 0), + "show_past_uv": ("show_past_uv", 1), + "hide_past_uv": ("show_past_uv", 0), "hide_height": ("show_height", 0), - "show_height_history": ("show_height_history", 1), "hh": ("show_height", 0), + "show_height_history": ("show_height_history", 1), + "hide_height_history": ("show_height_history", 0), "hide_direction": ("show_direction", 0), - "show_direction_history": ("show_direction_history", 1), "hdir": ("show_direction", 0), + "show_direction_history": ("show_direction_history", 1), + "hide_direction_history": ("show_direction_history", 0), "hide_period": ("show_period", 0), - "show_period_history": ("show_period_history", 1), "hp": ("show_period", 0), + "show_period_history": ("show_period_history", 1), + "hide_period_history": ("show_period_history", 0), "hide_location": ("show_city", 0), "hl": ("show_city", 0), "hide_date": ("show_date", 0), @@ -188,35 +192,6 @@ def print_ocean_data(arguments_dict, ocean_data_dict): print(f"{label}{ocean_data_dict[data_key]}") -def print_historical_data(ocean_data_dict): - """ - Prints historical ocean data from one year ago, including: - - UV Index - - Wave Height - - Wave Direction - - Wave Period - - Args: - ocean_data_dict (dict): A dictionary containing ocean data, - including historical values for UV Index, - wave height, direction, and period. - """ - # Extract historical data with fallback to "No data" if not available - past_uv_index = ocean_data_dict.get("UV Index one year ago", "No data") - past_wave_height = ocean_data_dict.get("Height one year ago", - "No data") - past_wave_direction = ocean_data_dict.get("Swell Direction one year ago", - "No data") - past_wave_period = ocean_data_dict.get("Period one year ago", "No data") - - # Display the extracted historical data - print("Historical Ocean Data (1 Year Ago):") - print(f"UV Index: {past_uv_index}") - print(f"Wave Height: {past_wave_height}") - print(f"Wave Direction: {past_wave_direction}") - print(f"Wave Period: {past_wave_period}") - - def print_forecast(ocean, forecast): """ Takes in dict of forecast data and prints. @@ -337,9 +312,6 @@ def print_outputs(ocean_data_dict, arguments, gpt_prompt, gpt_info): # Prints the forecast(if activated in CLI args) print_forecast(arguments, forecast) - # Prints Historical Data - print_historical_data(ocean_data_dict) - # Checks if GPT in args, prints GPT response if True gpt_response = None if arguments["gpt"] == 1: diff --git a/tests/test_helper.py b/tests/test_helper.py index 1836fd0..e9576df 100644 --- a/tests/test_helper.py +++ b/tests/test_helper.py @@ -5,10 +5,10 @@ """ import io -import sys from unittest.mock import patch from src import cli, helper +from src.helper import set_output_values def test_invalid_input(): @@ -62,96 +62,81 @@ def test_print_gpt(): assert "gpt works" in gpt_response -def test_print_historical_data(): - """ - Tests the print_historical_data function for correct output. - - This test verifies that the function prints the expected information - from a dictionary containing historical ocean data. It captures the - printed output and checks if specific test values are present in - the output. - """ - - # Prepare test data - test_ocean_data_dict = { - "UV Index one year ago": "test", - "Height one year ago": "test", - "Swell Direction one year ago": "test", - "Period one year ago": "test" +def test_set_output_values_show_past_uv(): + args = ["show_past_uv"] + arguments_dictionary = {} + expected = {"show_past_uv": 1} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_hide_past_uv(): + args = ["hide_past_uv"] + arguments_dictionary = {} + expected = {"show_past_uv": 0} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_show_height_history(): + args = ["show_height_history"] + arguments_dictionary = {} + expected = {"show_height_history": 1} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_hide_height_history(): + args = ["hide_height_history"] + arguments_dictionary = {} + expected = {"show_height_history": 0} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_show_direction_history(): + args = ["show_direction_history"] + arguments_dictionary = {} + expected = {"show_direction_history": 1} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_hide_direction_history(): + args = ["hide_direction_history"] + arguments_dictionary = {} + expected = {"show_direction_history": 0} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_show_period_history(): + args = ["show_period_history"] + arguments_dictionary = {} + expected = {"show_period_history": 1} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_hide_period_history(): + args = ["hide_period_history"] + arguments_dictionary = {} + expected = {"show_period_history": 0} + result = set_output_values(args, arguments_dictionary) + assert result == expected + + +def test_set_output_values_combined_arguments(): + args = ["show_past_uv", + "show_height_history", + "show_direction_history", + "show_period_history"] + arguments_dictionary = {} + expected = { + "show_past_uv": 1, + "show_height_history": 1, + "show_direction_history": 1, + "show_period_history": 1, } - - # Capture the printed output - captured_output = io.StringIO() - sys.stdout = captured_output - - # Call the function - helper.print_historical_data(test_ocean_data_dict) - sys.stdout = sys.__stdout__ - - # Get the printed response - print_response = captured_output.getvalue().strip() - - # Check if "test" is in the output - assert "test" in print_response - - -def test_print_historical_data_no_data(): - """ - Tests the print_historical_data function with an empty dictionary. - - This test verifies that the function handles an empty dictionary correctly - and prints an appropriate message indicating no data is available. - """ - - # Prepare test data - empty_ocean_data_dict = {} - - # Capture the printed output - captured_output = io.StringIO() - sys.stdout = captured_output - - # Call the function - helper.print_historical_data(empty_ocean_data_dict) - sys.stdout = sys.__stdout__ - - # Get the printed response - print_response = captured_output.getvalue().strip() - - # Check if the appropriate message is in the output - assert "No data" in print_response - - -def test_print_historical_data_various_data_types(): - """ - Tests the print_historical_data function line by line. - - This test verifies that the function can handle and - print various data types - (such as integers, and floats) correctly, and ensures that - each piece of data is displayed with the appropriate message. - """ - - # Prepare test data with various data types - test_ocean_data_dict = { - "UV Index one year ago": 5.2345, - "Height one year ago": 4.1123, - "Swell Direction one year ago": 230, - "Period one year ago": 9.5 - } - - # Capture the printed output - captured_output = io.StringIO() - sys.stdout = captured_output - - # Call the function - helper.print_historical_data(test_ocean_data_dict) - sys.stdout = sys.__stdout__ - - # Get the printed response - print_response = captured_output.getvalue().strip() - - # Check if the values are correctly formatted in the output - assert "UV Index: 5.2" in print_response - assert "Wave Height: 4.1" in print_response - assert "Wave Direction: 230" in print_response - assert "Wave Period: 9.5" in print_response + result = set_output_values(args, arguments_dictionary) + assert result == expected