Conditions | 10 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like test_django_add_or_set_locked() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import pytest |
||
17 | @pytest.mark.skipif("not django") |
||
18 | def test_django_add_or_set_locked(redis_server): |
||
19 | def creator_42(): |
||
20 | return 42 |
||
21 | |||
22 | def none_creator(): |
||
23 | return None |
||
24 | |||
25 | def assert_false_creator(): |
||
26 | assert False |
||
27 | |||
28 | assert cache.locked_get_or_set("foobar-aosl", creator_42) == 42 |
||
29 | assert cache.locked_get_or_set("foobar-aosl", assert_false_creator) == 42 |
||
30 | |||
31 | try: |
||
32 | val = cache.locked_get_or_set("foobar-aosl2", none_creator) |
||
33 | except ValueError: |
||
34 | pass |
||
35 | else: |
||
36 | assert False |
||
37 | |||
52 |