Skip to content

Commit 9b748fd

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Enhance TypeError with descriptive message and add tests
1 parent c2a7ce9 commit 9b748fd

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

cstvis/collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Collector:
1515

1616
def __add__(self, other: 'Collector') -> 'Collector':
1717
if not isinstance(other, type(self)):
18-
raise TypeError
18+
raise TypeError('Collector objects can only be added to other collector objects.')
1919

2020
result = Collector()
2121

tests/test_collector.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
from full_match import match
3+
14
from cstvis import Collector
25

36

@@ -73,3 +76,11 @@ def some_converter_2(node, context): # noqa: ARG001
7376
collector_3 = collector_1 + collector_2
7477

7578
assert [x.function for x in collector_3._filters] == [some_converter_1, some_converter_2]
79+
80+
81+
def test_add_wrong_things_to_collector():
82+
with pytest.raises(TypeError, match=match('Collector objects can only be added to other collector objects.')):
83+
Collector() + 1
84+
85+
with pytest.raises(TypeError, match=match('Collector objects can only be added to other collector objects.')):
86+
Collector() + 'kek'

0 commit comments

Comments
 (0)