Codecleanup #3#54
Conversation
|
Hey @GUKWAT, nice job! I'll review your PR this afternoon. In the meantime, the formatter failed... could you try to resolve those errors? You should be able to run If not, I can give you a hand later. Regardless, thank you for your contribution Also, I think you may have committed some files that shouldn't have been! I see 10 files changed in the PR, like .idea/misc.xml. Shouldn't only |
| for arg in args: | ||
| if arg in actions: | ||
| key, value = actions[arg] | ||
| arguments[key] = value |
There was a problem hiding this comment.
Great work!
IMO, there's one point I'd like to highlight. To ensure that the modifications you've made haven't caused any regressions (and that everything is functioning correctly), I recommend adding test cases to test_helper.py. This will help guarantee the integrity of the changes.
There was a problem hiding this comment.
Hey @ryansurf Thank you!
I only made changes to the helper.py function and cli.py function where I fixed a typo. I am not sure how files like idea/misc.xml were altered.
I will also try to figure out why the formatter is failing but if not, I will let you know
There was a problem hiding this comment.
Thank you! @K-dash
Yes I agree with you on that. I'm adding some tests to the test_helper.py file. Will push the changes for your review when I am done.
There was a problem hiding this comment.
Hey @ryansurf Thank you!
I only made changes to the helper.py function and cli.py function where I fixed a typo. I am not sure how files like idea/misc.xml were altered. I will also try to figure out why the formatter is failing but if not, I will let you know
When you do git add <file>, make sure you're only adding helper.py and cli.py!
There was a problem hiding this comment.
Hey @GUKWAT, hows it going? Feel free to ping me if you need any help!
There was a problem hiding this comment.
Hey @ryansurf I am just working on the unit tests for helper.py. Still trying to figure out how to format the code using ruff having issues when it comes to the file path
There was a problem hiding this comment.
@GUKWAT great! What are the file path errors you are dealing with?
|
@sourcery-ai review |
Reviewer's Guide by SourceryThis pull request focuses on improving code readability and maintainability by refactoring conditional logic in the src/helper.py file to use dictionary mappings. Additionally, it corrects spelling mistakes in function names and comments, and adds new test cases in tests/test_helper.py to ensure the correctness of the refactored functions. File-Level Changes
Tips
|
There was a problem hiding this comment.
Hey @GUKWAT - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 3 issues found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
|
|
||
|
|
||
| def print_ocean_data(arguments_dict, ocean_data_dict): | ||
| def print_ocean_data(arguments_dict, ocean_data): |
There was a problem hiding this comment.
suggestion: Improve handling of None values in print_ocean_data
Instead of printing 'None' for missing values, consider using a more user-friendly message like 'Not available' or 'N/A'.
| def print_ocean_data(arguments_dict, ocean_data): | |
| def print_ocean_data(arguments_dict, ocean_data): | |
| for key, value in ocean_data.items(): | |
| if value is None: | |
| print(f"{key}: N/A") | |
| else: | |
| print(f"{key}: {value}") |
| def test_print_location(): | ||
| city = "Perth" | ||
| show_city = 1 | ||
| captured_output = io.StringIO() | ||
| sys.stdout = captured_output | ||
| print_location(city, show_city) | ||
| sys.stdout = sys.__stdout__ | ||
| expected_output = "Location: Perth" | ||
| assert captured_output.getvalue().strip() == expected_output.strip() |
There was a problem hiding this comment.
suggestion (testing): Test for print_location does not cover the case when show_city is 0
Please add a test case for when show_city is 0 to ensure that the function handles this scenario correctly.
| def test_set_output_values(): | ||
| args = ['hw', 'show_large_wave', 'huv'] | ||
| arguments = {} | ||
| expected = {"show_wave": 0, "show_large_wave": 1, "show_uv": 0} | ||
| assert set_output_values(args, arguments) == expected |
There was a problem hiding this comment.
suggestion (testing): Test for set_output_values does not cover all possible arguments
Consider adding more test cases to cover all possible arguments in the actions dictionary to ensure comprehensive testing.
| def test_set_output_values(): | |
| args = ['hw', 'show_large_wave', 'huv'] | |
| arguments = {} | |
| expected = {"show_wave": 0, "show_large_wave": 1, "show_uv": 0} | |
| assert set_output_values(args, arguments) == expected | |
| def test_set_output_values(): | |
| args = ['hw', 'show_large_wave', 'huv'] | |
| arguments = {} | |
| expected = {"show_wave": 0, "show_large_wave": 1, "show_uv": 0} | |
| assert set_output_values(args, arguments) == expected | |
| args = ['show_wave', 'show_uv'] | |
| expected = {"show_wave": 1, "show_large_wave": 0, "show_uv": 1} | |
| assert set_output_values(args, arguments) == expected |
| def test_print_ocean_data(): | ||
| arguments_dict = { | ||
| "show_uv": "1", | ||
| "show_height": "1", | ||
| "show_direction": "1", | ||
| "show_period": "0", | ||
| "show_air_temp": "1", | ||
| "show_wind_speed": "1", | ||
| "show_wind_direction": "0" | ||
| } |
There was a problem hiding this comment.
suggestion (testing): Test for print_ocean_data does not cover all display_mapping keys
Please add test cases to cover all keys in the display_mapping dictionary to ensure that all possible outputs are tested.
For better code readability and maintenance, I changed the if statements into dictionary mapping conditions
Summary by Sourcery
This pull request refactors several functions to use dictionary mappings for improved readability and maintainability. It also fixes a typo in a function name and adds unit tests for key functions.
seperate_argstoseparate_argsinhelper.pyandcli.py.set_output_valuesfunction to use dictionary mapping for better readability and maintainability.print_ocean_datafunction to use dictionary mapping for displaying ocean data.print_forecastfunction to use dictionary mapping for displaying forecast data.print_location,set_output_values, andprint_ocean_datafunctions intest_helper.py.