1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
2 class Mixin:
3 def is_a_witch(self):
4 if getattr(self, 'mass_attr_name', None) == 'mass' or getattr(self, 'material_attr_name', None) == 'material'\
5 or callable(getattr(self, 'float_method_name', None)):
6 return "Burn her!"
7 else:
8 return "No, but it's a pity, cuz she looks like a witch!"
9 return Mixin
F
======================================================================
FAIL: test_realcase (test.TestWitchMixinFactory)
Real test for the Witch factory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 34, in test_realcase
self.assertEqual(MassTrue().is_a_witch(), self.RESULT_TRUE)
AssertionError: "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!
+ Burn her!
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
Анна Безлова
10.11.2023 17:10Допуснала си изключително проста грешка. Как се викат параметрите на функция? Също така if-a е добре да бъде разделен на няколко реда, а не разцепен с наклонена черта (според РЕР8 правилата).
|
t | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | t | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): |
2 | class Mixin: | 2 | class Mixin: | ||
3 | def is_a_witch(self): | 3 | def is_a_witch(self): | ||
4 | if getattr(self, 'mass_attr_name', None) == 'mass' or getattr(self, 'material_attr_name', None) == 'material'\ | 4 | if getattr(self, 'mass_attr_name', None) == 'mass' or getattr(self, 'material_attr_name', None) == 'material'\ | ||
5 | or callable(getattr(self, 'float_method_name', None)): | 5 | or callable(getattr(self, 'float_method_name', None)): | ||
6 | return "Burn her!" | 6 | return "Burn her!" | ||
7 | else: | 7 | else: | ||
8 | return "No, but it's a pity, cuz she looks like a witch!" | 8 | return "No, but it's a pity, cuz she looks like a witch!" | ||
9 | return Mixin | 9 | return Mixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|