Skip to content

Commit 0c5b03b

Browse files
committed
better test names
1 parent 49f4e0a commit 0c5b03b

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

chartlets.py/tests/channel_test.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from abc import abstractmethod
23
from typing import Type
34

45
import pytest
@@ -10,38 +11,45 @@ def make_base():
1011
class ChannelTest(unittest.TestCase):
1112
channel_cls: Type[Channel]
1213

13-
def test_no_args_given(self):
14-
with pytest.raises(
15-
TypeError, match="missing 1 required positional argument: 'id'"
16-
):
17-
# noinspection PyArgumentList
18-
obj = self.channel_cls()
14+
def test_component(self):
15+
obj = self.channel_cls("dataset_select", "options")
16+
self.assertEqual("dataset_select", obj.id)
17+
self.assertEqual("options", obj.property)
1918

20-
def test_id_given(self):
19+
def test_component_no_property(self):
2120
obj = self.channel_cls("dataset_select")
2221
self.assertEqual("dataset_select", obj.id)
2322
self.assertEqual("value", obj.property)
2423

25-
def test_app_ok(self):
24+
@abstractmethod
25+
def test_component_empty_property(self):
26+
pass
27+
28+
def test_app(self):
2629
obj = self.channel_cls("@app", "datasetId")
2730
self.assertEqual("@app", obj.id)
2831
self.assertEqual("datasetId", obj.property)
2932

30-
def test_container_with_id(self):
33+
def test_app_no_property(self):
3134
with pytest.raises(
3235
ValueError,
3336
match="value for 'property' must be given",
3437
):
35-
self.channel_cls("@container")
38+
self.channel_cls("@app")
3639

37-
def test_app_no_prop(self):
40+
def test_container(self):
41+
obj = self.channel_cls("@container", "title")
42+
self.assertEqual("@container", obj.id)
43+
self.assertEqual("title", obj.property)
44+
45+
def test_container_no_property(self):
3846
with pytest.raises(
3947
ValueError,
4048
match="value for 'property' must be given",
4149
):
42-
self.channel_cls("@app")
50+
self.channel_cls("@container")
4351

44-
def test_wrong_link(self):
52+
def test_unknown_id(self):
4553
with pytest.raises(
4654
ValueError,
4755
match=(
@@ -70,25 +78,40 @@ def test_to_dict(self):
7078
obj.to_dict(),
7179
)
7280

81+
def test_no_arguments(self):
82+
with pytest.raises(
83+
TypeError, match="missing 1 required positional argument: 'id'"
84+
):
85+
# noinspection PyArgumentList
86+
obj = self.channel_cls()
87+
88+
def test_keyword_arguments(self):
89+
obj = self.channel_cls(property="color", id="dataset_select")
90+
self.assertEqual("dataset_select", obj.id)
91+
self.assertEqual("color", obj.property)
92+
7393
return ChannelTest
7494

7595

7696
class InputTest(make_base(), unittest.TestCase):
7797
channel_cls = Input
7898

79-
def test_disallow_empty_property(self):
99+
def test_component_empty_property(self):
80100
with pytest.raises(ValueError, match="value for 'property' must be given"):
81-
self.channel_cls("some_id", "")
101+
self.channel_cls("dataset_select", "")
82102

83103

84104
class StateTest(make_base(), unittest.TestCase):
85105
channel_cls = State
86106

107+
def test_component_empty_property(self):
108+
with pytest.raises(ValueError, match="value for 'property' must be given"):
109+
self.channel_cls("dataset_select", "")
87110

88111
class OutputTest(make_base(), unittest.TestCase):
89112
channel_cls = Output
90113

91-
def test_allow_empty_property(self):
92-
obj = self.channel_cls("some_id", "")
93-
self.assertEqual("some_id", obj.id)
114+
def test_component_empty_property(self):
115+
obj = self.channel_cls("dataset_select", "")
116+
self.assertEqual("dataset_select", obj.id)
94117
self.assertEqual("", obj.property)

0 commit comments

Comments
 (0)