1"""
2Solution to challenge 2 for Introduction to Python course at FMI
3by Nikolay Nikolaev.
4"""
5
6def logic_mixin_factory(mass, mass_attr_name, material,
7 material_attr_name, float_method_name):
8 """Return a mixin, used to check if a class object is a witch."""
9 class WitchMixin:
10
11 def is_a_witch(self):
12 """Check the mass, material and functions to identify a witch."""
13 if (getattr(self, mass_attr_name, None) == mass or
14 getattr(self, material_attr_name, None) == material or
15 hasattr(self, float_method_name)):
16 return "Burn her!"
17 return "No, but it's a pity, cuz she looks like a witch!"
18
19 return WitchMixin
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 | """ | f | 1 | """ |
2 | Solution to challenge 2 for Introduction to Python course at FMI | 2 | Solution to challenge 2 for Introduction to Python course at FMI | ||
3 | by Nikolay Nikolaev. | 3 | by Nikolay Nikolaev. | ||
4 | """ | 4 | """ | ||
5 | 5 | ||||
6 | def logic_mixin_factory(mass, mass_attr_name, material, | 6 | def logic_mixin_factory(mass, mass_attr_name, material, | ||
7 | material_attr_name, float_method_name): | 7 | material_attr_name, float_method_name): | ||
n | 8 | """Returns a mixin, used to check if a class object is a witch.""" | n | 8 | """Return a mixin, used to check if a class object is a witch.""" |
9 | class WitchMixin: | 9 | class WitchMixin: | ||
10 | 10 | ||||
11 | def is_a_witch(self): | 11 | def is_a_witch(self): | ||
t | 12 | """Checks mass, material and functions to identify a witch.""" | t | 12 | """Check the mass, material and functions to identify a witch.""" |
13 | if (getattr(self, mass_attr_name, None) == mass or | 13 | if (getattr(self, mass_attr_name, None) == mass or | ||
14 | getattr(self, material_attr_name, None) == material or | 14 | getattr(self, material_attr_name, None) == material or | ||
15 | hasattr(self, float_method_name)): | 15 | hasattr(self, float_method_name)): | ||
16 | return "Burn her!" | 16 | return "Burn her!" | ||
17 | return "No, but it's a pity, cuz she looks like a witch!" | 17 | return "No, but it's a pity, cuz she looks like a witch!" | ||
18 | 18 | ||||
19 | return WitchMixin | 19 | return WitchMixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|