Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d9cf65f0
Kaydet (Commit)
d9cf65f0
authored
Eyl 14, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use more appropriate asserts in re tests.
üst
a25875cf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
115 deletions
+115
-115
test_re.py
Lib/test/test_re.py
+115
-115
No files found.
Lib/test/test_re.py
Dosyayı görüntüle @
d9cf65f0
...
...
@@ -59,12 +59,12 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
re
.
search
(
'x*'
,
'axx'
)
.
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
)
.
span
(
0
),
(
1
,
3
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
)
.
span
(),
(
1
,
3
))
self
.
assert
Equal
(
re
.
search
(
'x'
,
'aaa'
),
None
)
self
.
assert
IsNone
(
re
.
search
(
'x'
,
'aaa'
)
)
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
)
.
span
(
0
),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
)
.
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
)
.
span
(
0
),
(
0
,
3
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
)
.
span
(),
(
0
,
3
))
self
.
assert
Equal
(
re
.
match
(
'a+'
,
'xxx'
),
None
)
self
.
assert
IsNone
(
re
.
match
(
'a+'
,
'xxx'
)
)
def
bump_num
(
self
,
matchobj
):
int_value
=
int
(
matchobj
.
group
(
0
))
...
...
@@ -384,8 +384,8 @@ class ReTests(unittest.TestCase):
(
'('
,
'a'
))
self
.
assertEqual
(
re
.
match
(
'^(
\
()?([^()]+)(?(1)
\
))$'
,
'a'
)
.
groups
(),
(
None
,
'a'
))
self
.
assert
Equal
(
re
.
match
(
'^(
\
()?([^()]+)(?(1)
\
))$'
,
'a)'
),
None
)
self
.
assert
Equal
(
re
.
match
(
'^(
\
()?([^()]+)(?(1)
\
))$'
,
'(a'
),
None
)
self
.
assert
IsNone
(
re
.
match
(
'^(
\
()?([^()]+)(?(1)
\
))$'
,
'a)'
)
)
self
.
assert
IsNone
(
re
.
match
(
'^(
\
()?([^()]+)(?(1)
\
))$'
,
'(a'
)
)
self
.
assertEqual
(
re
.
match
(
'^(?:(a)|c)((?(1)b|d))$'
,
'ab'
)
.
groups
(),
(
'a'
,
'b'
))
self
.
assertEqual
(
re
.
match
(
'^(?:(a)|c)((?(1)b|d))$'
,
'cd'
)
.
groups
(),
...
...
@@ -401,8 +401,8 @@ class ReTests(unittest.TestCase):
(
'a'
,
'b'
,
'c'
))
self
.
assertEqual
(
p
.
match
(
'ad'
)
.
groups
(),
(
'a'
,
None
,
'd'
))
self
.
assert
Equal
(
p
.
match
(
'abd'
),
None
)
self
.
assert
Equal
(
p
.
match
(
'ac'
),
None
)
self
.
assert
IsNone
(
p
.
match
(
'abd'
)
)
self
.
assert
IsNone
(
p
.
match
(
'ac'
)
)
def
test_re_groupref
(
self
):
...
...
@@ -410,8 +410,8 @@ class ReTests(unittest.TestCase):
(
'|'
,
'a'
))
self
.
assertEqual
(
re
.
match
(
r'^(\|)?([^()]+)\1?$'
,
'a'
)
.
groups
(),
(
None
,
'a'
))
self
.
assert
Equal
(
re
.
match
(
r'^(\|)?([^()]+)\1$'
,
'a|'
),
None
)
self
.
assert
Equal
(
re
.
match
(
r'^(\|)?([^()]+)\1$'
,
'|a'
),
None
)
self
.
assert
IsNone
(
re
.
match
(
r'^(\|)?([^()]+)\1$'
,
'a|'
)
)
self
.
assert
IsNone
(
re
.
match
(
r'^(\|)?([^()]+)\1$'
,
'|a'
)
)
self
.
assertEqual
(
re
.
match
(
r'^(?:(a)|c)(\1)$'
,
'aa'
)
.
groups
(),
(
'a'
,
'a'
))
self
.
assertEqual
(
re
.
match
(
r'^(?:(a)|c)(\1)?$'
,
'c'
)
.
groups
(),
...
...
@@ -429,10 +429,10 @@ class ReTests(unittest.TestCase):
"second first second first"
)
def
test_repeat_minmax
(
self
):
self
.
assert
Equal
(
re
.
match
(
"^(
\
w){1}$"
,
"abc"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^(
\
w){1}?$"
,
"abc"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^(
\
w){1,2}$"
,
"abc"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^(
\
w){1,2}?$"
,
"abc"
),
None
)
self
.
assert
IsNone
(
re
.
match
(
"^(
\
w){1}$"
,
"abc"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^(
\
w){1}?$"
,
"abc"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^(
\
w){1,2}$"
,
"abc"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^(
\
w){1,2}?$"
,
"abc"
)
)
self
.
assertEqual
(
re
.
match
(
"^(
\
w){3}$"
,
"abc"
)
.
group
(
1
),
"c"
)
self
.
assertEqual
(
re
.
match
(
"^(
\
w){1,3}$"
,
"abc"
)
.
group
(
1
),
"c"
)
...
...
@@ -443,22 +443,22 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
re
.
match
(
"^(
\
w){1,4}?$"
,
"abc"
)
.
group
(
1
),
"c"
)
self
.
assertEqual
(
re
.
match
(
"^(
\
w){3,4}?$"
,
"abc"
)
.
group
(
1
),
"c"
)
self
.
assert
Equal
(
re
.
match
(
"^x{1}$"
,
"xxx"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^x{1}?$"
,
"xxx"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^x{1,2}$"
,
"xxx"
),
None
)
self
.
assert
Equal
(
re
.
match
(
"^x{1,2}?$"
,
"xxx"
),
None
)
self
.
assert
IsNone
(
re
.
match
(
"^x{1}$"
,
"xxx"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^x{1}?$"
,
"xxx"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^x{1,2}$"
,
"xxx"
)
)
self
.
assert
IsNone
(
re
.
match
(
"^x{1,2}?$"
,
"xxx"
)
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{3}$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{1,3}$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{1,4}$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{3,4}?$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{3}?$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{1,3}?$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{1,4}?$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{3,4}?$"
,
"xxx"
),
None
)
self
.
assert
True
(
re
.
match
(
"^x{3}$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{1,3}$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{1,4}$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{3,4}?$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{3}?$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{1,3}?$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{1,4}?$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{3,4}?$"
,
"xxx"
)
)
self
.
assert
Equal
(
re
.
match
(
"^x{}$"
,
"xxx"
),
None
)
self
.
assert
NotEqual
(
re
.
match
(
"^x{}$"
,
"x{}"
),
None
)
self
.
assert
IsNone
(
re
.
match
(
"^x{}$"
,
"xxx"
)
)
self
.
assert
True
(
re
.
match
(
"^x{}$"
,
"x{}"
)
)
def
test_getattr
(
self
):
self
.
assertEqual
(
re
.
compile
(
"(?i)(a)(b)"
)
.
pattern
,
"(?i)(a)(b)"
)
...
...
@@ -472,7 +472,7 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
re
.
match
(
"(a)"
,
"a"
)
.
endpos
,
1
)
self
.
assertEqual
(
re
.
match
(
"(a)"
,
"a"
)
.
string
,
"a"
)
self
.
assertEqual
(
re
.
match
(
"(a)"
,
"a"
)
.
regs
,
((
0
,
1
),
(
0
,
1
)))
self
.
assert
NotEqual
(
re
.
match
(
"(a)"
,
"a"
)
.
re
,
Non
e
)
self
.
assert
True
(
re
.
match
(
"(a)"
,
"a"
)
.
r
e
)
def
test_special_escapes
(
self
):
self
.
assertEqual
(
re
.
search
(
r"\b(b.)\b"
,
...
...
@@ -489,7 +489,7 @@ class ReTests(unittest.TestCase):
"abc bcd bc abxd"
,
re
.
LOCALE
)
.
group
(
1
),
"bx"
)
self
.
assertEqual
(
re
.
search
(
r"^abc$"
,
"
\n
abc
\n
"
,
re
.
M
)
.
group
(
0
),
"abc"
)
self
.
assertEqual
(
re
.
search
(
r"^\Aabc\Z$"
,
"abc"
,
re
.
M
)
.
group
(
0
),
"abc"
)
self
.
assert
Equal
(
re
.
search
(
r"^\Aabc\Z$"
,
"
\n
abc
\n
"
,
re
.
M
),
None
)
self
.
assert
IsNone
(
re
.
search
(
r"^\Aabc\Z$"
,
"
\n
abc
\n
"
,
re
.
M
)
)
self
.
assertEqual
(
re
.
search
(
br
"
\b
(b.)
\b
"
,
b
"abcd abc bcd bx"
)
.
group
(
1
),
b
"bx"
)
self
.
assertEqual
(
re
.
search
(
br
"
\
B(b.)
\
B"
,
...
...
@@ -500,7 +500,7 @@ class ReTests(unittest.TestCase):
b
"abc bcd bc abxd"
,
re
.
LOCALE
)
.
group
(
1
),
b
"bx"
)
self
.
assertEqual
(
re
.
search
(
br
"^abc$"
,
b
"
\n
abc
\n
"
,
re
.
M
)
.
group
(
0
),
b
"abc"
)
self
.
assertEqual
(
re
.
search
(
br
"^
\
Aabc
\
Z$"
,
b
"abc"
,
re
.
M
)
.
group
(
0
),
b
"abc"
)
self
.
assert
Equal
(
re
.
search
(
br
"^
\
Aabc
\
Z$"
,
b
"
\n
abc
\n
"
,
re
.
M
),
None
)
self
.
assert
IsNone
(
re
.
search
(
br
"^
\
Aabc
\
Z$"
,
b
"
\n
abc
\n
"
,
re
.
M
)
)
self
.
assertEqual
(
re
.
search
(
r"\d\D\w\W\s\S"
,
"1aa! a"
)
.
group
(
0
),
"1aa! a"
)
self
.
assertEqual
(
re
.
search
(
br
"
\
d
\
D
\
w
\
W
\
s
\
S"
,
...
...
@@ -524,10 +524,10 @@ class ReTests(unittest.TestCase):
self
.
assertFalse
(
re
.
match
(
r"\B"
,
"abc"
))
# However, an empty string contains no word boundaries, and also no
# non-boundaries.
self
.
assert
Equal
(
re
.
search
(
r"\B"
,
""
),
None
)
self
.
assert
IsNone
(
re
.
search
(
r"\B"
,
""
)
)
# This one is questionable and different from the perlre behaviour,
# but describes current behavior.
self
.
assert
Equal
(
re
.
search
(
r"\b"
,
""
),
None
)
self
.
assert
IsNone
(
re
.
search
(
r"\b"
,
""
)
)
# A single word-character string has two boundaries, but no
# non-boundary gaps.
self
.
assertEqual
(
len
(
re
.
findall
(
r"\b"
,
"a"
)),
2
)
...
...
@@ -547,8 +547,8 @@ class ReTests(unittest.TestCase):
def
test_big_codesize
(
self
):
# Issue #1160
r
=
re
.
compile
(
'|'
.
join
((
'
%
d'
%
x
for
x
in
range
(
10000
))))
self
.
assert
IsNotNon
e
(
r
.
match
(
'1000'
))
self
.
assert
IsNotNon
e
(
r
.
match
(
'9999'
))
self
.
assert
Tru
e
(
r
.
match
(
'1000'
))
self
.
assert
Tru
e
(
r
.
match
(
'9999'
))
def
test_anyall
(
self
):
self
.
assertEqual
(
re
.
match
(
"a.b"
,
"a
\n
b"
,
re
.
DOTALL
)
.
group
(
0
),
...
...
@@ -674,29 +674,29 @@ class ReTests(unittest.TestCase):
def
test_flags
(
self
):
for
flag
in
[
re
.
I
,
re
.
M
,
re
.
X
,
re
.
S
,
re
.
L
]:
self
.
assert
NotEqual
(
re
.
compile
(
'^pattern$'
,
flag
),
None
)
self
.
assert
True
(
re
.
compile
(
'^pattern$'
,
flag
)
)
def
test_sre_character_literals
(
self
):
for
i
in
[
0
,
8
,
16
,
32
,
64
,
127
,
128
,
255
,
256
,
0xFFFF
,
0x10000
,
0x10FFFF
]:
if
i
<
256
:
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\%03o"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\%03o0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\%03o8"
%
i
,
chr
(
i
)
+
"8"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\x
%02
x"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\x
%02
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\x
%02
xz"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\%03o"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"\%03o0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\%03o8"
%
i
,
chr
(
i
)
+
"8"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\x
%02
x"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"\x
%02
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\x
%02
xz"
%
i
,
chr
(
i
)
+
"z"
))
if
i
<
0x10000
:
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\u
%04
x"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\u
%04
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\u
%04
xz"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\U
%08
x"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\U
%08
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\U
%08
xz"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\0"
,
"
\000
"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\08"
,
"
\000
8"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\01"
,
"
\001
"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\018"
,
"
\001
8"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"\567"
,
chr
(
0
o167
)))
self
.
assert
Tru
e
(
re
.
match
(
r"\u
%04
x"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"\u
%04
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\u
%04
xz"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\U
%08
x"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"\U
%08
x0"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\U
%08
xz"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\0"
,
"
\000
"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\08"
,
"
\000
8"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\01"
,
"
\001
"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\018"
,
"
\001
8"
))
self
.
assert
Tru
e
(
re
.
match
(
r"\567"
,
chr
(
0
o167
)))
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"\911"
,
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"\x1"
,
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"\x1z"
,
""
)
...
...
@@ -709,22 +709,22 @@ class ReTests(unittest.TestCase):
def
test_sre_character_class_literals
(
self
):
for
i
in
[
0
,
8
,
16
,
32
,
64
,
127
,
128
,
255
,
256
,
0xFFFF
,
0x10000
,
0x10FFFF
]:
if
i
<
256
:
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\%o]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\%o8]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\%03o]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\%03o0]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\%03o8]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\x
%02
x]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\x
%02
x0]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\x
%02
xz]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\%o]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\%o8]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\%03o]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\%03o0]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\%03o8]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\x
%02
x]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\x
%02
x0]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\x
%02
xz]"
%
i
,
chr
(
i
)))
if
i
<
0x10000
:
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\u
%04
x]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\u
%04
x0]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\u
%04
xz]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\U
%08
x]"
%
i
,
chr
(
i
)))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\U
%08
x0]"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\U
%08
xz]"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
r"[\U0001d49c-\U0001d4b5]"
,
"
\U0001d49e
"
))
self
.
assert
Tru
e
(
re
.
match
(
r"[\u
%04
x]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\u
%04
x0]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\u
%04
xz]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\U
%08
x]"
%
i
,
chr
(
i
)))
self
.
assert
Tru
e
(
re
.
match
(
r"[\U
%08
x0]"
%
i
,
chr
(
i
)
+
"0"
))
self
.
assert
Tru
e
(
re
.
match
(
r"[\U
%08
xz]"
%
i
,
chr
(
i
)
+
"z"
))
self
.
assert
Tru
e
(
re
.
match
(
r"[\U0001d49c-\U0001d4b5]"
,
"
\U0001d49e
"
))
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"[\911]"
,
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"[\x1z]"
,
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
r"[\u123z]"
,
""
)
...
...
@@ -733,35 +733,35 @@ class ReTests(unittest.TestCase):
def
test_sre_byte_literals
(
self
):
for
i
in
[
0
,
8
,
16
,
32
,
64
,
127
,
128
,
255
]:
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\%03o"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\%03o0"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\%03o8"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"8"
))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\x
%02
x"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\x
%02
x0"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"0"
))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"\x
%02
xz"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"z"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\
u"
,
b
'u'
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\
U"
,
b
'U'
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\0
"
,
b
"
\000
"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\0
8"
,
b
"
\000
8"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\01
"
,
b
"
\001
"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\01
8"
,
b
"
\001
8"
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"
\567
"
,
bytes
([
0
o167
])))
self
.
assert
Tru
e
(
re
.
match
((
r"\%03o"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"\%03o0"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"0"
))
self
.
assert
Tru
e
(
re
.
match
((
r"\%03o8"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"8"
))
self
.
assert
Tru
e
(
re
.
match
((
r"\x
%02
x"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"\x
%02
x0"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"0"
))
self
.
assert
Tru
e
(
re
.
match
((
r"\x
%02
xz"
%
i
)
.
encode
(),
bytes
([
i
])
+
b
"z"
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\
u"
,
b
'u'
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\
U"
,
b
'U'
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\0
"
,
b
"
\000
"
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\0
8"
,
b
"
\000
8"
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\01
"
,
b
"
\001
"
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\01
8"
,
b
"
\001
8"
))
self
.
assert
Tru
e
(
re
.
match
(
br
"
\567
"
,
bytes
([
0
o167
])))
self
.
assertRaises
(
re
.
error
,
re
.
match
,
br
"
\
911"
,
b
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
br
"
\
x1"
,
b
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
br
"
\
x1z"
,
b
""
)
def
test_sre_byte_class_literals
(
self
):
for
i
in
[
0
,
8
,
16
,
32
,
64
,
127
,
128
,
255
]:
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\%o]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\%o8]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\%03o]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\%03o0]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\%03o8]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\x
%02
x]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\x
%02
x0]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
((
r"[\x
%02
xz]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"[
\
u]"
,
b
'u'
))
self
.
assert
IsNotNon
e
(
re
.
match
(
br
"[
\
U]"
,
b
'U'
))
self
.
assert
Tru
e
(
re
.
match
((
r"[\%o]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\%o8]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\%03o]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\%03o0]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\%03o8]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\x
%02
x]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\x
%02
x0]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
((
r"[\x
%02
xz]"
%
i
)
.
encode
(),
bytes
([
i
])))
self
.
assert
Tru
e
(
re
.
match
(
br
"[
\
u]"
,
b
'u'
))
self
.
assert
Tru
e
(
re
.
match
(
br
"[
\
U]"
,
b
'U'
))
self
.
assertRaises
(
re
.
error
,
re
.
match
,
br
"[
\
911]"
,
""
)
self
.
assertRaises
(
re
.
error
,
re
.
match
,
br
"[
\
x1z]"
,
""
)
...
...
@@ -772,7 +772,7 @@ class ReTests(unittest.TestCase):
def
test_bug_527371
(
self
):
# bug described in patches 527371/672491
self
.
assert
Equal
(
re
.
match
(
r'(a)?a'
,
'a'
)
.
lastindex
,
None
)
self
.
assert
IsNone
(
re
.
match
(
r'(a)?a'
,
'a'
)
.
lastindex
)
self
.
assertEqual
(
re
.
match
(
r'(a)(b)?b'
,
'ab'
)
.
lastindex
,
1
)
self
.
assertEqual
(
re
.
match
(
r'(?P<a>a)(?P<b>b)?b'
,
'ab'
)
.
lastgroup
,
'a'
)
self
.
assertEqual
(
re
.
match
(
"(?P<a>a(b))"
,
"ab"
)
.
lastgroup
,
'a'
)
...
...
@@ -829,7 +829,7 @@ class ReTests(unittest.TestCase):
(
r"\s+"
,
None
),
])
self
.
assert
NotEqual
(
scanner
.
scanner
.
scanner
(
""
)
.
pattern
,
None
)
self
.
assert
True
(
scanner
.
scanner
.
scanner
(
""
)
.
pattern
)
self
.
assertEqual
(
scanner
.
scan
(
"sum = 3*foo + 312.50 + bar"
),
([
'sum'
,
'op='
,
3
,
'op*'
,
'foo'
,
'op+'
,
312.5
,
...
...
@@ -874,7 +874,7 @@ class ReTests(unittest.TestCase):
# bug 764548, re.compile() barfs on str/unicode subclasses
class
my_unicode
(
str
):
pass
pat
=
re
.
compile
(
my_unicode
(
"abc"
))
self
.
assert
Equal
(
pat
.
match
(
"xyz"
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
"xyz"
)
)
def
test_finditer
(
self
):
iter
=
re
.
finditer
(
r":+"
,
"a:b::c:::d"
)
...
...
@@ -902,8 +902,8 @@ class ReTests(unittest.TestCase):
[
"::"
,
"::"
])
def
test_bug_926075
(
self
):
self
.
assert
True
(
re
.
compile
(
'bug_926075'
)
is
not
re
.
compile
(
b
'bug_926075'
))
self
.
assert
IsNot
(
re
.
compile
(
'bug_926075'
),
re
.
compile
(
b
'bug_926075'
))
def
test_bug_931848
(
self
):
pattern
=
"[
\u002E\u3002\uFF0E\uFF61
]"
...
...
@@ -917,7 +917,7 @@ class ReTests(unittest.TestCase):
scanner
=
re
.
compile
(
r"\s"
)
.
scanner
(
"a b"
)
self
.
assertEqual
(
scanner
.
search
()
.
span
(),
(
1
,
2
))
self
.
assert
Equal
(
scanner
.
search
(),
None
)
self
.
assert
IsNone
(
scanner
.
search
()
)
def
test_bug_817234
(
self
):
iter
=
re
.
finditer
(
r".*"
,
"asdf"
)
...
...
@@ -951,7 +951,7 @@ class ReTests(unittest.TestCase):
import
array
for
typecode
in
'bBuhHiIlLfd'
:
a
=
array
.
array
(
typecode
)
self
.
assert
Equal
(
re
.
compile
(
b
"bla"
)
.
match
(
a
),
None
)
self
.
assert
IsNone
(
re
.
compile
(
b
"bla"
)
.
match
(
a
)
)
self
.
assertEqual
(
re
.
compile
(
b
""
)
.
match
(
a
)
.
groups
(),
())
def
test_inline_flags
(
self
):
...
...
@@ -961,27 +961,27 @@ class ReTests(unittest.TestCase):
p
=
re
.
compile
(
upper_char
,
re
.
I
|
re
.
U
)
q
=
p
.
match
(
lower_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
p
=
re
.
compile
(
lower_char
,
re
.
I
|
re
.
U
)
q
=
p
.
match
(
upper_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
p
=
re
.
compile
(
'(?i)'
+
upper_char
,
re
.
U
)
q
=
p
.
match
(
lower_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
p
=
re
.
compile
(
'(?i)'
+
lower_char
,
re
.
U
)
q
=
p
.
match
(
upper_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
p
=
re
.
compile
(
'(?iu)'
+
upper_char
)
q
=
p
.
match
(
lower_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
p
=
re
.
compile
(
'(?iu)'
+
lower_char
)
q
=
p
.
match
(
upper_char
)
self
.
assert
NotEqual
(
q
,
None
)
self
.
assert
True
(
q
)
def
test_dollar_matches_twice
(
self
):
"$ matches the end of string, and just before the terminating
\n
"
...
...
@@ -1012,23 +1012,23 @@ class ReTests(unittest.TestCase):
# String patterns
for
flags
in
(
0
,
re
.
UNICODE
):
pat
=
re
.
compile
(
'
\xc0
'
,
flags
|
re
.
IGNORECASE
)
self
.
assert
NotEqual
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
True
(
pat
.
match
(
'
\xe0
'
)
)
pat
=
re
.
compile
(
'
\
w'
,
flags
)
self
.
assert
NotEqual
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
True
(
pat
.
match
(
'
\xe0
'
)
)
pat
=
re
.
compile
(
'
\xc0
'
,
re
.
ASCII
|
re
.
IGNORECASE
)
self
.
assert
Equal
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
'
\xe0
'
)
)
pat
=
re
.
compile
(
'(?a)
\xc0
'
,
re
.
IGNORECASE
)
self
.
assert
Equal
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
'
\xe0
'
)
)
pat
=
re
.
compile
(
'
\
w'
,
re
.
ASCII
)
self
.
assert
Equal
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
'
\xe0
'
)
)
pat
=
re
.
compile
(
'(?a)
\
w'
)
self
.
assert
Equal
(
pat
.
match
(
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
'
\xe0
'
)
)
# Bytes patterns
for
flags
in
(
0
,
re
.
ASCII
):
pat
=
re
.
compile
(
b
'
\xc0
'
,
flags
|
re
.
IGNORECASE
)
self
.
assert
Equal
(
pat
.
match
(
b
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
b
'
\xe0
'
)
)
pat
=
re
.
compile
(
b
'
\
w'
,
flags
)
self
.
assert
Equal
(
pat
.
match
(
b
'
\xe0
'
),
None
)
self
.
assert
IsNone
(
pat
.
match
(
b
'
\xe0
'
)
)
# Incompatibilities
self
.
assertRaises
(
ValueError
,
re
.
compile
,
b
'
\
w'
,
re
.
UNICODE
)
self
.
assertRaises
(
ValueError
,
re
.
compile
,
b
'(?u)
\
w'
)
...
...
@@ -1068,11 +1068,11 @@ class ReTests(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
_sre
.
compile
,
{},
0
,
[])
def
test_search_dot_unicode
(
self
):
self
.
assert
IsNotNon
e
(
re
.
search
(
"123.*-"
,
'123abc-'
))
self
.
assert
IsNotNon
e
(
re
.
search
(
"123.*-"
,
'123
\xe9
-'
))
self
.
assert
IsNotNon
e
(
re
.
search
(
"123.*-"
,
'123
\u20ac
-'
))
self
.
assert
IsNotNon
e
(
re
.
search
(
"123.*-"
,
'123
\U0010ffff
-'
))
self
.
assert
IsNotNon
e
(
re
.
search
(
"123.*-"
,
'123
\xe9\u20ac\U0010ffff
-'
))
self
.
assert
Tru
e
(
re
.
search
(
"123.*-"
,
'123abc-'
))
self
.
assert
Tru
e
(
re
.
search
(
"123.*-"
,
'123
\xe9
-'
))
self
.
assert
Tru
e
(
re
.
search
(
"123.*-"
,
'123
\u20ac
-'
))
self
.
assert
Tru
e
(
re
.
search
(
"123.*-"
,
'123
\U0010ffff
-'
))
self
.
assert
Tru
e
(
re
.
search
(
"123.*-"
,
'123
\xe9\u20ac\U0010ffff
-'
))
def
test_compile
(
self
):
# Test return value when given string and pattern as parameter
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment