1class LockPicker_2MI0600361:
2 """Unlock a lock."""
3 def __init__(self, lock):
4 self.lock = lock
5
6 def unlock(self):
7 args = []
8
9 while True:
10 try:
11 if self.lock.pick(*args):
12 return True
13 except Exception as ex:
14 position = ex.position
15 expected = ex.expected
16
17 if position is None:
18 args = [None] * expected
19 elif isinstance(expected, type):
20 idx = position - 1
21 args[idx] = expected
22 else:
23 idx = position - 1
24 args[idx] = expected()
Грешка при опит за отключване:
Traceback (most recent call last):
File "/tmp/solution.py", line 11, in unlock
if self.lock.pick(*args):
^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 52, in pick
for position, (attempt, slot) in enumerate(zip(attempts, self._slots),
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/timeout_decorator/timeout_decorator.py", line 69, in handler
_raise_exception(timeout_exception, exception_message)
File "/usr/local/lib/python3.12/dist-packages/timeout_decorator/timeout_decorator.py", line 45, in _raise_exception
raise exception()
timeout_decorator.timeout_decorator.TimeoutError: 'Timed Out'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 98, in <module>
test_unlocker(LockPicker(lock))
File "/usr/local/lib/python3.12/dist-packages/timeout_decorator/timeout_decorator.py", line 82, in new_function
return function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/test.py", line 77, in test_unlocker
unlocker.unlock()
File "/tmp/solution.py", line 14, in unlock
position = ex.position
^^^^^^^^^^^
AttributeError: 'TimeoutError' object has no attribute 'position'
F
======================================================================
FAIL: test_picking (test.TestLockPicker.test_picking)
Ensure the lock is picked based on already stored boolean var.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 72, in test_picking
self.assertTrue(correct, "Не успя да отключиш.")
AssertionError: False is not true : Не успя да отключиш.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
f | 1 | class LockPicker_2MI0600361: | f | 1 | class LockPicker_2MI0600361: |
2 | """Unlock a lock.""" | 2 | """Unlock a lock.""" | ||
3 | def __init__(self, lock): | 3 | def __init__(self, lock): | ||
4 | self.lock = lock | 4 | self.lock = lock | ||
5 | 5 | ||||
6 | def unlock(self): | 6 | def unlock(self): | ||
7 | args = [] | 7 | args = [] | ||
8 | 8 | ||||
9 | while True: | 9 | while True: | ||
10 | try: | 10 | try: | ||
11 | if self.lock.pick(*args): | 11 | if self.lock.pick(*args): | ||
12 | return True | 12 | return True | ||
13 | except Exception as ex: | 13 | except Exception as ex: | ||
14 | position = ex.position | 14 | position = ex.position | ||
15 | expected = ex.expected | 15 | expected = ex.expected | ||
16 | 16 | ||||
17 | if position is None: | 17 | if position is None: | ||
18 | args = [None] * expected | 18 | args = [None] * expected | ||
19 | elif isinstance(expected, type): | 19 | elif isinstance(expected, type): | ||
20 | idx = position - 1 | 20 | idx = position - 1 | ||
n | 21 | if idx < len(args): | n | ||
22 | args[idx] = expected | 21 | args[idx] = expected | ||
23 | else: | ||||
24 | args.extend([None] * (idx - len(args))) | ||||
25 | args[idx] = expected() | ||||
26 | else: | 22 | else: | ||
27 | idx = position - 1 | 23 | idx = position - 1 | ||
t | 28 | if idx < len(args): | t | ||
29 | args[idx] = expected() | 24 | args[idx] = expected() | ||
30 | else: | ||||
31 | args.extend([None] * (idx - len(args))) | ||||
32 | args[idx] = expected |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|