Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c732e3ba
Commit
c732e3ba
authored
Aug 18, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test_sys: move tests at the right place
filesystem encoding is not related to sys.sizeof()
parent
358b63a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
56 deletions
+57
-56
Lib/test/test_sys.py
Lib/test/test_sys.py
+57
-56
No files found.
Lib/test/test_sys.py
View file @
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