| Conditions | 5 |
| Total Lines | 56 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 39 | @pytest.mark.parametrize( |
||
| 40 | 'Watcher', (PollingWatcher, QtWatcher), |
||
| 41 | ) |
||
| 42 | def test_watchers(Watcher, tmpdir): |
||
| 43 | """Stress test Watcher implementations""" |
||
| 44 | |||
| 45 | # Skip when QtWatcher is None - when Qt is not installed. |
||
| 46 | if not Watcher: |
||
| 47 | return |
||
| 48 | |||
| 49 | watch_dir = tmpdir.join('src').strpath |
||
| 50 | os.makedirs(watch_dir) |
||
| 51 | shutil.copy2(example('dummy.scss'), watch_dir) |
||
| 52 | input = tmpdir.join('src/dummy.scss').strpath |
||
| 53 | output = tmpdir.join('build/dummy.css').strpath |
||
| 54 | output_exists = lambda: exists(output) |
||
|
|
|||
| 55 | |||
| 56 | c = CallCounter() |
||
| 57 | w = Watcher( |
||
| 58 | watch_dir=watch_dir, |
||
| 59 | compiler=compile_filename, |
||
| 60 | args=(input, output), |
||
| 61 | ) |
||
| 62 | w.connect(c) |
||
| 63 | |||
| 64 | # Output should not yet exist |
||
| 65 | assert not exists(output) |
||
| 66 | |||
| 67 | w.start() |
||
| 68 | |||
| 69 | touch(input) |
||
| 70 | time.sleep(0.5) |
||
| 71 | if not await_condition(output_exists): |
||
| 72 | assert False, 'Output file not created...' |
||
| 73 | |||
| 74 | # Removing the watch_dir should not kill the Watcher |
||
| 75 | # simply stop dispatching callbacks |
||
| 76 | shutil.rmtree(watch_dir) |
||
| 77 | time.sleep(0.5) |
||
| 78 | assert c.count == 1 |
||
| 79 | |||
| 80 | # Watcher should recover once the input file is there again |
||
| 81 | os.makedirs(watch_dir) |
||
| 82 | shutil.copy2(example('dummy.scss'), watch_dir) |
||
| 83 | time.sleep(0.5) |
||
| 84 | assert c.count == 2 |
||
| 85 | |||
| 86 | # Stop watcher |
||
| 87 | w.stop() |
||
| 88 | w.join() |
||
| 89 | |||
| 90 | for _ in range(5): |
||
| 91 | touch(input) |
||
| 92 | |||
| 93 | # Count should not change |
||
| 94 | assert c.count == 2 |
||
| 95 | |||
| 139 |