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
690402ff
Kaydet (Commit)
690402ff
authored
Kas 17, 2005
tarafından
Walter Dörwald
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
üst
a5389927
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
2 deletions
+150
-2
test_codeccallbacks.py
Lib/test/test_codeccallbacks.py
+131
-2
test_codecs.py
Lib/test/test_codecs.py
+19
-0
No files found.
Lib/test/test_codeccallbacks.py
Dosyayı görüntüle @
690402ff
...
...
@@ -18,6 +18,66 @@ class PosReturn:
self
.
pos
=
len
(
exc
.
object
)
return
(
u"<?>"
,
oldpos
)
# A UnicodeEncodeError object without a start attribute
class
NoStartUnicodeEncodeError
(
UnicodeEncodeError
):
def
__init__
(
self
):
UnicodeEncodeError
.
__init__
(
self
,
"ascii"
,
u""
,
0
,
1
,
"bad"
)
del
self
.
start
# A UnicodeEncodeError object with a bad start attribute
class
BadStartUnicodeEncodeError
(
UnicodeEncodeError
):
def
__init__
(
self
):
UnicodeEncodeError
.
__init__
(
self
,
"ascii"
,
u""
,
0
,
1
,
"bad"
)
self
.
start
=
[]
# A UnicodeEncodeError object without an end attribute
class
NoEndUnicodeEncodeError
(
UnicodeEncodeError
):
def
__init__
(
self
):
UnicodeEncodeError
.
__init__
(
self
,
"ascii"
,
u""
,
0
,
1
,
"bad"
)
del
self
.
end
# A UnicodeEncodeError object without an object attribute
class
NoObjectUnicodeEncodeError
(
UnicodeEncodeError
):
def
__init__
(
self
):
UnicodeEncodeError
.
__init__
(
self
,
"ascii"
,
u""
,
0
,
1
,
"bad"
)
del
self
.
object
# A UnicodeEncodeError object with a bad object attribute
class
BadObjectUnicodeEncodeError
(
UnicodeEncodeError
):
def
__init__
(
self
):
UnicodeEncodeError
.
__init__
(
self
,
"ascii"
,
u""
,
0
,
1
,
"bad"
)
self
.
object
=
[]
# A UnicodeDecodeError object without an end attribute
class
NoEndUnicodeDecodeError
(
UnicodeDecodeError
):
def
__init__
(
self
):
UnicodeDecodeError
.
__init__
(
self
,
"ascii"
,
""
,
0
,
1
,
"bad"
)
del
self
.
end
# A UnicodeDecodeError object with a bad object attribute
class
BadObjectUnicodeDecodeError
(
UnicodeDecodeError
):
def
__init__
(
self
):
UnicodeDecodeError
.
__init__
(
self
,
"ascii"
,
""
,
0
,
1
,
"bad"
)
self
.
object
=
[]
# A UnicodeTranslateError object without a start attribute
class
NoStartUnicodeTranslateError
(
UnicodeTranslateError
):
def
__init__
(
self
):
UnicodeTranslateError
.
__init__
(
self
,
u""
,
0
,
1
,
"bad"
)
del
self
.
start
# A UnicodeTranslateError object without an end attribute
class
NoEndUnicodeTranslateError
(
UnicodeTranslateError
):
def
__init__
(
self
):
UnicodeTranslateError
.
__init__
(
self
,
u""
,
0
,
1
,
"bad"
)
del
self
.
end
# A UnicodeTranslateError object without an object attribute
class
NoObjectUnicodeTranslateError
(
UnicodeTranslateError
):
def
__init__
(
self
):
UnicodeTranslateError
.
__init__
(
self
,
u""
,
0
,
1
,
"bad"
)
del
self
.
object
class
CodecCallbackTest
(
unittest
.
TestCase
):
def
test_xmlcharrefreplace
(
self
):
...
...
@@ -417,6 +477,56 @@ class CodecCallbackTest(unittest.TestCase):
codecs
.
replace_errors
,
UnicodeError
(
"ouch"
)
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoStartUnicodeEncodeError
()
)
self
.
assertRaises
(
TypeError
,
codecs
.
replace_errors
,
BadStartUnicodeEncodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoEndUnicodeEncodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoObjectUnicodeEncodeError
()
)
self
.
assertRaises
(
TypeError
,
codecs
.
replace_errors
,
BadObjectUnicodeEncodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoEndUnicodeDecodeError
()
)
self
.
assertRaises
(
TypeError
,
codecs
.
replace_errors
,
BadObjectUnicodeDecodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoStartUnicodeTranslateError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoEndUnicodeTranslateError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
replace_errors
,
NoObjectUnicodeTranslateError
()
)
# With the correct exception, "replace" returns an "?" or u"\ufffd" replacement
self
.
assertEquals
(
codecs
.
replace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\u3042
"
,
0
,
1
,
"ouch"
)),
...
...
@@ -455,10 +565,29 @@ class CodecCallbackTest(unittest.TestCase):
codecs
.
xmlcharrefreplace_errors
,
UnicodeTranslateError
(
u"
\u3042
"
,
0
,
1
,
"ouch"
)
)
self
.
assertRaises
(
AttributeError
,
codecs
.
xmlcharrefreplace_errors
,
NoStartUnicodeEncodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
xmlcharrefreplace_errors
,
NoEndUnicodeEncodeError
()
)
self
.
assertRaises
(
AttributeError
,
codecs
.
xmlcharrefreplace_errors
,
NoObjectUnicodeEncodeError
()
)
# Use the correct exception
cs
=
(
0
,
1
,
9
,
10
,
99
,
100
,
999
,
1000
,
9999
,
10000
,
0x3042
)
s
=
""
.
join
(
unichr
(
c
)
for
c
in
cs
)
self
.
assertEquals
(
codecs
.
xmlcharrefreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\u3042
"
,
0
,
1
,
"ouch"
)),
(
u"&#
%
d;"
%
0x3042
,
1
)
codecs
.
xmlcharrefreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
s
,
0
,
len
(
s
),
"ouch"
)
),
(
u""
.
join
(
u"&#
%
d;"
%
ord
(
c
)
for
c
in
s
),
len
(
s
))
)
def
test_badandgoodbackslashreplaceexceptions
(
self
):
...
...
Lib/test/test_codecs.py
Dosyayı görüntüle @
690402ff
...
...
@@ -746,15 +746,34 @@ class CodecsModuleTest(unittest.TestCase):
self
.
assertEquals
(
codecs
.
encode
(
u'
\xe4\xf6\xfc
'
,
'latin-1'
),
'
\xe4\xf6\xfc
'
)
self
.
assertRaises
(
TypeError
,
codecs
.
encode
)
self
.
assertRaises
(
LookupError
,
codecs
.
encode
,
"foo"
,
"__spam__"
)
self
.
assertEquals
(
codecs
.
encode
(
u'abc'
),
'abc'
)
self
.
assertRaises
(
UnicodeEncodeError
,
codecs
.
encode
,
u'
\xff
ff'
,
'ascii'
)
def
test_register
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
register
)
self
.
assertRaises
(
TypeError
,
codecs
.
register
,
42
)
def
test_lookup
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
lookup
)
self
.
assertRaises
(
LookupError
,
codecs
.
lookup
,
"__spam__"
)
self
.
assertRaises
(
LookupError
,
codecs
.
lookup
,
" "
)
def
test_getencoder
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
getencoder
)
self
.
assertRaises
(
LookupError
,
codecs
.
getencoder
,
"__spam__"
)
def
test_getdecoder
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
getdecoder
)
self
.
assertRaises
(
LookupError
,
codecs
.
getdecoder
,
"__spam__"
)
def
test_getreader
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
getreader
)
self
.
assertRaises
(
LookupError
,
codecs
.
getreader
,
"__spam__"
)
def
test_getwriter
(
self
):
self
.
assertRaises
(
TypeError
,
codecs
.
getwriter
)
self
.
assertRaises
(
LookupError
,
codecs
.
getwriter
,
"__spam__"
)
class
StreamReaderTest
(
unittest
.
TestCase
):
...
...
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