-
Notifications
You must be signed in to change notification settings - Fork 57
#14 Add tests. pytest_watch.command and pytest_watch.watcher #79
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
base: master
Are you sure you want to change the base?
Changes from all commits
755e402
dc82b40
8e63df5
314dc78
a3286f9
8b64901
6eab020
f07934a
6c1400b
efebe20
a87a382
785a645
66c8c95
6d9c39d
a243dd6
548e06a
1ad3d8a
117fe1d
1b6a0ea
897cf5d
b0f4b18
d5e7710
c673b9a
0f8c89b
d7828e9
6bd4c34
26159fd
8a0d80d
309a8cf
ef774dc
343ebc4
636d2d9
4f9fc32
bb82b1d
dd3cfbf
8c78d16
a02236f
839acc7
2fa4235
b1c3197
61414b3
dcfbe36
b9ac9f4
da4ee19
ac44193
24a78a9
e514278
135b7de
973b3b5
dc6a326
2557cc2
b915f81
158ca45
7e272aa
bcfd391
e8572d8
9a7ace0
13029b7
515d898
da3e334
a0fbe45
06b6da6
5c4ff37
7adcb13
0be301a
6f1638c
81f5c63
3849636
2e250cb
8d699d5
77e529b
47adfc3
bbe37af
1f597c8
e39858e
3c8ff1b
1f8888f
d5eefb9
3932987
f62cd37
1f11440
828c6eb
299067f
e6b26b8
5f2cf64
03c243b
2ef5b86
42a64da
c944899
e0beb47
61083c9
1913c66
bb39e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [run] | ||
| source=pytest_watch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| language: python | ||
| python: | ||
| - 2.7 | ||
| - pypy2.7-5.8.0 | ||
| - 3.4 | ||
| - 3.5.4 | ||
| - 3.6 | ||
| - pypy3.5-5.8.0 | ||
|
|
||
| os: | ||
| - linux | ||
|
|
||
| cache: pip | ||
|
|
||
| install: | ||
| - pip install -e ".[qa]" | ||
|
|
||
| script: | ||
| - python -m pytest --cov=pytest_watch --cov-report=term-missing -v pytest_watch | ||
|
|
||
| after_success: | ||
| - codecov --token=$CODECOV_TOKEN |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| version: 1.0.{build} | ||
|
|
||
| build_script: | ||
| - cmd: python setup.py test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]. | ||
| Use --ext=* to allow any file (including .pyc). | ||
| --config <file> Load configuration from `file` instead of trying to | ||
| locate one of the implicit configuration files. | ||
|
|
@@ -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). | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, nice removal of the redundant |
||
| -v --verbose Increase verbosity of the output. | ||
| -q --quiet Decrease verbosity of the output (precedence over -v). | ||
|
|
@@ -55,6 +55,8 @@ | |
| def main(argv=None): | ||
| """ | ||
| The entry point of the application. | ||
|
|
||
| argv -- List of strings to parse. The default is taken from sys.argv[1:]. | ||
| """ | ||
| if argv is None: | ||
| argv = sys.argv[1:] | ||
|
|
@@ -68,6 +70,8 @@ def main(argv=None): | |
| # Get paths and initial pytest arguments | ||
| directories = args['<directory>'] | ||
| pytest_args = list(directories) | ||
|
|
||
| # Merge pytest arguments and directories | ||
| if '--' in directories: | ||
| index = directories.index('--') | ||
| directories = directories[:index] | ||
|
|
@@ -76,6 +80,8 @@ def main(argv=None): | |
| # Adjust pytest and --collect-only args | ||
| for ignore in args['--ignore']: | ||
| pytest_args.extend(['--ignore', ignore]) | ||
|
|
||
| # Set pytest config file | ||
| if args['--config']: | ||
| pytest_args.extend(['-c', args['--config']]) | ||
|
|
||
|
|
@@ -87,23 +93,27 @@ def main(argv=None): | |
| if args['--pdb']: | ||
| pytest_args.append('--pdb') | ||
|
|
||
| # Parse extensions | ||
| # Parse extensions [default: .py] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice addition of comments 👍 Even more so with the defaults right there. |
||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 👍 |
||
|
|
||
| # Parse numeric arguments | ||
| spool = args['--spool'] | ||
| if spool is not None: | ||
| try: | ||
| spool = int(spool) | ||
| except ValueError: | ||
| sys.stderr.write('Error: Spool must be an integer.\n') | ||
| return 2 | ||
| try: | ||
| spool = int(spool) | ||
| except ValueError: | ||
| sys.stderr.write('Error: Spool (--spool {}) must be an integer.\n' | ||
| .format(spool)) | ||
| return 2 | ||
|
|
||
| if spool < 0: | ||
| sys.stderr.write('Error: Spool value(--spool {}) must be positive' | ||
| ' integer\n' | ||
| .format(spool)) | ||
| return 2 | ||
|
|
||
| # Run pytest and watch for changes | ||
| return watch(directories=directories, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import time | ||
|
|
||
| from colorama import Fore, Style | ||
|
|
||
|
|
||
| STYLE_BRIGHT = Fore.WHITE + Style.NORMAL + Style.BRIGHT | ||
| STYLE_HIGHLIGHT = Fore.CYAN + Style.NORMAL + Style.BRIGHT | ||
|
|
||
|
|
||
| def _reduce_events(events): | ||
| # FUTURE: Reduce ['a -> b', 'b -> c'] renames to ['a -> c'] | ||
|
|
||
| creates = [] | ||
| moves = [] | ||
| for event, src, dest in events: | ||
| if event == FileCreatedEvent: | ||
| creates.append(dest) | ||
| if event == FileMovedEvent: | ||
| moves.append(dest) | ||
|
|
||
| seen = [] | ||
| filtered = [] | ||
| for event, src, dest in events: | ||
| # Skip 'modified' event during 'created' | ||
| if src in creates and event != FileCreatedEvent: | ||
| continue | ||
|
|
||
| # Skip 'modified' event during 'moved' | ||
| if src in moves: | ||
| continue | ||
|
|
||
| # Skip duplicate events | ||
| if src in seen: | ||
| continue | ||
| seen.append(src) | ||
|
|
||
| filtered.append((event, src, dest)) | ||
| return filtered | ||
|
|
||
|
|
||
| def _bright(arg): | ||
| return STYLE_BRIGHT + arg + Style.RESET_ALL | ||
|
|
||
|
|
||
| def _highlight(arg): | ||
| return STYLE_HIGHLIGHT + arg + Style.RESET_ALL | ||
|
|
||
|
|
||
| def show_summary(argv, events, verbose=False): | ||
| command = ' '.join(argv) | ||
| bright = _bright | ||
| highlight = _highlight | ||
|
|
||
| time_stamp = time.strftime("%c", time.localtime(time.time())) | ||
| run_command_info = '[{}] Running: {}'.format(time_stamp, | ||
| highlight(command)) | ||
| if not events: | ||
| print(run_command_info) | ||
| return | ||
|
|
||
| events = _reduce_events(events) | ||
| if verbose: | ||
| lines = ['Changes detected:'] | ||
| m = max(map(len, map(lambda e: VERBOSE_EVENT_NAMES[e[0]], events))) | ||
| for event, src, dest in events: | ||
| event = VERBOSE_EVENT_NAMES[event].ljust(m) | ||
| lines.append(' {} {}'.format( | ||
| event, | ||
| highlight(src + (' -> ' + dest if dest else '')))) | ||
| lines.append('') | ||
| lines.append(run_command_info) | ||
| else: | ||
| lines = [] | ||
| for event, src, dest in events: | ||
| lines.append('{} detected: {}'.format( | ||
| EVENT_NAMES[event], | ||
| bright(src + (' -> ' + dest if dest else '')))) | ||
| lines.append('') | ||
| lines.append(run_command_info) | ||
|
|
||
| print('\n'.join(lines)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def merge_config_callee(mocker): | ||
| m = mocker.patch("pytest_watch.command.merge_config", | ||
| side_effect=lambda *args, **kwargs: True) | ||
| return m | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def beep_mock(mocker): | ||
| return mocker.patch("pytest_watch.helpers.beep") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def watch_callee(mocker): | ||
| watch_mock = mocker.patch("pytest_watch.command.watch") | ||
| watch_mock.return_value.side_effect = lambda *args, **kwargs: 0 | ||
| return watch_mock |
Uh oh!
There was an error while loading. Please reload this page.
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 toolNevermind. Just noticed docopt uses brackets in their docs. Thanks for updating 👍--helptexts?