Skip to content

Commit 77ffb5a

Browse files
gpsheadclaude
andcommitted
Complete traceback timestamps test coverage gaps
- Include BaseException and Exception in pickle tests by removing unnecessary filtering - Add user-derived exception classes for ImportError and AttributeError - Tests now fully cover all built-in exception types and required user-derived classes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bab3575 commit 77ffb5a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

Lib/test/test_traceback_timestamps/test_pickle.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,9 @@
1010
class ExceptionPickleTests(unittest.TestCase):
1111
"""Test that exception types can be pickled and unpickled with timestamps intact."""
1212

13-
def _get_builtin_exception_types(self):
14-
"""Get concrete built-in exception types (excluding abstract bases)."""
15-
all_types = get_builtin_exception_types()
16-
return [
17-
exc
18-
for exc in all_types
19-
if exc not in ["BaseException", "Exception"]
20-
]
21-
2213
def test_builtin_exception_pickle_without_timestamps(self):
2314
"""Test that all built-in exception types can be pickled without timestamps."""
24-
exception_types = self._get_builtin_exception_types()
15+
exception_types = get_builtin_exception_types()
2516

2617
for exc_name in exception_types:
2718
with self.subTest(exception_type=exc_name):
@@ -45,7 +36,7 @@ def test_builtin_exception_pickle_without_timestamps(self):
4536

4637
def test_builtin_exception_pickle_with_timestamps(self):
4738
"""Test that all built-in exception types can be pickled with timestamps."""
48-
exception_types = self._get_builtin_exception_types()
39+
exception_types = get_builtin_exception_types()
4940

5041
for exc_name in exception_types:
5142
with self.subTest(exception_type=exc_name):

Lib/test/test_traceback_timestamps/test_user_exceptions.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ def __init__(self, errno=None, strerror=None):
3030
super().__init__("MyOSError")
3131
self.custom_data = "os_error_data"
3232
33+
class MyImportError(ImportError):
34+
def __init__(self, message="MyImportError"):
35+
super().__init__(message)
36+
self.custom_data = "import_error_data"
37+
38+
class MyAttributeError(AttributeError):
39+
def __init__(self, message="MyAttributeError"):
40+
super().__init__(message)
41+
self.custom_data = "attribute_error_data"
42+
3343
def test_user_exception(exc_class_name):
3444
try:
3545
exc_class = globals()[exc_class_name]
@@ -64,11 +74,13 @@ class UserExceptionTests(unittest.TestCase):
6474

6575
def test_user_derived_exceptions_without_timestamps(self):
6676
"""Test user-derived exception classes without timestamps."""
67-
user_exceptions = ["MyBaseException", "MyException", "MyOSError"]
77+
user_exceptions = ["MyBaseException", "MyException", "MyOSError", "MyImportError", "MyAttributeError"]
6878
expected_bases = {
6979
"MyBaseException": "BaseException",
7080
"MyException": "Exception",
7181
"MyOSError": "OSError",
82+
"MyImportError": "ImportError",
83+
"MyAttributeError": "AttributeError",
7284
}
7385

7486
for exc_name in user_exceptions:
@@ -96,11 +108,13 @@ def test_user_derived_exceptions_without_timestamps(self):
96108

97109
def test_user_derived_exceptions_with_timestamps(self):
98110
"""Test user-derived exception classes with timestamps."""
99-
user_exceptions = ["MyBaseException", "MyException", "MyOSError"]
111+
user_exceptions = ["MyBaseException", "MyException", "MyOSError", "MyImportError", "MyAttributeError"]
100112
expected_bases = {
101113
"MyBaseException": "BaseException",
102114
"MyException": "Exception",
103115
"MyOSError": "OSError",
116+
"MyImportError": "ImportError",
117+
"MyAttributeError": "AttributeError",
104118
}
105119

106120
for exc_name in user_exceptions:

0 commit comments

Comments
 (0)