1def logic_mixin_factory(mass, mass_attr_name, material,
2 material_attr_name, float_method_name):
3 class Mixin():
4 def is_a_witch(self):
5 try:
6 self_mass = getattr(self, mass_attr_name)
7 if self_mass == mass:
8 return "Burn her!"
9 except AttributeError:
10 pass
11
12 try:
13 self_material = getattr(self, material_attr_name)
14 if self_material == material:
15 return "Burn her!"
16 except AttributeError:
17 pass
18
19 try:
20 if getattr(self, float_method_name):
21 return "Burn her!"
22 except AttributeError:
23 pass
24
25 return "No, but it's a pity, cuz she looks like a witch!"
26
27 return Mixin
F
======================================================================
FAIL: test_realcase (test.TestWitchMixinFactory)
Real test for the Witch factory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_realcase
self.assertEqual(FloatFalse().is_a_witch(), self.RESULT_FALSE)
AssertionError: 'Burn her!' != "No, but it's a pity, cuz she looks like a witch!"
- Burn her!
+ No, but it's a pity, cuz she looks like a witch!
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (failures=1)
f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, | f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, |
2 | material_attr_name, float_method_name): | 2 | material_attr_name, float_method_name): | ||
3 | class Mixin(): | 3 | class Mixin(): | ||
n | 4 | mixin_mass = mass | n | ||
5 | mixin_material = material | ||||
6 | def __init__(self): | ||||
7 | pass | ||||
8 | |||||
9 | def is_a_witch(self): | 4 | def is_a_witch(self): | ||
10 | try: | 5 | try: | ||
11 | self_mass = getattr(self, mass_attr_name) | 6 | self_mass = getattr(self, mass_attr_name) | ||
n | 12 | if self_mass == self.mixin_mass: | n | 7 | if self_mass == mass: |
13 | return "Burn her!" | 8 | return "Burn her!" | ||
14 | except AttributeError: | 9 | except AttributeError: | ||
15 | pass | 10 | pass | ||
n | 16 | finally: | n | 11 | |
17 | try: | 12 | try: | ||
18 | self_material = getattr(self, material_attr_name) | 13 | self_material = getattr(self, material_attr_name) | ||
19 | if self_material == self.mixin_material: | 14 | if self_material == material: | ||
20 | return "Burn her!" | 15 | return "Burn her!" | ||
21 | except AttributeError: | 16 | except AttributeError: | ||
22 | pass | 17 | pass | ||
23 | finally: | 18 | |||
24 | try: | 19 | try: | ||
25 | if getattr(self, float_method_name): | 20 | if getattr(self, float_method_name): | ||
26 | return "Burn her!" | 21 | return "Burn her!" | ||
27 | except AttributeError: | 22 | except AttributeError: | ||
28 | pass | 23 | pass | ||
24 | |||||
29 | return "No, but it's a pity, cuz she looks like a witch!" | 25 | return "No, but it's a pity, cuz she looks like a witch!" | ||
t | t | 26 | |||
30 | return Mixin | 27 | return Mixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|