Skip to content

Commit d527184

Browse files
committedNov 9, 2024
move test case to pytest
1 parent 886bca2 commit d527184

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed
 

‎tests/test_controlcharacters.py

+26-41
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,41 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
import unittest
1717

18+
import pytest
19+
1820
from pydifact.control import Characters
1921

2022

21-
class TestControlCharacters(unittest.TestCase):
22-
def setUp(self):
23-
self.cc = Characters()
23+
@pytest.fixture
24+
def cc():
25+
return Characters()
26+
27+
28+
def test_wrong_attribute(cc):
29+
with pytest.raises(AttributeError):
30+
cc.with_control_character("wrongtype", "+")
2431

25-
def test_wrong_attribute(self):
26-
self.assertRaises(
27-
AttributeError, self.cc.with_control_character, "wrongtype", "+"
28-
)
2932

30-
def test_wrong_character_size(self):
31-
self.assertRaises(
32-
ValueError, self.cc.with_control_character, "decimal_point", ",."
33-
)
33+
def test_wrong_character_size(cc):
34+
with pytest.raises(ValueError):
35+
cc.with_control_character("decimal_point", ",.")
3436

35-
def test_correct_parameters(self):
36-
d = self.cc.with_control_character("component_separator", "/")
3737

38-
self.assertEqual(
39-
self.cc.with_control_character(
40-
"component_separator", "/"
41-
).component_separator,
42-
"/",
43-
)
38+
def test_correct_parameters(cc):
39+
assert (
40+
cc.with_control_character("component_separator", "/").component_separator == "/"
41+
)
4442

45-
self.assertEqual(
46-
self.cc.with_control_character("data_separator", "/").data_separator, "/"
47-
)
43+
assert cc.with_control_character("data_separator", "/").data_separator == "/"
4844

49-
self.assertEqual(
50-
self.cc.with_control_character("decimal_point", "/").decimal_point, "/"
51-
)
45+
assert cc.with_control_character("decimal_point", "/").decimal_point == "/"
5246

53-
self.assertEqual(
54-
self.cc.with_control_character("escape_character", "/").escape_character,
55-
"/",
56-
)
47+
assert cc.with_control_character("escape_character", "/").escape_character == "/"
5748

58-
self.assertEqual(
59-
self.cc.with_control_character(
60-
"reserved_character", "/"
61-
).reserved_character,
62-
"/",
63-
)
49+
assert (
50+
cc.with_control_character("reserved_character", "/").reserved_character == "/"
51+
)
6452

65-
self.assertEqual(
66-
self.cc.with_control_character(
67-
"segment_terminator", "/"
68-
).segment_terminator,
69-
"/",
70-
)
53+
assert (
54+
cc.with_control_character("segment_terminator", "/").segment_terminator == "/"
55+
)

0 commit comments

Comments
 (0)
Please sign in to comment.