-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add validators for 'python_major' and 'python_minor' arguments #402
Conversation
Codecov Report
@@ Coverage Diff @@
## main #402 +/- ##
==========================================
+ Coverage 99.60% 99.62% +0.01%
==========================================
Files 8 8
Lines 764 792 +28
==========================================
+ Hits 761 789 +28
Misses 3 3
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
e5ad05f
to
37543b6
Compare
Please could you add tests in https://github.com/hugovk/pypistats/blob/main/tests/test_cli.py? |
Hi @hugovk. Would you work on the remaining tasks?! They look a bit confusing to me actually. Sorry for that. |
Sure! Let me explain the general idea: @c("test_input", ["2", "3", "4"])
def test__python_major_version_valid(test_input: str) -> None:
# Act / Assert
assert cli._python_major_version(test_input) == test_input
It runs the test function three times for each input value there: "2", "3" and "4". Each time is like a fresh run, independent of any previous inputs. It's a nice way to repeat a test with the same logic but with different input values. It's basically a do-not-repeat-yourself of doing: def test__python_major_version_valid2() -> None:
# Act / Assert
assert cli._python_major_version("2") == "2"
def test__python_major_version_valid3() -> None:
# Act / Assert
assert cli._python_major_version("3") == "3"
def test__python_major_version_valid4() -> None:
# Act / Assert
assert cli._python_major_version("4") == "4" We could of course loop it: def test__python_major_version_valid() -> None:
# Act / Assert
for test_input in ("2", "3", "4"):
assert cli._python_major_version(test_input) == test_input But if it failed for, say, "3", then it wouldn't run it for "3". |
The invalid one is similar: @pytest.mark.parametrize("test_input", ["2.7", "3.9", "3.11", "-5", "pillow"])
def test__python_major_version_invalid(test_input) -> None:
# Act / Assert
with pytest.raises(argparse.ArgumentTypeError):
cli._python_major_version(test_input) Except that Then we have a similar pair for |
Would you to look at exception handling for empty data or shall I check that? We could actually merge this PR as it is, it's nicely self-contained, and do that bit in another PR. |
I actually thought that you want me to add tests for the actual CLI arguments like the |
Yes indeed. We can have that exception handling in another PR. I unlinked this PR. By merging this PR, the issue won't get closed anymore. Would you please work on that part too?! I looked over the codebase days ago and that was a bit hard to figure out its parts. Keep in mind that I looked over it with the mindset that I talked about in #401. For the sake of simplicity, we can have some refactoring and improvements next up. 🍻 |
Sounds good 👍 |
argparse
validators implementation