| 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 -*- |
||
| 40 | @pytest.mark.parametrize( |
||
| 41 | 'Watcher', (PollingWatcher, QtWatcher), |
||
| 42 | ) |
||
| 43 | def test_watchers(Watcher, tmpdir): |
||
| 44 | """Stress test Watcher implementations""" |
||
| 45 | |||
| 46 | # Skip when QtWatcher is None - when Qt is not installed. |
||
| 47 | if not Watcher: |
||
| 48 | return |
||
| 49 | |||
| 50 | watch_dir = tmpdir.join('src').strpath |
||
| 51 | os.makedirs(watch_dir) |
||
| 52 | shutil.copy2(example('dummy.scss'), watch_dir) |
||
| 53 | input = tmpdir.join('src/dummy.scss').strpath |
||
| 54 | output = tmpdir.join('build/dummy.css').strpath |
||
| 55 | output_exists = lambda: exists(output) |
||
|
|
|||
| 56 | |||
| 57 | c = CallCounter() |
||
| 58 | w = Watcher( |
||
| 59 | watch_dir=watch_dir, |
||
| 60 | compiler=compile_filename, |
||
| 61 | args=(input, output), |
||
| 62 | ) |
||
| 63 | w.connect(c) |
||
| 64 | |||
| 65 | # Output should not yet exist |
||
| 66 | assert not exists(output) |
||
| 67 | |||
| 68 | w.start() |
||
| 69 | |||
| 70 | touch(input) |
||
| 71 | time.sleep(0.5) |
||
| 72 | if not await_condition(output_exists): |
||
| 73 | assert False, 'Output file not created...' |
||
| 74 | |||
| 75 | # Removing the watch_dir should not kill the Watcher |
||
| 76 | # simply stop dispatching callbacks |
||
| 77 | shutil.rmtree(watch_dir) |
||
| 78 | time.sleep(0.5) |
||
| 79 | assert c.count == 1 |
||
| 80 | |||
| 81 | # Watcher should recover once the input file is there again |
||
| 82 | os.makedirs(watch_dir) |
||
| 83 | shutil.copy2(example('dummy.scss'), watch_dir) |
||
| 84 | time.sleep(0.5) |
||
| 85 | assert c.count == 2 |
||
| 86 | |||
| 87 | # Stop watcher |
||
| 88 | w.stop() |
||
| 89 | w.join() |
||
| 90 | |||
| 91 | for _ in range(5): |
||
| 92 | touch(input) |
||
| 93 | |||
| 94 | # Count should not change |
||
| 95 | assert c.count == 2 |
||
| 96 | |||
| 166 |