Skip to content
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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Codecleanup #3 #54

wants to merge 14 commits into from

Conversation

GUKWAT
Copy link

@GUKWAT GUKWAT commented Jul 23, 2024

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.

  • Bug Fixes:
    • Fixed typo in function name seperate_args to separate_args in helper.py and cli.py.
  • Enhancements:
    • Refactored set_output_values function to use dictionary mapping for better readability and maintainability.
    • Refactored print_ocean_data function to use dictionary mapping for displaying ocean data.
    • Refactored print_forecast function to use dictionary mapping for displaying forecast data.
  • Tests:
    • Added unit tests for print_location, set_output_values, and print_ocean_data functions in test_helper.py.

@GUKWAT GUKWAT changed the title Codecleanup Codecleanup #3 Jul 23, 2024
@ryansurf
Copy link
Owner

ryansurf commented Jul 23, 2024

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 poetry run pre-commit run --all-files in your local environment to see whats going on.

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 helper.py be altered? I can help on this too, unless I'm missing something

for arg in args:
if arg in actions:
key, value = actions[arg]
arguments[key] = value
Copy link
Collaborator

@K-dash K-dash Jul 24, 2024

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.

Copy link
Author

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

Copy link
Author

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.

Copy link
Owner

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!

Copy link
Owner

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!

Copy link
Author

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

Copy link
Owner

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?

@ryansurf
Copy link
Owner

@sourcery-ai review

Copy link
Contributor

sourcery-ai bot commented Jul 29, 2024

Reviewer's Guide by Sourcery

This 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

Files Changes
src/helper.py
tests/test_helper.py
Refactored functions to use dictionary mappings for conditions and added corresponding test cases.
src/helper.py
src/cli.py
Corrected spelling mistakes in function names and comments.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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):
Copy link
Contributor

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'.

Suggested change
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}")

Comment on lines 34 to 42
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()
Copy link
Contributor

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.

Comment on lines 45 to 49
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
Copy link
Contributor

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.

Suggested change
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

Comment on lines 52 to 61
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"
}
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants