Предизвикателства > Безгрешен блок > Решения > Решението на Виктория Гарджева

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

1 точки общо

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

 1class ProtectedSection:
 2
 3    def __init__(self, log=(), suppress=()):
 4        self.log = log
 5        self.suppress = suppress
 6        self.exception = None
 7
 8    def __enter__(self):
 9        return self
10
11    def __exit__(self, exc_type, exc_val, exc_tb):
12        if exc_type is not None:
13            if exc_type in self.log:
14                self.exception = exc_val
15                return True  # Continue execution without raising an error
16            if exc_type in self.suppress:
17                    return True  # Continue execution without raising an error
18        return False  # In case no tuple has this error, raise the error

.F
======================================================================
FAIL: test_special_cases (test.TestSolution.test_special_cases)
Test special cases to show you that you missed something.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 128, in test_special_cases
self.assertIsNone(cm.exception)
AssertionError: ZeroDivisionError('division by zero') is not None

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (failures=1)

Дискусия
История

f1class ProtectedSection:f1class ProtectedSection:
22
3    def __init__(self, log=(), suppress=()):3    def __init__(self, log=(), suppress=()):
4        self.log = log4        self.log = log
5        self.suppress = suppress5        self.suppress = suppress
6        self.exception = None6        self.exception = None
77
8    def __enter__(self):8    def __enter__(self):
9        return self9        return self
1010
11    def __exit__(self, exc_type, exc_val, exc_tb):11    def __exit__(self, exc_type, exc_val, exc_tb):
12        if exc_type is not None:12        if exc_type is not None:
13            if exc_type in self.log:13            if exc_type in self.log:
14                self.exception = exc_val14                self.exception = exc_val
n15                return True #Continue execution without raising an errorn15                return True  # Continue execution without raising an error
16            if exc_type in self.suppress:16            if exc_type in self.suppress:
t17                    return True #Continue execution without raising an errort17                    return True  # Continue execution without raising an error
18        return False #In case no tuple has this error, raise the error18        return False  # In case no tuple has this error, raise the error
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1class ProtectedSection:f1class ProtectedSection:
22
3    def __init__(self, log=(), suppress=()):3    def __init__(self, log=(), suppress=()):
4        self.log = log4        self.log = log
5        self.suppress = suppress5        self.suppress = suppress
6        self.exception = None6        self.exception = None
77
8    def __enter__(self):8    def __enter__(self):
9        return self9        return self
1010
11    def __exit__(self, exc_type, exc_val, exc_tb):11    def __exit__(self, exc_type, exc_val, exc_tb):
12        if exc_type is not None:12        if exc_type is not None:
13            if exc_type in self.log:13            if exc_type in self.log:
14                self.exception = exc_val14                self.exception = exc_val
n15                return True #Coninue execution without raising an errorn15                return True #Continue execution without raising an error
16            if exc_type in self.suppress:16            if exc_type in self.suppress:
t17                    return True #Coninue execution without raising an errort17                    return True #Continue execution without raising an error
18        return False #In case no tuple has this error, raise the error18        return False #In case no tuple has this error, raise the error
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op