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
f1669a39
Kaydet (Commit)
f1669a39
authored
Nis 10, 2016
tarafından
Martin Panter
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #26712: Unify (r)split(), (l/r)strip() tests into string_tests
This eliminates a few redundant test cases.
üst
ec3c245c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
72 deletions
+36
-72
string_tests.py
Lib/test/string_tests.py
+32
-1
test_bytes.py
Lib/test/test_bytes.py
+4
-71
No files found.
Lib/test/string_tests.py
Dosyayı görüntüle @
f1669a39
...
...
@@ -349,14 +349,22 @@ class CommonTest(unittest.TestCase):
self
.
checkequal
([
'a'
],
' a '
,
'split'
)
self
.
checkequal
([
'a'
,
'b'
],
' a b '
,
'split'
)
self
.
checkequal
([
'a'
,
'b '
],
' a b '
,
'split'
,
None
,
1
)
self
.
checkequal
([
'a b c '
],
' a b c '
,
'split'
,
None
,
0
)
self
.
checkequal
([
'a'
,
'b c '
],
' a b c '
,
'split'
,
None
,
1
)
self
.
checkequal
([
'a'
,
'b'
,
'c '
],
' a b c '
,
'split'
,
None
,
2
)
self
.
checkequal
([
'a'
,
'b'
,
'c'
],
' a b c '
,
'split'
,
None
,
3
)
self
.
checkequal
([
'a'
,
'b'
],
'
\n\t
a
\t\r
b
\v
'
,
'split'
)
aaa
=
' a '
*
20
self
.
checkequal
([
'a'
]
*
20
,
aaa
,
'split'
)
self
.
checkequal
([
'a'
]
+
[
aaa
[
4
:]],
aaa
,
'split'
,
None
,
1
)
self
.
checkequal
([
'a'
]
*
19
+
[
'a '
],
aaa
,
'split'
,
None
,
19
)
for
b
in
(
'arf
\t
barf'
,
'arf
\n
barf'
,
'arf
\r
barf'
,
'arf
\f
barf'
,
'arf
\v
barf'
):
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'split'
)
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'split'
,
None
)
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'split'
,
None
,
2
)
# by a char
self
.
checkequal
([
'a'
,
'b'
,
'c'
,
'd'
],
'a|b|c|d'
,
'split'
,
'|'
)
self
.
checkequal
([
'a|b|c|d'
],
'a|b|c|d'
,
'split'
,
'|'
,
0
)
...
...
@@ -368,6 +376,8 @@ class CommonTest(unittest.TestCase):
sys
.
maxint
-
2
)
self
.
checkequal
([
'a|b|c|d'
],
'a|b|c|d'
,
'split'
,
'|'
,
0
)
self
.
checkequal
([
'a'
,
''
,
'b||c||d'
],
'a||b||c||d'
,
'split'
,
'|'
,
2
)
self
.
checkequal
([
'abcd'
],
'abcd'
,
'split'
,
'|'
)
self
.
checkequal
([
''
],
''
,
'split'
,
'|'
)
self
.
checkequal
([
'endcase '
,
''
],
'endcase |'
,
'split'
,
'|'
)
self
.
checkequal
([
''
,
' startcase'
],
'| startcase'
,
'split'
,
'|'
)
self
.
checkequal
([
''
,
'bothcase'
,
''
],
'|bothcase|'
,
'split'
,
'|'
)
...
...
@@ -438,16 +448,25 @@ class CommonTest(unittest.TestCase):
self
.
checkequal
([
'a'
],
' a '
,
'rsplit'
)
self
.
checkequal
([
'a'
,
'b'
],
' a b '
,
'rsplit'
)
self
.
checkequal
([
' a'
,
'b'
],
' a b '
,
'rsplit'
,
None
,
1
)
self
.
checkequal
([
' a b c'
],
' a b c '
,
'rsplit'
,
None
,
0
)
self
.
checkequal
([
' a b'
,
'c'
],
' a b c '
,
'rsplit'
,
None
,
1
)
self
.
checkequal
([
' a'
,
'b'
,
'c'
],
' a b c '
,
'rsplit'
,
None
,
2
)
self
.
checkequal
([
'a'
,
'b'
,
'c'
],
' a b c '
,
'rsplit'
,
None
,
3
)
self
.
checkequal
([
'a'
,
'b'
],
'
\n\t
a
\t\r
b
\v
'
,
'rsplit'
,
None
,
88
)
aaa
=
' a '
*
20
self
.
checkequal
([
'a'
]
*
20
,
aaa
,
'rsplit'
)
self
.
checkequal
([
aaa
[:
-
4
]]
+
[
'a'
],
aaa
,
'rsplit'
,
None
,
1
)
self
.
checkequal
([
' a a'
]
+
[
'a'
]
*
18
,
aaa
,
'rsplit'
,
None
,
18
)
for
b
in
(
'arf
\t
barf'
,
'arf
\n
barf'
,
'arf
\r
barf'
,
'arf
\f
barf'
,
'arf
\v
barf'
):
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'rsplit'
)
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'rsplit'
,
None
)
self
.
checkequal
([
'arf'
,
'barf'
],
b
,
'rsplit'
,
None
,
2
)
# by a char
self
.
checkequal
([
'a'
,
'b'
,
'c'
,
'd'
],
'a|b|c|d'
,
'rsplit'
,
'|'
)
...
...
@@ -459,6 +478,8 @@ class CommonTest(unittest.TestCase):
sys
.
maxint
-
100
)
self
.
checkequal
([
'a|b|c|d'
],
'a|b|c|d'
,
'rsplit'
,
'|'
,
0
)
self
.
checkequal
([
'a||b||c'
,
''
,
'd'
],
'a||b||c||d'
,
'rsplit'
,
'|'
,
2
)
self
.
checkequal
([
'abcd'
],
'abcd'
,
'rsplit'
,
'|'
)
self
.
checkequal
([
''
],
''
,
'rsplit'
,
'|'
)
self
.
checkequal
([
''
,
' begincase'
],
'| begincase'
,
'rsplit'
,
'|'
)
self
.
checkequal
([
'endcase '
,
''
],
'endcase |'
,
'rsplit'
,
'|'
)
self
.
checkequal
([
''
,
'bothcase'
,
''
],
'|bothcase|'
,
'rsplit'
,
'|'
)
...
...
@@ -510,23 +531,33 @@ class CommonTest(unittest.TestCase):
self
.
checkraises
(
ValueError
,
'hello'
,
'rsplit'
,
''
)
self
.
checkraises
(
ValueError
,
'hello'
,
'rsplit'
,
''
,
0
)
def
test_strip
(
self
):
def
test_strip
_whitespace
(
self
):
self
.
checkequal
(
'hello'
,
' hello '
,
'strip'
)
self
.
checkequal
(
'hello '
,
' hello '
,
'lstrip'
)
self
.
checkequal
(
' hello'
,
' hello '
,
'rstrip'
)
self
.
checkequal
(
'hello'
,
'hello'
,
'strip'
)
b
=
'
\t\n\r\f\v
abc
\t\n\r\f\v
'
self
.
checkequal
(
'abc'
,
b
,
'strip'
)
self
.
checkequal
(
'abc
\t\n\r\f\v
'
,
b
,
'lstrip'
)
self
.
checkequal
(
'
\t\n\r\f\v
abc'
,
b
,
'rstrip'
)
# strip/lstrip/rstrip with None arg
self
.
checkequal
(
'hello'
,
' hello '
,
'strip'
,
None
)
self
.
checkequal
(
'hello '
,
' hello '
,
'lstrip'
,
None
)
self
.
checkequal
(
' hello'
,
' hello '
,
'rstrip'
,
None
)
self
.
checkequal
(
'hello'
,
'hello'
,
'strip'
,
None
)
def
test_strip
(
self
):
# strip/lstrip/rstrip with str arg
self
.
checkequal
(
'hello'
,
'xyzzyhelloxyzzy'
,
'strip'
,
'xyz'
)
self
.
checkequal
(
'helloxyzzy'
,
'xyzzyhelloxyzzy'
,
'lstrip'
,
'xyz'
)
self
.
checkequal
(
'xyzzyhello'
,
'xyzzyhelloxyzzy'
,
'rstrip'
,
'xyz'
)
self
.
checkequal
(
'hello'
,
'hello'
,
'strip'
,
'xyz'
)
self
.
checkequal
(
''
,
'mississippi'
,
'strip'
,
'mississippi'
)
# only trims the start and end, does not strip internal characters
self
.
checkequal
(
'mississipp'
,
'mississippi'
,
'strip'
,
'i'
)
# strip/lstrip/rstrip with unicode arg
if
self
.
type2test
is
not
bytearray
and
test_support
.
have_unicode
:
...
...
Lib/test/test_bytes.py
Dosyayı görüntüle @
f1669a39
...
...
@@ -336,52 +336,16 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertEqual
(
b
.
replace
(
b
'i'
,
b
'a'
),
b
'massassappa'
)
self
.
assertEqual
(
b
.
replace
(
b
'ss'
,
b
'x'
),
b
'mixixippi'
)
def
test_split
(
self
):
b
=
self
.
type2test
(
b
'mississippi'
)
self
.
assertEqual
(
b
.
split
(
b
'i'
),
[
b
'm'
,
b
'ss'
,
b
'ss'
,
b
'pp'
,
b
''
])
self
.
assertEqual
(
b
.
split
(
b
'ss'
),
[
b
'mi'
,
b
'i'
,
b
'ippi'
])
self
.
assertEqual
(
b
.
split
(
b
'w'
),
[
b
])
def
test_split_whitespace
(
self
):
for
b
in
(
b
' arf barf '
,
b
'arf
\t
barf'
,
b
'arf
\n
barf'
,
b
'arf
\r
barf'
,
b
'arf
\f
barf'
,
b
'arf
\v
barf'
):
b
=
self
.
type2test
(
b
)
self
.
assertEqual
(
b
.
split
(),
[
b
'arf'
,
b
'barf'
])
self
.
assertEqual
(
b
.
split
(
None
),
[
b
'arf'
,
b
'barf'
])
self
.
assertEqual
(
b
.
split
(
None
,
2
),
[
b
'arf'
,
b
'barf'
])
for
b
in
(
b
'a
\x1C
b'
,
b
'a
\x1D
b'
,
b
'a
\x1E
b'
,
b
'a
\x1F
b'
):
b
=
self
.
type2test
(
b
)
self
.
assertEqual
(
b
.
split
(),
[
b
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
split
(
None
,
0
),
[
b
'a bb c '
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
split
(
None
,
1
),
[
b
'a'
,
b
'bb c '
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
split
(
None
,
2
),
[
b
'a'
,
b
'bb'
,
b
'c '
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
split
(
None
,
3
),
[
b
'a'
,
b
'bb'
,
b
'c'
])
def
test_split_string_error
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
type2test
(
b
'a b'
)
.
split
,
u' '
)
def
test_split_unicodewhitespace
(
self
):
for
b
in
(
b
'a
\x1C
b'
,
b
'a
\x1D
b'
,
b
'a
\x1E
b'
,
b
'a
\x1F
b'
):
b
=
self
.
type2test
(
b
)
self
.
assertEqual
(
b
.
split
(),
[
b
])
b
=
self
.
type2test
(
b
"
\x09\x0A\x0B\x0C\x0D\x1C\x1D\x1E\x1F
"
)
self
.
assertEqual
(
b
.
split
(),
[
b
'
\x1c\x1d\x1e\x1f
'
])
def
test_rsplit
(
self
):
b
=
self
.
type2test
(
b
'mississippi'
)
self
.
assertEqual
(
b
.
rsplit
(
b
'i'
),
[
b
'm'
,
b
'ss'
,
b
'ss'
,
b
'pp'
,
b
''
])
self
.
assertEqual
(
b
.
rsplit
(
b
'ss'
),
[
b
'mi'
,
b
'i'
,
b
'ippi'
])
self
.
assertEqual
(
b
.
rsplit
(
b
'w'
),
[
b
])
def
test_rsplit_whitespace
(
self
):
for
b
in
(
b
' arf barf '
,
b
'arf
\t
barf'
,
b
'arf
\n
barf'
,
b
'arf
\r
barf'
,
b
'arf
\f
barf'
,
b
'arf
\v
barf'
):
b
=
self
.
type2test
(
b
)
self
.
assertEqual
(
b
.
rsplit
(),
[
b
'arf'
,
b
'barf'
])
self
.
assertEqual
(
b
.
rsplit
(
None
),
[
b
'arf'
,
b
'barf'
])
self
.
assertEqual
(
b
.
rsplit
(
None
,
2
),
[
b
'arf'
,
b
'barf'
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
rsplit
(
None
,
0
),
[
b
' a bb c'
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
rsplit
(
None
,
1
),
[
b
' a bb'
,
b
'c'
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
rsplit
(
None
,
2
),
[
b
' a'
,
b
'bb'
,
b
'c'
])
self
.
assertEqual
(
self
.
type2test
(
b
' a bb c '
)
.
rsplit
(
None
,
3
),
[
b
'a'
,
b
'bb'
,
b
'c'
])
def
test_rsplit_string_error
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
type2test
(
b
'a b'
)
.
rsplit
,
u' '
)
...
...
@@ -408,37 +372,6 @@ class BaseBytesTest(unittest.TestCase):
q
=
pickle
.
loads
(
ps
)
self
.
assertEqual
(
b
,
q
)
def
test_strip
(
self
):
b
=
self
.
type2test
(
b
'mississippi'
)
self
.
assertEqual
(
b
.
strip
(
b
'i'
),
b
'mississipp'
)
self
.
assertEqual
(
b
.
strip
(
b
'm'
),
b
'ississippi'
)
self
.
assertEqual
(
b
.
strip
(
b
'pi'
),
b
'mississ'
)
self
.
assertEqual
(
b
.
strip
(
b
'im'
),
b
'ssissipp'
)
self
.
assertEqual
(
b
.
strip
(
b
'pim'
),
b
'ssiss'
)
self
.
assertEqual
(
b
.
strip
(
b
),
b
''
)
def
test_lstrip
(
self
):
b
=
self
.
type2test
(
b
'mississippi'
)
self
.
assertEqual
(
b
.
lstrip
(
b
'i'
),
b
'mississippi'
)
self
.
assertEqual
(
b
.
lstrip
(
b
'm'
),
b
'ississippi'
)
self
.
assertEqual
(
b
.
lstrip
(
b
'pi'
),
b
'mississippi'
)
self
.
assertEqual
(
b
.
lstrip
(
b
'im'
),
b
'ssissippi'
)
self
.
assertEqual
(
b
.
lstrip
(
b
'pim'
),
b
'ssissippi'
)
def
test_rstrip
(
self
):
b
=
self
.
type2test
(
b
'mississippi'
)
self
.
assertEqual
(
b
.
rstrip
(
b
'i'
),
b
'mississipp'
)
self
.
assertEqual
(
b
.
rstrip
(
b
'm'
),
b
'mississippi'
)
self
.
assertEqual
(
b
.
rstrip
(
b
'pi'
),
b
'mississ'
)
self
.
assertEqual
(
b
.
rstrip
(
b
'im'
),
b
'mississipp'
)
self
.
assertEqual
(
b
.
rstrip
(
b
'pim'
),
b
'mississ'
)
def
test_strip_whitespace
(
self
):
b
=
self
.
type2test
(
b
'
\t\n\r\f\v
abc
\t\n\r\f\v
'
)
self
.
assertEqual
(
b
.
strip
(),
b
'abc'
)
self
.
assertEqual
(
b
.
lstrip
(),
b
'abc
\t\n\r\f\v
'
)
self
.
assertEqual
(
b
.
rstrip
(),
b
'
\t\n\r\f\v
abc'
)
def
test_strip_bytearray
(
self
):
self
.
assertEqual
(
self
.
type2test
(
b
'abc'
)
.
strip
(
memoryview
(
b
'ac'
)),
b
'b'
)
self
.
assertEqual
(
self
.
type2test
(
b
'abc'
)
.
lstrip
(
memoryview
(
b
'ac'
)),
b
'bc'
)
...
...
@@ -1020,7 +953,7 @@ class AssortedBytesTest(unittest.TestCase):
# XXX More string methods? (Those that don't use character properties)
# There are tests in string_tests.py that are more
# comprehensive for things like
split,
partition, etc.
# comprehensive for things like partition, etc.
# Unfortunately they are all bundled with tests that
# are not appropriate for bytes
...
...
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