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
cac1d236
Kaydet (Commit)
cac1d236
authored
Mar 20, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added new tests for detecting Python source code encoding.
üst
67818a1d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
3 deletions
+75
-3
test_source_encoding.py
Lib/test/test_source_encoding.py
+75
-3
No files found.
Lib/test/test_source_encoding.py
Dosyayı görüntüle @
cac1d236
# -*- coding: koi8-r -*-
import
test.test_support
,
unittest
import
unittest
from
test.test_support
import
run_unittest
,
rmtree
,
captured_stdout
import
script_helper
import
os
import
tempfile
class
SourceEncodingTest
(
unittest
.
TestCase
):
class
Misc
SourceEncodingTest
(
unittest
.
TestCase
):
def
test_pep263
(
self
):
self
.
assertEqual
(
...
...
@@ -90,8 +93,77 @@ class SourceEncodingTest(unittest.TestCase):
self
.
assertTrue
(
c
.
exception
.
args
[
0
]
.
startswith
(
expected
))
class
AbstractSourceEncodingTest
:
def
test_first_coding_line
(
self
):
src
=
(
'#coding:iso8859-15
\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_second_coding_line
(
self
):
src
=
(
'#
\n
'
'#coding:iso8859-15
\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_double_coding_line
(
self
):
# If the first line matches the second line is ignored.
src
=
(
'#coding:iso8859-15
\n
'
'#coding:latin1
\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_double_coding_same_line
(
self
):
src
=
(
'#coding:iso8859-15 coding:latin1
\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_first_non_utf8_coding_line
(
self
):
src
=
(
'#coding:iso-8859-15
\xa4\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_second_non_utf8_coding_line
(
self
):
src
=
(
'
\n
'
'#coding:iso-8859-15
\xa4\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xc3\u20ac'"
)
def
test_utf8_bom
(
self
):
src
=
(
'
\xef\xbb\xbf
print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xe4'"
)
def
test_utf8_bom_and_utf8_coding_line
(
self
):
src
=
(
'
\xef\xbb\xbf
#coding:utf-8
\n
'
'print(repr(u"
\xc3\xa4
"))
\n
'
)
self
.
check_script_output
(
src
,
r"u'\xe4'"
)
class
BytesSourceEncodingTest
(
AbstractSourceEncodingTest
,
unittest
.
TestCase
):
def
check_script_output
(
self
,
src
,
expected
):
with
captured_stdout
()
as
stdout
:
exec
(
src
)
out
=
stdout
.
getvalue
()
.
encode
(
'latin1'
)
self
.
assertEqual
(
out
.
rstrip
(),
expected
)
class
FileSourceEncodingTest
(
AbstractSourceEncodingTest
,
unittest
.
TestCase
):
def
check_script_output
(
self
,
src
,
expected
):
tmpd
=
tempfile
.
mkdtemp
()
try
:
fn
=
os
.
path
.
join
(
tmpd
,
'test.py'
)
with
open
(
fn
,
'wb'
)
as
fp
:
fp
.
write
(
src
)
rc
,
out
,
err
=
script_helper
.
assert_python_ok
(
fn
)
finally
:
rmtree
(
tmpd
)
self
.
assertEqual
(
out
.
rstrip
(),
expected
)
def
test_main
():
test
.
test_support
.
run_unittest
(
SourceEncodingTest
)
run_unittest
(
MiscSourceEncodingTest
,
BytesSourceEncodingTest
,
File
SourceEncodingTest
)
if
__name__
==
"__main__"
:
test_main
()
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