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
c732e3ba
Kaydet (Commit)
c732e3ba
authored
Agu 18, 2010
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
test_sys: move tests at the right place
filesystem encoding is not related to sys.sizeof()
üst
358b63a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
56 deletions
+57
-56
test_sys.py
Lib/test/test_sys.py
+57
-56
No files found.
Lib/test/test_sys.py
Dosyayı görüntüle @
c732e3ba
...
...
@@ -564,6 +564,63 @@ class SysModuleTest(unittest.TestCase):
p
.
wait
()
self
.
assertIn
(
executable
,
[
"b''"
,
repr
(
sys
.
executable
.
encode
(
"ascii"
,
"backslashreplace"
))])
def
test_getfilesystemencoding
(
self
):
import
codecs
def
check_fsencoding
(
fs_encoding
,
expected
=
None
):
self
.
assertIsNotNone
(
fs_encoding
)
if
sys
.
platform
==
'darwin'
:
self
.
assertEqual
(
fs_encoding
,
'utf-8'
)
codecs
.
lookup
(
fs_encoding
)
if
expected
:
self
.
assertEqual
(
fs_encoding
,
expected
)
fs_encoding
=
sys
.
getfilesystemencoding
()
check_fsencoding
(
fs_encoding
)
def
get_fsencoding
(
env
):
output
=
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"import sys; print(sys.getfilesystemencoding())"
],
env
=
env
)
return
output
.
rstrip
()
.
decode
(
'ascii'
)
try
:
sys
.
executable
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
# Python doesn't start with ASCII locale if its path is not ASCII,
# see issue #8611
pass
else
:
# Even in C locale
env
=
os
.
environ
.
copy
()
env
[
'LANG'
]
=
'C'
try
:
del
env
[
'PYTHONFSENCODING'
]
except
KeyError
:
pass
check_fsencoding
(
get_fsencoding
(
env
),
'ascii'
)
# Filesystem encoding is hardcoded on Windows and Mac OS X
if
sys
.
platform
not
in
(
'win32'
,
'darwin'
):
for
encoding
in
(
'ascii'
,
'cp850'
,
'iso8859-1'
,
'utf-8'
):
env
=
os
.
environ
.
copy
()
env
[
'PYTHONFSENCODING'
]
=
encoding
check_fsencoding
(
get_fsencoding
(
env
),
encoding
)
def
test_setfilesystemencoding
(
self
):
old
=
sys
.
getfilesystemencoding
()
try
:
sys
.
setfilesystemencoding
(
"iso-8859-1"
)
self
.
assertEqual
(
sys
.
getfilesystemencoding
(),
"iso-8859-1"
)
finally
:
sys
.
setfilesystemencoding
(
old
)
try
:
self
.
assertRaises
(
LookupError
,
sys
.
setfilesystemencoding
,
"xxx"
)
finally
:
sys
.
setfilesystemencoding
(
old
)
class
SizeofTest
(
unittest
.
TestCase
):
...
...
@@ -863,62 +920,6 @@ class SizeofTest(unittest.TestCase):
# sys.flags
check
(
sys
.
flags
,
size
(
vh
)
+
self
.
P
*
len
(
sys
.
flags
))
def
test_getfilesystemencoding
(
self
):
import
codecs
def
check_fsencoding
(
fs_encoding
,
expected
=
None
):
self
.
assertIsNotNone
(
fs_encoding
)
if
sys
.
platform
==
'darwin'
:
self
.
assertEqual
(
fs_encoding
,
'utf-8'
)
codecs
.
lookup
(
fs_encoding
)
if
expected
:
self
.
assertEqual
(
fs_encoding
,
expected
)
fs_encoding
=
sys
.
getfilesystemencoding
()
check_fsencoding
(
fs_encoding
)
def
get_fsencoding
(
env
):
output
=
subprocess
.
check_output
(
[
sys
.
executable
,
"-c"
,
"import sys; print(sys.getfilesystemencoding())"
],
env
=
env
)
return
output
.
rstrip
()
.
decode
(
'ascii'
)
try
:
sys
.
executable
.
encode
(
'ascii'
)
except
UnicodeEncodeError
:
# Python doesn't start with ASCII locale if its path is not ASCII,
# see issue #8611
pass
else
:
# Even in C locale
env
=
os
.
environ
.
copy
()
env
[
'LANG'
]
=
'C'
try
:
del
env
[
'PYTHONFSENCODING'
]
except
KeyError
:
pass
check_fsencoding
(
get_fsencoding
(
env
),
'ascii'
)
# Filesystem encoding is hardcoded on Windows and Mac OS X
if
sys
.
platform
not
in
(
'win32'
,
'darwin'
):
for
encoding
in
(
'ascii'
,
'cp850'
,
'iso8859-1'
,
'utf-8'
):
env
=
os
.
environ
.
copy
()
env
[
'PYTHONFSENCODING'
]
=
encoding
check_fsencoding
(
get_fsencoding
(
env
),
encoding
)
def
test_setfilesystemencoding
(
self
):
old
=
sys
.
getfilesystemencoding
()
try
:
sys
.
setfilesystemencoding
(
"iso-8859-1"
)
self
.
assertEqual
(
sys
.
getfilesystemencoding
(),
"iso-8859-1"
)
finally
:
sys
.
setfilesystemencoding
(
old
)
try
:
self
.
assertRaises
(
LookupError
,
sys
.
setfilesystemencoding
,
"xxx"
)
finally
:
sys
.
setfilesystemencoding
(
old
)
def
test_main
():
test
.
support
.
run_unittest
(
SysModuleTest
,
SizeofTest
)
...
...
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