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

Assert error message content in tests #37

Merged
merged 12 commits into from
Sep 9, 2022

Conversation

h4l
Copy link
Contributor

@h4l h4l commented Aug 28, 2022

I'm going to have a crack at making the error messages a little more user-friendly, to resolve #5. Especially the Warning: found unmatched (duplicate?) arguments [Argument(None, '.\\10. PowerShell.ps1')] that occurs in response to an end user passing incorrect or too many arguments when running a program using docopt-ng. I need that to be resolved before I can use docopt-ng in place of docopt really.

Before making changes there, I'd like to ensure the current messages are tested, so I can be sure I don't change messages unexpectedly.

This PR mostly adds exception message assertions to all the places where tests trigger an exception or SystemExit with usage.

The first 3 commits are unrelated to these messages assertions — small improvements to the dev experience using this repo. They could go into a separate PR if you prefer, but I've already opened a few, so I didn't want to swamp with too many!

@h4l
Copy link
Contributor Author

h4l commented Aug 28, 2022

h4l force-pushed the test-error-messages branch from 1f166be to 93ea3f0 35 seconds ago

Removed import re from one of the commits.

@h4l
Copy link
Contributor Author

h4l commented Aug 28, 2022

Also, just to flag that one of the commits (ecc12c2) makes a change to the GitHub Actions config.

@h4l
Copy link
Contributor Author

h4l commented Sep 1, 2022

h4l force-pushed the test-error-messages branch from 93ea3f0 to 9c0f189 1 minute ago

Fixed tests failing on Python 3.7 due to annotation with dict[...]. Also changed "use a stable sys.argv" to use list instead of a tuple for the patched argv — docopt expects it to be a list.

And also just added:

  • fix: detect multi-word options sections in usage
  • fix: handle 3+ word Options: section names

We'd lost a line of coverage after "test: assert the messages of raised errors" as no test was triggering the "options (case-insensitive) was found in usage" error. I added a test to trigger it, and in doing so realised the code checking for the error condition was not handling options sections with extra qualifying words, like "Advanced Options:". And further to that, a separate error occurred with 3+ word Options sections.

tests/test_docopt.py Outdated Show resolved Hide resolved
docopt("Usage: prog", "-x")

with raises(DocoptLanguageError):
# -o needs an argument in usage. The "unmatched" error is because `-o` is
Copy link
Contributor

@NickCrews NickCrews Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you open a separate issue for this? I don't think I totally understand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've taken out the message assertion/comment. It's a weird quirk of the way the parser is implemented, not at all intuitive. (Just to avoid any confusion, this isn't something I've changed here, it's just existing behaviour that I was asserting the message of.)

I've fixed the issue in a separate branch I'm working on to improve the usability of the error messages, it can wait for that.

@NickCrews
Copy link
Contributor

This looks great @h4l, but let's wait for #36 to merge so we can then rebase on top of that?

@codecov
Copy link

codecov bot commented Sep 7, 2022

Codecov Report

Merging #37 (c817b29) into master (850293b) will increase coverage by 0.20%.
The diff coverage is 100.00%.

❗ Current head c817b29 differs from pull request most recent head df66068. Consider uploading reports for the commit df66068 to get more accurate results

@@             Coverage Diff             @@
##           master       #37      +/-   ##
===========================================
+ Coverage   99.79%   100.00%   +0.20%     
===========================================
  Files           1         1              
  Lines         487       492       +5     
===========================================
+ Hits          486       492       +6     
+ Misses          1         0       -1     
Impacted Files Coverage Δ
docopt/__init__.py 100.00% <100.00%> (+0.20%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@h4l
Copy link
Contributor Author

h4l commented Sep 8, 2022

Yep, I can rebase this up once 36 is sorted.

@NickCrews
Copy link
Contributor

Eh I just tried to fix the merge conflicts in the Web UI and it doesn't look that good, do you think you could actually do a rebase locally and fix the conflicts in their respective commits?

The .gitignore now ignores all dotfiles at the repo root, other than those
explicitly not ignored with !.
Flake8 will spend a long time scanning the virtualenv files dir if the
readme instructions are followed, creating one at /.venv.
It's a bit distracting when running tests during development to have
coverage printed every time, and slows down the tests somewhat. Coverage
and mypy are now run by CI, but not by default with pytest.
It was un-covered in the coverage report.
I need to know that these code paths are hit by tests.
These errors are not triggered by current tests.
This can only occur because of programmer error.
These errors are caused by bad usage docs, they shouldn't ever trigger
DocoptExit as they're not the end user's fault.
A lot of docopt tests call docopt() without specifying argv, which uses
`sys.argv` by default, so a predictable value for it is necessary.
I'm planning to make the error messages more user-friendly, (especially
"Warning: found unmatched (duplicate?) arguments ..."), so I need to verify
what the messages currently are so I can ensure that any changes are expected.
@h4l
Copy link
Contributor Author

h4l commented Sep 9, 2022

@NickCrews No problem, there were quite a few merge conflicts in there! I've rebased it on master.

Two of the changes/fixes from here were indirectly fixed by #36 so they're gone now:

Should be good to go!

@NickCrews NickCrews merged commit 296ca67 into jazzband:master Sep 9, 2022
@NickCrews
Copy link
Contributor

Excellent work @h4l ! I'm going to add the isort-ing now. Didn't want to add before and cause more merge conflicts.

@h4l
Copy link
Contributor Author

h4l commented Sep 9, 2022

Very sensible, thanks @NickCrews! I guess when you do the isort pr it's probably easier to just take the change adding the isort config and re-run it to update the files rather than using the commit I made.

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.

Warning message incomprehensible for end-user
2 participants