1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
2 # Проверка на входните данни
3 if not isinstance(mass, int):
4 raise ValueError("mass трябва да бъде цяло число (int).")
5 if not isinstance(mass_attr_name, str):
6 raise ValueError("mass_attr_name трябва да бъде низ (str).")
7 if not isinstance(material, str):
8 raise ValueError("material трябва да бъде низ (str).")
9 if not isinstance(material_attr_name, str):
10 raise ValueError("material_attr_name трябва да бъде низ (str).")
11 if not isinstance(float_method_name, str):
12 raise ValueError("float_method_name трябва да бъде низ (str).")
13
14 # Дефиниция на миксин класа
15 class WitchMixin:
16 @staticmethod
17 def is_a_witch(obj):
18 # Проверка дали обектът е вещица според зададените критерии
19 is_witch = False
20
21 if hasattr(obj, mass_attr_name) and getattr(obj, mass_attr_name) == mass:
22 is_witch = True
23
24 if hasattr(obj, material_attr_name) and getattr(obj, material_attr_name) == material:
25 is_witch = True
26
27 if float_method_name in dir(obj):
28 is_witch = True
29
30 if is_witch:
31 return "Burn her!"
32 else:
33 return "No, but it's a pity, cuz she looks like a witch!"
34
35 return WitchMixin
E
======================================================================
ERROR: test_realcase (test.TestWitchMixinFactory)
Real test for the Witch factory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 30, in test_realcase
self.assertEqual(Nothing().is_a_witch(), self.RESULT_FALSE)
TypeError: logic_mixin_factory.<locals>.WitchMixin.is_a_witch() missing 1 required positional argument: 'obj'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)