Skip to content

Commit 4a76261

Browse files
committed
Break out sequence API tests
1 parent ea0c6ab commit 4a76261

File tree

2 files changed

+58
-61
lines changed

2 files changed

+58
-61
lines changed

test/test_cstring.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from cstring import cstring
32

43

@@ -51,63 +50,3 @@ def test_ge():
5150
assert cstring('a') >= cstring('a')
5251
assert cstring('b') >= cstring('a')
5352

54-
55-
# Sequence API
56-
57-
58-
def test_len():
59-
result = cstring('hello, world')
60-
assert len(result) == 12
61-
62-
63-
def test_concat():
64-
result = cstring('hello') + cstring(', ') + cstring('world')
65-
assert 'hello, world' == str(result)
66-
67-
68-
def test_concat_TypeError():
69-
with pytest.raises(TypeError, match='^Object must have type cstring, not str.$'):
70-
cstring('hello') + 'world'
71-
72-
73-
def test_repeat_zero():
74-
result = cstring('hello') * 0
75-
assert result == cstring('')
76-
77-
78-
def test_repeat_five():
79-
result = cstring('hello') * 5
80-
assert result == cstring('hellohellohellohellohello')
81-
82-
83-
def test_item_IndexError_too_small():
84-
with pytest.raises(IndexError):
85-
result = cstring('hello')[-6]
86-
87-
88-
def test_item_ok_neg():
89-
result = cstring('hello')[-5]
90-
assert isinstance(result, cstring)
91-
assert result == cstring('h')
92-
93-
94-
def test_item_IndexError_too_big():
95-
with pytest.raises(IndexError):
96-
result = cstring('hello')[5]
97-
98-
99-
def test_item_ok_pos():
100-
result = cstring('hello')[4]
101-
assert isinstance(result, cstring)
102-
assert result == cstring('o')
103-
104-
105-
def test_contains_True():
106-
assert cstring('ell') in cstring('hello')
107-
108-
109-
def test_contains_False():
110-
assert cstring('hello') not in cstring('world')
111-
112-
113-

test/test_sequence.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import pytest
2+
from cstring import cstring
3+
4+
5+
def test_len():
6+
result = cstring('hello, world')
7+
assert len(result) == 12
8+
9+
10+
def test_concat():
11+
result = cstring('hello') + cstring(', ') + cstring('world')
12+
assert 'hello, world' == str(result)
13+
14+
15+
def test_concat_TypeError():
16+
with pytest.raises(TypeError, match='^Object must have type cstring, not str.$'):
17+
cstring('hello') + 'world'
18+
19+
20+
def test_repeat_zero():
21+
result = cstring('hello') * 0
22+
assert result == cstring('')
23+
24+
25+
def test_repeat_five():
26+
result = cstring('hello') * 5
27+
assert result == cstring('hellohellohellohellohello')
28+
29+
30+
def test_item_IndexError_too_small():
31+
with pytest.raises(IndexError):
32+
result = cstring('hello')[-6]
33+
34+
35+
def test_item_ok_neg():
36+
result = cstring('hello')[-5]
37+
assert isinstance(result, cstring)
38+
assert result == cstring('h')
39+
40+
41+
def test_item_IndexError_too_big():
42+
with pytest.raises(IndexError):
43+
result = cstring('hello')[5]
44+
45+
46+
def test_item_ok_pos():
47+
result = cstring('hello')[4]
48+
assert isinstance(result, cstring)
49+
assert result == cstring('o')
50+
51+
52+
def test_contains_True():
53+
assert cstring('ell') in cstring('hello')
54+
55+
56+
def test_contains_False():
57+
assert cstring('hello') not in cstring('world')
58+

0 commit comments

Comments
 (0)