1class LockPicker_6MI0600278:
2 """Represents a lock picker and points checker."""
3
4 def __init__(self, lock):
5 self.lock = lock
6
7 def unlock(self):
8 try:
9 self.lock.pick()
10 except TypeError as ex:
11 # In expected we know number of elements wanted
12
13 args = [ None ] * ex.expected # Creates a list with the right number of arguments
14
15 while True:
16 try:
17 self.lock.pick(args)
18 break # No errors
19 except TypeError as ex: # Wrong argument type
20 args[ex.position] = ex.expected() # The type is callable and gives default type value
21 except ValueError as ex: # Wrong value
22 args[ex.position] = ex.expected # Sets the right value to a position
Грешка при опит за отключване:
Traceback (most recent call last):
File "/tmp/solution.py", line 17, in unlock
self.lock.pick(args)
File "/tmp/test.py", line 50, in pick
raise LockTypeError("This is a different kind of lock.",
test.LockTypeError: This is a different kind of lock.
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 20, in unlock
args[ex.position] = ex.expected() # The type is callable and gives default type value
^^^^^^^^^^^^^
TypeError: 'int' object is not callable
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_6MI0600278: | f | 1 | class LockPicker_6MI0600278: |
2 | """Represents a lock picker and points checker.""" | 2 | """Represents a lock picker and points checker.""" | ||
3 | 3 | ||||
4 | def __init__(self, lock): | 4 | def __init__(self, lock): | ||
5 | self.lock = lock | 5 | self.lock = lock | ||
6 | 6 | ||||
7 | def unlock(self): | 7 | def unlock(self): | ||
8 | try: | 8 | try: | ||
9 | self.lock.pick() | 9 | self.lock.pick() | ||
10 | except TypeError as ex: | 10 | except TypeError as ex: | ||
11 | # In expected we know number of elements wanted | 11 | # In expected we know number of elements wanted | ||
12 | 12 | ||||
13 | args = [ None ] * ex.expected # Creates a list with the right number of arguments | 13 | args = [ None ] * ex.expected # Creates a list with the right number of arguments | ||
14 | 14 | ||||
15 | while True: | 15 | while True: | ||
16 | try: | 16 | try: | ||
17 | self.lock.pick(args) | 17 | self.lock.pick(args) | ||
18 | break # No errors | 18 | break # No errors | ||
19 | except TypeError as ex: # Wrong argument type | 19 | except TypeError as ex: # Wrong argument type | ||
t | 20 | args[ex.position] = ex.expected() # The type is callable and gives | t | 20 | args[ex.position] = ex.expected() # The type is callable and gives default type value |
21 | except ValueError as ex: | 21 | except ValueError as ex: # Wrong value | ||
22 | args[ex.position] = ex.expected | 22 | args[ex.position] = ex.expected # Sets the right value to a position |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|