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

RDS: refactoring .get() calls in test cases #8483

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

snordhausen
Copy link
Contributor

Slightly simplifying the test case for RDS, continuation of #8461.

...in those places where we know the key must exist.
...where the calling code doesn't even care about the result.
...by removing the top level dictionary and thus avoiding line
breaks.
@snordhausen
Copy link
Contributor Author

Test failures seem unrelated to my code changes.

@bpandola
Copy link
Collaborator

@snordhausen I don't have any problem with this, but just curious: what was the motivation? Save a few characters and make things a bit more tidy, or is there some larger issue here?

@bpandola bpandola self-assigned this Jan 14, 2025
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.63%. Comparing base (699b55e) to head (4e9df4e).
Report is 12 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #8483    +/-   ##
========================================
  Coverage   92.62%   92.63%            
========================================
  Files        1225     1225            
  Lines      105708   105918   +210     
========================================
+ Hits        97916    98120   +204     
- Misses       7792     7798     +6     
Flag Coverage Δ
servertests 27.76% <ø> (+<0.01%) ⬆️
unittests 92.61% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@snordhausen
Copy link
Contributor Author

@bpandola The goal is to reduce code complexity.

foo = bar.get("batz")

is equivalent to

foo = bar["batz"] if "batz" in bar else None

I'm replacing that with

foo = bar["batz"]

which eliminates the complexity of one if-else-statement.

Additionally, most test cases look like

foo = bar.get("batz")
assert foo["abc"] == "xyz"

If the batz key actually does not exist, the error becomes apparent only in line 2 with an error message NoneType object is not subscriptable. One needs to read both line 1 and line 2 to understand that error. But with

foo = bar["batz"]
assert foo["abc"] == "xyz"

line 1 will raise a KeyError. To understand the error, one only needs to read a single line of code.

So in summary, the .get() increases code complexity and obscures certain errors.

@bpandola bpandola merged commit 7953966 into getmoto:master Jan 14, 2025
60 of 61 checks passed
@snordhausen snordhausen deleted the rds-test-refactoring-get-calls branch January 14, 2025 17:12
@bblommers bblommers added this to the 5.0.27 milestone Jan 15, 2025
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