7
7
:license: BSD, see LICENSE.rst for details
8
8
"""
9
9
import re
10
+ import sys
10
11
11
12
from oore import r
12
13
13
14
from pytest import raises
14
15
15
16
17
+ if sys .version_info [0 ] == 2 :
18
+ text_type = unicode
19
+ else :
20
+ text_type = str
21
+
22
+
16
23
def test_add_text ():
17
24
foo = r (u'foo' )
18
25
bar = r (u'bar' )
19
26
foobar = foo + bar
27
+ assert isinstance (foobar .pattern , text_type )
20
28
assert foobar .match (u'foobar' )
21
29
22
30
23
31
def test_add_bytes ():
24
32
foo = r (b'foo' )
25
33
bar = r (b'bar' )
26
34
foobar = foo + bar
35
+ assert isinstance (foobar .pattern , bytes )
27
36
assert foobar .match (b'foobar' )
28
37
29
38
@@ -60,53 +69,61 @@ def test_or_mixed():
60
69
def test_repeat_text ():
61
70
foo = r (u'foo' )
62
71
foo_3 = foo [3 ]
72
+ assert isinstance (foo_3 .pattern , text_type )
63
73
assert foo_3 .match (u'foo' * 3 )
64
74
65
75
66
76
def test_repeat_bytes ():
67
77
foo = r (b'foo' )
68
78
foo_3 = foo [3 ]
79
+ assert isinstance (foo_3 .pattern , bytes )
69
80
assert foo_3 .match (b'foo' * 3 )
70
81
71
82
72
83
def test_repeat_from_to_text ():
73
84
foo = r (u'foo' )
74
85
foo_2_to_4 = foo [2 , 4 ]
86
+ assert isinstance (foo_2_to_4 .pattern , text_type )
75
87
for i in range (2 , 5 ):
76
88
assert foo_2_to_4 .match (u'foo' * i )
77
89
78
90
79
91
def test_repeat_from_to_bytes ():
80
92
foo = r (b'foo' )
81
93
foo_2_to_4 = foo [2 , 4 ]
94
+ assert isinstance (foo_2_to_4 .pattern , bytes )
82
95
for i in range (2 , 5 ):
83
96
assert foo_2_to_4 .match (b'foo' * i )
84
97
85
98
86
99
def test_repeat_zero_or_more_text ():
87
100
foo = r (u'foo' )
88
101
foo_zero_or_more = foo [0 , ...]
102
+ assert isinstance (foo_zero_or_more .pattern , text_type )
89
103
for i in range (10 ):
90
104
assert foo_zero_or_more .match (u'foo' * i )
91
105
92
106
93
107
def test_repeat_zero_or_more_bytes ():
94
108
foo = r (b'foo' )
95
109
foo_zero_or_more = foo [0 , ...]
110
+ assert isinstance (foo_zero_or_more .pattern , bytes )
96
111
for i in range (10 ):
97
112
assert foo_zero_or_more .match (b'foo' * i )
98
113
99
114
100
115
def test_repeat_one_or_more_text ():
101
116
foo = r (u'foo' )
102
117
foo_one_or_more = foo [1 , ...]
118
+ assert isinstance (foo_one_or_more .pattern , text_type )
103
119
for i in range (1 , 10 ):
104
120
assert foo_one_or_more .match (u'foo' * i )
105
121
106
122
107
123
def test_repeat_one_or_more_bytes ():
108
124
foo = r (b'foo' )
109
125
foo_one_or_more = foo [1 , ...]
126
+ assert isinstance (foo_one_or_more .pattern , bytes )
110
127
for i in range (1 , 10 ):
111
128
assert foo_one_or_more .match (b'foo' * i )
112
129
@@ -115,6 +132,7 @@ def test_repeat_n_or_more_text():
115
132
foo = r (u'foo' )
116
133
for n in range (2 , 5 ):
117
134
foo_n_or_more = foo [n , ...]
135
+ assert isinstance (foo_n_or_more .pattern , text_type )
118
136
for i in range (n , 10 ):
119
137
assert foo_n_or_more .match (u'foo' * i )
120
138
@@ -123,6 +141,7 @@ def test_repeat_n_or_more_bytes():
123
141
foo = r (b'foo' )
124
142
for n in range (2 , 5 ):
125
143
foo_n_or_more = foo [n , ...]
144
+ assert isinstance (foo_n_or_more .pattern , bytes )
126
145
for i in range (n , 10 ):
127
146
assert foo_n_or_more .match (b'foo' * i )
128
147
@@ -134,6 +153,7 @@ def test_check_r_argument_is_valid_regexp():
134
153
135
154
def test_numbered_groups_text ():
136
155
foo = r (u'foo' ).grouped ()
156
+ assert isinstance (foo .pattern , text_type )
137
157
bar = r (u'bar' )
138
158
foobar = foo + bar
139
159
match = foobar .match (u'foobar' )
@@ -142,6 +162,7 @@ def test_numbered_groups_text():
142
162
143
163
def test_numbered_groups_bytes ():
144
164
foo = r (b'foo' ).grouped ()
165
+ assert isinstance (foo .pattern , bytes )
145
166
bar = r (b'bar' )
146
167
foobar = foo + bar
147
168
match = foobar .match (b'foobar' )
@@ -150,6 +171,7 @@ def test_numbered_groups_bytes():
150
171
151
172
def test_named_groups_text ():
152
173
foo = r (u'foo' ).grouped ('group' )
174
+ assert isinstance (foo .pattern , text_type )
153
175
bar = r (u'bar' )
154
176
foobar = foo + bar
155
177
match = foobar .match (u'foobar' )
@@ -158,6 +180,7 @@ def test_named_groups_text():
158
180
159
181
def test_named_groups_bytes ():
160
182
foo = r (b'foo' ).grouped ('group' )
183
+ assert isinstance (foo .pattern , bytes )
161
184
bar = r (b'bar' )
162
185
foobar = foo + bar
163
186
match = foobar .match (b'foobar' )
0 commit comments