-
Notifications
You must be signed in to change notification settings - Fork 52
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
#14 Add tests. pytest_watch.command and pytest_watch.watcher #79
base: master
Are you sure you want to change the base?
Conversation
Now, default value is set as 200.
…fault value as 200
…fault value as 200
@@ -29,7 +29,7 @@ | |||
--pdb Start the interactive Python debugger on errors. | |||
This also enables --wait to prevent pdb interruption. | |||
--spool <delay> Re-run after a delay (in milliseconds), allowing for | |||
more file system events to queue up (default: 200 ms). | |||
more file system events to queue up [default: 200]. | |||
-p --poll Use polling instead of OS events (useful in VMs). |
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.
Ah, nice removal of the redundant ms
.
@@ -11,7 +11,7 @@ | |||
--ignore <dir> Ignore directory from being watched and during | |||
collection (multi-allowed). | |||
--ext <exts> Comma-separated list of file extensions that can | |||
trigger a new test run when changed (default: .py). | |||
trigger a new test run when changed [default: .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.
Are brackets a common for default values in CLI tool Nevermind. Just noticed docopt uses brackets in their docs. Thanks for updating 👍--help
texts?
pytest_watch/__main__.py
Outdated
sys.path.append(os.path.dirname(__file__)) | ||
|
||
from pytest_watch.command import main | ||
main() | ||
main(argv=sys.argv[1:]) |
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.
I think main()
with no args is more aesthetic. The default is to use argv[1:]
and adding that here adds noise.
Could you change it back?
If your rationale was "I couldn't tell what main's default were", a better docstring for main
could address that instead of more code.
if args['--ext'] == '*': | ||
extensions = ALL_EXTENSIONS | ||
elif args['--ext']: | ||
extensions = [('.' if not e.startswith('.') else '') + e | ||
for e in args['--ext'].split(',')] | ||
else: | ||
extensions = None |
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.
Ahh I see fixing the default value in docopt allows you to remove this. Very nice 👍
pytest_watch/command.py
Outdated
try: | ||
spool = int(spool) | ||
except ValueError: | ||
sys.stderr.write('Error: Spool (--spool %s) must be an integer.\n' % spool) |
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.
Two things.
-
I used to willfully break PEP8's "80 character limit" rule all the time. With side-by-side comparisons and 3-way merges, I've since come to appreciate this style rule. Could you do the same here?
-
I thought I read a while back that Python favored
.format
over%
these days. A quick Google search yields no results on this. But since I've since switched to using.format
everywhere, could you do the same here for consistency? A case could be made later to go back to%
everywhere.
This should do it:
sys.stderr.write(
'Error: Spool (--spool {}) must be an integer.\n'.format(spool))
Or perhaps:
print(
'Error: Spool (--spool {}) must be an integer.\n'.format(spool),
file=sys.stderr)
pytest_watch/command.py
Outdated
|
||
if spool < 0: | ||
sys.stderr.write("Error: Spool value(--spool %s) must be positive integer" % spool) | ||
return 2 |
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.
Ahh nice catch! 👍
Also, same comment as above about using 80 characters.
pytest_watch/tests/test_main.py
Outdated
from pytest_watch.__main__ import run_cli | ||
|
||
|
||
class TestRunCLI(unittest.TestCase): |
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.
Is there any chance you could switch to classless pytest? Using classes just adds overhead IMHO.
If not, I'll probably go back and do this at a (much) later date.
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.
Yes, I will adopt this classless where it is unecessary.
ignore = [] if ignore is None else ignore | ||
extensions = [] if extensions is None else extensions | ||
pytest_args = [] if pytest_args is None else pytest_args | ||
|
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.
This is much better than what I had 👍
Avoiding any accidental mutation is definitely a good thing. Good eye!
@@ -0,0 +1,437 @@ | |||
import sys |
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.
(Same comment in this file about using functions over class-based tests.)
Also assert x != y
is much more readable than self.assertFalse(condition)
, etc. Pytest does an amazing job of inspecting values when things go wrong, so I'm all for the boost in readability using raw assert
. Same goes for assert x in y
over self.assertIn(x, y)
and assert x not in y
over self.assertNotIn(x, y)
And again, if you'd rather get this in now, that's fine. I'll probably go back and switch it later on if that's the case.
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.
Perfect. I agree with readability os simple assert. I will adopt this for general assertions.
I am in doubt about self.assertListEqual and self.assertDictEqual calls. I think it is better to use unittest helpers in this case. What do you think?
Thanks
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.
Well given that pytest advocates the use of assert
over self.assert
, and this is a pytest-based project, I think using vanilla assert
is appropriate.
Here's the top bullet from pytest's Features list:
- Detailed info on failing assert statements (no need to remember
self.assert*
names)
FWIW readability and the lack of boilerplate was what attracted me to pytest to begin with.
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.
Done!
@@ -87,23 +91,24 @@ def main(argv=None): | |||
if args['--pdb']: | |||
pytest_args.append('--pdb') | |||
|
|||
# Parse extensions | |||
# Parse extensions [default: .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.
Nice addition of comments 👍 Even more so with the defaults right there.
.gitignore
Outdated
@@ -14,3 +14,7 @@ env | |||
.DS_Store | |||
Desktop.ini | |||
Thumbs.db | |||
.coverage | |||
.coverage.* | |||
venv |
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.
"Environment file" may be a better place for venv
.
I wonder if it'd make sense to add a new "Testing files" for things like .coverage
.
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.
About the suggested github .gitignore (https://github.com/github/gitignore/blob/master/Python.gitignore), it is up to date and a more complete version for python related projects.
Can we replace current version by the community version?
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.
This looks great! Thank you 😄
Only requested some small change here and there. I think we can get this in quickly after that.
Nice! Just tested on Windows and everything is passing 💯 😌 The only thing I had to do was install
|
@blueyed Anything you'd like to add? |
Hello, Joe, Thanks for your detailed review. I will check this and change code or reply properly. []'s, Andre |
…ted in joeyespo#79 (review), it was preferable to add more detailed docstring.
Messages formatting using .format() methods Tests over error messages for invalid --spool arguments Related to: joeyespo#79 (review)
Joe, it seems excellent to add this requirements-test.txt file and declare it in setup.py file. I will implement this suggestion and commit soon. []'s, |
I added a version checker inside setup.py for python 2 compatibility. I really don't know if it is the best pratice, or can we keep it this way for this moment. What do you think? []'s, |
… ignored resources
… into setup.py extras_require was added to config mock module conditional installation was moved to extras_require section, simplifying duplicated verification
…ttern. Initial usage of conftest.py and fixtures
…e|False) cases and legacy python versions
…ere are issues when they are on environment
… doesnt support symlinks
Hi,
This PR refers to #14 .
I added initial tests over command.py (coverage 98%) and to main.py.
Tests are implemented using basic unittest, and I run it on Linux using python 2 & 3.
I am implementing it from top-down, before try to add or change any funcionality.
General structure of code was keep as the same. I only fixed docopt [default: ...] definitions for --spool and --ext and now we have default values defined by documentation and being set by docopt parser. I updated README.md accordingly.
I mocked pytest_watch.watcher.watch and pytest_watch.config.merge_config to isolate and focus on CLI input and validadion.
Can you review and give me some feedback to improve the code before accept this PR?
Thank you!