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
ca87aefe
Kaydet (Commit)
ca87aefe
authored
Ock 27, 2003
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #670715: Universal Unicode Codec for POSIX iconv.
üst
7e172898
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
0 deletions
+95
-0
test_iconv_codecs.py
Lib/test/test_iconv_codecs.py
+95
-0
No files found.
Lib/test/test_iconv_codecs.py
0 → 100644
Dosyayı görüntüle @
ca87aefe
from
test
import
test_support
import
unittest
,
sys
import
codecs
,
_iconv_codec
from
encodings
import
iconv_codec
from
StringIO
import
StringIO
class
IconvCodecTest
(
unittest
.
TestCase
):
if
sys
.
byteorder
==
'big'
:
spam
=
'
\x00
s
\x00
p
\x00
a
\x00
m
\x00
s
\x00
p
\x00
a
\x00
m'
else
:
spam
=
's
\x00
p
\x00
a
\x00
m
\x00
s
\x00
p
\x00
a
\x00
m
\x00
'
def
test_sane
(
self
):
self
.
encoder
,
self
.
decoder
,
self
.
reader
,
self
.
writer
=
\
codecs
.
lookup
(
_iconv_codec
.
internal_encoding
)
self
.
assertEqual
(
self
.
decoder
(
self
.
spam
),
(
u'spamspam'
,
16
))
self
.
assertEqual
(
self
.
encoder
(
u'spamspam'
),
(
self
.
spam
,
8
))
self
.
assertEqual
(
self
.
reader
(
StringIO
(
self
.
spam
))
.
read
(),
u'spamspam'
)
f
=
StringIO
()
self
.
writer
(
f
)
.
write
(
u'spamspam'
)
self
.
assertEqual
(
f
.
getvalue
(),
self
.
spam
)
def
test_basic_errors
(
self
):
self
.
encoder
,
self
.
decoder
,
self
.
reader
,
self
.
writer
=
\
iconv_codec
.
lookup
(
"ascii"
)
def
testencerror
(
errors
):
return
self
.
encoder
(
u'sp
\ufffd
am'
,
errors
)
def
testdecerror
(
errors
):
return
self
.
decoder
(
'sp
\xff
am'
,
errors
)
self
.
assertRaises
(
UnicodeEncodeError
,
testencerror
,
'strict'
)
self
.
assertRaises
(
UnicodeDecodeError
,
testdecerror
,
'strict'
)
self
.
assertEqual
(
testencerror
(
'replace'
),
(
'sp?am'
,
5
))
self
.
assertEqual
(
testdecerror
(
'replace'
),
(
u'sp
\ufffd
am'
,
5
))
self
.
assertEqual
(
testencerror
(
'ignore'
),
(
'spam'
,
5
))
self
.
assertEqual
(
testdecerror
(
'ignore'
),
(
u'spam'
,
5
))
def
test_pep293_errors
(
self
):
self
.
encoder
,
self
.
decoder
,
self
.
reader
,
self
.
writer
=
\
iconv_codec
.
lookup
(
"ascii"
)
def
testencerror
(
errors
):
return
self
.
encoder
(
u'sp
\ufffd
am'
,
errors
)
def
testdecerror
(
errors
):
return
self
.
decoder
(
'sp
\xff
am'
,
errors
)
self
.
assertEqual
(
testencerror
(
'xmlcharrefreplace'
),
(
'sp�am'
,
5
))
self
.
assertEqual
(
testencerror
(
'backslashreplace'
),
(
'sp
\\
ufffdam'
,
5
))
def
error_bomb
(
exc
):
return
(
u'*'
*
40
,
len
(
exc
.
object
))
def
error_mock
(
exc
):
error_mock
.
lastexc
=
exc
return
(
unicode
(
exc
.
object
[
exc
.
start
-
1
]),
exc
.
end
)
codecs
.
register_error
(
'test_iconv_codec.bomb'
,
error_bomb
)
codecs
.
register_error
(
'test_iconv_codec.mock'
,
error_mock
)
self
.
assertEqual
(
testencerror
(
'test_iconv_codec.bomb'
),
(
'sp'
+
(
'*'
*
40
),
5
))
self
.
assertEqual
(
testdecerror
(
'test_iconv_codec.bomb'
),
(
u'sp'
+
(
u'*'
*
40
),
5
))
self
.
assertEqual
(
testencerror
(
'test_iconv_codec.mock'
),
(
'sppam'
,
5
))
exc
=
error_mock
.
lastexc
self
.
assertEqual
(
exc
.
object
,
u'sp
\ufffd
am'
)
self
.
assertEqual
(
exc
.
start
,
2
)
self
.
assertEqual
(
exc
.
end
,
3
)
self
.
assert_
(
isinstance
(
exc
,
UnicodeEncodeError
))
self
.
assertEqual
(
testdecerror
(
'test_iconv_codec.mock'
),
(
u'sppam'
,
5
))
exc
=
error_mock
.
lastexc
self
.
assertEqual
(
exc
.
object
,
'sp
\xff
am'
)
self
.
assertEqual
(
exc
.
start
,
2
)
self
.
assertEqual
(
exc
.
end
,
3
)
self
.
assert_
(
isinstance
(
exc
,
UnicodeDecodeError
))
def
test_empty_escape_decode
(
self
):
self
.
encoder
,
self
.
decoder
,
self
.
reader
,
self
.
writer
=
\
iconv_codec
.
lookup
(
"ascii"
)
self
.
assertEquals
(
self
.
decoder
(
u""
),
(
""
,
0
))
self
.
assertEquals
(
self
.
encoder
(
""
),
(
u""
,
0
))
def
test_main
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
IconvCodecTest
))
test_support
.
run_suite
(
suite
)
if
__name__
==
"__main__"
:
test_main
()
# ex: ts=8 sts=4 et
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