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