1from collections import defaultdict
2import re
3
4phrases = defaultdict(list)
5
6def memnick(*funcs):
7 if not funcs:
8 def decorator(func):
9 def wrapper():
10 speaker = ' '.join(word.capitalize() for word in func.__name__.split('_'))
11 result = func()
12 phrases[speaker].append(result)
13 return result
14 return wrapper
15 return decorator
16
17 printed_phrases = []
18 for func in funcs:
19 searched_name = ' '.join(word.capitalize() for word in func.__name__.split('_'))
20 for speaker, lines in phrases.items():
21 for line in lines:
22 printed_phrases.append(f"С гласа на {speaker}: {line}")
23 return printed_phrases
EFF.F
======================================================================
ERROR: test_memnick_decorates_variable_functions (test.TestMemnick.test_memnick_decorates_variable_functions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 108, in test_memnick_decorates_variable_functions
solution.memnick()(граматиков)("Капан 1", "Капан 2", "кос", "друг кос", утрепан_от_мамника=True)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: memnick.<locals>.decorator.<locals>.wrapper() got an unexpected keyword argument 'утрепан_от_мамника'
======================================================================
FAIL: test_memnick_does_not_memorize_repetitions (test.TestMemnick.test_memnick_does_not_memorize_repetitions)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 76, in test_memnick_does_not_memorize_repetitions
self.assertEqual(
~~~~~~~~~~~~~~~~^
["С гласа на Бай Венци: Емил, айде да играем шах!"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
solution.memnick(емил),
^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: Lists differ: ['С г[40 chars]шах!'] != ['С г[40 chars]шах!', 'С гласа на Бай Венци: Емил, айде да иг[210 chars]ах!']
Second list contains 5 additional elements.
First extra element 1:
'С гласа на Бай Венци: Емил, айде да играем шах!'
- ['С гласа на Бай Венци: Емил, айде да играем шах!']
? ^
+ ['С гласа на Бай Венци: Емил, айде да играем шах!',
? ^
+ 'С гласа на Бай Венци: Емил, айде да играем шах!',
+ 'С гласа на Бай Венци: Емил, айде да играем шах!',
+ 'С гласа на Бай Венци: Емил, айде да играем шах!',
+ 'С гласа на Бай Венци: Емил, айде да играем шах!',
+ 'С гласа на Бай Венци: Емил, айде да играем шах!']
======================================================================
FAIL: test_memnick_memorizes (test.TestMemnick.test_memnick_memorizes)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 51, in test_memnick_memorizes
self.assertEqual(
~~~~~~~~~~~~~~~~^
[
^
...<5 lines>...
solution.memnick(божана, емил),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: Lists differ: ['С гласа на Лазар: Божана, може би ще те любя.', 'С г[166 chars]ах!'] != ['С гласа на Бай Венци: Емил, айде да играем шах!', 'С[741 chars]бя.']
First differing element 0:
'С гласа на Лазар: Божана, може би ще те любя.'
'С гласа на Бай Венци: Емил, айде да играем шах!'
Second list contains 10 additional elements.
First extra element 4:
'С гласа на Митака: Божана, на този етап не съм сигурен дали искам да те любя.'
Diff is 1080 characters long. Set self.maxDiff to None to see it.
======================================================================
FAIL: test_memnick_splits_properly (test.TestMemnick.test_memnick_splits_properly)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 89, in test_memnick_splits_properly
self.assertEqual(
~~~~~~~~~~~~~~~~^
["С гласа на Емил: Бай Венци, кажи ми за рисунката."],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
solution.memnick(бай_венци),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: Lists differ: ['С гласа на Емил: Бай Венци, кажи ми за рисунката.'] != ['С гласа на Бай Венци: Емил, айде да играем шах!', 'С[173 chars]еш.']
First differing element 0:
'С гласа на Емил: Бай Венци, кажи ми за рисунката.'
'С гласа на Бай Венци: Емил, айде да играем шах!'
Second list contains 3 additional elements.
First extra element 1:
'С гласа на Емил: Бай Венци, кажи ми за рисунката.'
+ ['С гласа на Бай Венци: Емил, айде да играем шах!',
- ['С гласа на Емил: Бай Венци, кажи ми за рисунката.']
? ^ ^
+ 'С гласа на Емил: Бай Венци, кажи ми за рисунката.',
? ^ ^
+ 'С гласа на Лазар: Божана, може би ще те любя.',
+ 'С гласа на На Жанчето Майка Ѝ: Лазар, едни мекички съм направила да хапнеш.']
----------------------------------------------------------------------
Ran 5 tests in 0.003s
FAILED (failures=3, errors=1)
| f | 1 | from collections import defaultdict | f | 1 | from collections import defaultdict |
| 2 | import re | 2 | import re | ||
| 3 | 3 | ||||
| 4 | phrases = defaultdict(list) | 4 | phrases = defaultdict(list) | ||
| 5 | 5 | ||||
| 6 | def memnick(*funcs): | 6 | def memnick(*funcs): | ||
| n | 7 | # Декоратор | n | ||
| 8 | if not funcs: | 7 | if not funcs: | ||
| 9 | def decorator(func): | 8 | def decorator(func): | ||
| 10 | def wrapper(): | 9 | def wrapper(): | ||
| 11 | speaker = ' '.join(word.capitalize() for word in func.__name__.split('_')) | 10 | speaker = ' '.join(word.capitalize() for word in func.__name__.split('_')) | ||
| 12 | result = func() | 11 | result = func() | ||
| 13 | phrases[speaker].append(result) | 12 | phrases[speaker].append(result) | ||
| 14 | return result | 13 | return result | ||
| 15 | return wrapper | 14 | return wrapper | ||
| 16 | return decorator | 15 | return decorator | ||
| 17 | 16 | ||||
| n | 18 | # Извличане на фрази към таргетите | n | ||
| 19 | printed_phrases = [] | 17 | printed_phrases = [] | ||
| n | 20 | n | |||
| 21 | for func in funcs: | 18 | for func in funcs: | ||
| 22 | searched_name = ' '.join(word.capitalize() for word in func.__name__.split('_')) | 19 | searched_name = ' '.join(word.capitalize() for word in func.__name__.split('_')) | ||
| 23 | for speaker, lines in phrases.items(): | 20 | for speaker, lines in phrases.items(): | ||
| 24 | for line in lines: | 21 | for line in lines: | ||
| n | 25 | if re.match(rf'\b{re.escape(searched_name)}\b', line): | n | ||
| 26 | printed_phrases.append(f"С гласа на {speaker}: {line}") | 22 | printed_phrases.append(f"С гласа на {speaker}: {line}") | ||
| 27 | |||||
| 28 | return printed_phrases | 23 | return printed_phrases | ||
| 29 | 24 | ||||
| 30 | 25 | ||||
| 31 | 26 | ||||
| 32 | 27 | ||||
| 33 | 28 | ||||
| t | 34 | @memnick() | t | ||
| 35 | def божана(): | ||||
| 36 | return "Почекаин, ти си луд!" | ||||
| 37 | |||||
| 38 | божана() | ||||
| 39 | |||||
| 40 | @memnick() | ||||
| 41 | def бай_венци(): | ||||
| 42 | return "Емил, айде да играем шах!" | ||||
| 43 | |||||
| 44 | бай_венци() | ||||
| 45 | |||||
| 46 | @memnick() | ||||
| 47 | def бай_венци(): | ||||
| 48 | return "Емил, гладен съм!" | ||||
| 49 | |||||
| 50 | бай_венци() | ||||
| 51 | |||||
| 52 | @memnick() | ||||
| 53 | def емил(): | ||||
| 54 | return "Божана, намери сина ми." | ||||
| 55 | |||||
| 56 | емил() | ||||
| 57 | |||||
| 58 | @memnick() | ||||
| 59 | def емил(): | ||||
| 60 | return "Почекаин, нищо не става от тебе." | ||||
| 61 | |||||
| 62 | емил() | ||||
| 63 | |||||
| 64 | @memnick() | ||||
| 65 | def почекаин(): | ||||
| 66 | return "Божана, ще те любя." | ||||
| 67 | |||||
| 68 | почекаин() | ||||
| 69 | |||||
| 70 | |||||
| 71 | print(memnick(емил, божана)) | ||||
| 72 | |||||
| 73 | # ["С гласа на Бай Венци: Емил, айде да играем шах!", | ||||
| 74 | # "С гласа на Бай Венци: Емил, гладен съм!", | ||||
| 75 | # "С гласа на Емил: Божана, намери сина ми.", | ||||
| 76 | # "С гласа на Почекаин: Божана, ще те любя."] | ||||
| 77 | |||||
| 78 | print(memnick(бай_венци)) | ||||
| 79 | # [] - никой не се е обръщал към Бай Венци в никоя от горните фрази | ||||
| 80 | |||||
| 81 | print(memnick(почекаин)) | ||||
| 82 | # ["С гласа на Божана: Почекаин, ти си луд!", | ||||
| 83 | # "С гласа на Емил: Почекаин, нищо не става от тебе."] |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
15.03.2026 14:29
15.03.2026 14:30