1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
2 burn_her = "Burn her!"
3 looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!"
4
5 class WitchCheckMixin:
6
7 def is_a_witch(self):
8 # I am using hasattr(...) to avoid AttributeError exceptions
9 if (hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass
10 or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material
11 or hasattr(self, float_method_name)):
12 return burn_her
13 return looks_like_a_witch
14
15 return WitchCheckMixin
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.000s
FAILED (failures=1)
f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): |
2 | burn_her = "Burn her!" | 2 | burn_her = "Burn her!" | ||
3 | looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!" | 3 | looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!" | ||
4 | 4 | ||||
5 | class WitchCheckMixin: | 5 | class WitchCheckMixin: | ||
6 | 6 | ||||
7 | def is_a_witch(self): | 7 | def is_a_witch(self): | ||
8 | # I am using hasattr(...) to avoid AttributeError exceptions | 8 | # I am using hasattr(...) to avoid AttributeError exceptions | ||
t | 9 | if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass \ | t | 9 | if (hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass |
10 | or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material \ | 10 | or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material | ||
11 | or hasattr(self, float_method_name): | 11 | or hasattr(self, float_method_name)): | ||
12 | return burn_her | 12 | return burn_her | ||
13 | return looks_like_a_witch | 13 | return looks_like_a_witch | ||
14 | 14 | ||||
15 | return WitchCheckMixin | 15 | return WitchCheckMixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|