-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codecleanup #3 #54
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @GUKWAT, hows it going? Feel free to ping me if you need any help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}") |
tests/test_helper.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
tests/test_helper.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
tests/test_helper.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_args
toseparate_args
inhelper.py
andcli.py
.set_output_values
function to use dictionary mapping for better readability and maintainability.print_ocean_data
function to use dictionary mapping for displaying ocean data.print_forecast
function to use dictionary mapping for displaying forecast data.print_location
,set_output_values
, andprint_ocean_data
functions intest_helper.py
.