Предизвикателства > Разбий ни ключалката > Решения > Решението на Росица Илиева

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

0 успешни теста
1 неуспешни теста
Код

 1class LockPicker_6MI0600209:
 2    """The class represents a tool for unlocking a lock."""
 3    def __init__(self, lock):
 4        self.lock = lock
 5
 6    def unlock(self):
 7        args = []
 8        while True:
 9            try:
10                self.lock.pick(*args)
11                break
12            except TypeError as ex:
13                if ex.position is None and len(args) != ex.expected:
14                    ex.expected = len(args)
15                    args = [None] * ex.expected
16                elif isinstance(ex.position, int):
17                    args[ex.position - 1] = ex.expected()
18            except ValueError as ex:
19                if isinstance(ex.position, int):
20                    args[ex.position - 1] = ex.expected

Грешка при опит за отключване:
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 8, in unlock
while True:
^^^^
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'

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)

Дискусия
История
Това решение има само една версия.