1import importlib
2
3def methodify(module_name):
4 try:
5 module = importlib.import_module(module_name)
6 except ImportError:
7 raise ValueError(f"Модулът {module_name} не може да бъде зареден.")
8
9 def is_interesting(method_name):
10 return len(method_name) == 1 and method_name.isalnum()
11
12 interesting_methods = []
13
14 def explore(obj, path=""):
15 for name in dir(obj):
16 if "clue" in name:
17 attribute = getattr(obj, name)
18 if callable(attribute):
19 try:
20 result = attribute()
21 if isinstance(result, BaseException) or (isinstance(result, int) and result % 2 == 0):
22 interesting_methods.append(path + name[-1])
23 except TypeError as e:
24 if "Опаааааа, тука има нещо нередно." in str(e):
25 interesting_methods.append(path + name[-1])
26 else:
27 pass
28
29 elif isinstance(attribute, type):
30 explore(attribute, path + name + ".")
31
32 explore(module)
33
34 return tuple(interesting_methods)
35
36result = methodify("secret")
37print(result)
()
E
======================================================================
ERROR: test_metodify (test.TestMethodify)
Test metodify function.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 12, in test_metodify
self.assertIn(methodify(), _RESULTS.keys())
TypeError: methodify() missing 1 required positional argument: 'module_name'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)