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
f6211eda
Commit
f6211eda
authored
Oct 20, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move test_undecodable_code() from test_sys to test_cmd_line
parent
6722b5f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
38 deletions
+38
-38
Lib/test/test_cmd_line.py
Lib/test/test_cmd_line.py
+38
-0
Lib/test/test_sys.py
Lib/test/test_sys.py
+0
-38
No files found.
Lib/test/test_cmd_line.py
View file @
f6211eda
...
...
@@ -108,6 +108,44 @@ class CmdLineTest(unittest.TestCase):
command
=
"assert(ord('
\
xe9
') == 0xe9)"
assert_python_ok
(
'-c'
,
command
)
# On Windows, pass bytes to subprocess doesn't test how Python decodes the
# command line, but how subprocess does decode bytes to unicode. Python
# doesn't decode the command line because Windows provides directly the
# arguments as unicode (using wmain() instead of main()).
@
unittest
.
skipIf
(
sys
.
platform
==
'win32'
,
'Windows has a native unicode API'
)
def
test_undecodable_code
(
self
):
undecodable
=
b"
\
xff
"
env
=
os
.
environ
.
copy
()
# Use C locale to get ascii for the locale encoding
env
[
'LC_ALL'
]
=
'C'
code
=
(
b'import locale; '
b'print(ascii("'
+
undecodable
+
b'"), '
b'locale.getpreferredencoding())'
)
p
=
subprocess
.
Popen
(
[
sys
.
executable
,
"-c"
,
code
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
env
=
env
)
stdout
,
stderr
=
p
.
communicate
()
if
p
.
returncode
==
1
:
# _Py_char2wchar() decoded b'\xff' as '\udcff' (b'\xff' is not
# decodable from ASCII) and run_command() failed on
# PyUnicode_AsUTF8String(). This is the expected behaviour on
# Linux.
pattern
=
b"Unable to decode the command from the command line:"
elif
p
.
returncode
==
0
:
# _Py_char2wchar() decoded b'\xff' as '\xff' even if the locale is
# C and the locale encoding is ASCII. It occurs on FreeBSD, Solaris
# and Mac OS X.
pattern
=
b"'
\
\
xff' "
# The output is followed by the encoding name, an alias to ASCII.
# Examples: "US-ASCII" or "646" (ISO 646, on Solaris).
else
:
raise
AssertionError
(
"Unknown exit code: %s, output=%a"
%
(
p
.
returncode
,
stdout
))
if
not
stdout
.
startswith
(
pattern
):
raise
AssertionError
(
"%a doesn't start with %a"
%
(
stdout
,
pattern
))
def
test_unbuffered_output
(
self
):
# Test expected operation of the '-u' switch
for
stream
in
(
'stdout'
,
'stderr'
):
...
...
Lib/test/test_sys.py
View file @
f6211eda
...
...
@@ -496,44 +496,6 @@ class SysModuleTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
sys
.
intern
,
S
(
"abc"
))
# On Windows, pass bytes to subprocess doesn't test how Python decodes the
# command line, but how subprocess does decode bytes to unicode. Python
# doesn't decode the command line because Windows provides directly the
# arguments as unicode (using wmain() instead of main()).
@
unittest
.
skipIf
(
sys
.
platform
==
'win32'
,
'Windows has a native unicode API'
)
def
test_undecodable_code
(
self
):
undecodable
=
b"
\
xff
"
env
=
os
.
environ
.
copy
()
# Use C locale to get ascii for the locale encoding
env
[
'LC_ALL'
]
=
'C'
code
=
(
b'import locale; '
b'print(ascii("'
+
undecodable
+
b'"), '
b'locale.getpreferredencoding())'
)
p
=
subprocess
.
Popen
(
[
sys
.
executable
,
"-c"
,
code
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
env
=
env
)
stdout
,
stderr
=
p
.
communicate
()
if
p
.
returncode
==
1
:
# _Py_char2wchar() decoded b'\xff' as '\udcff' (b'\xff' is not
# decodable from ASCII) and run_command() failed on
# PyUnicode_AsUTF8String(). This is the expected behaviour on
# Linux.
pattern
=
b"Unable to decode the command from the command line:"
elif
p
.
returncode
==
0
:
# _Py_char2wchar() decoded b'\xff' as '\xff' even if the locale is
# C and the locale encoding is ASCII. It occurs on FreeBSD, Solaris
# and Mac OS X.
pattern
=
b"'
\
\
xff' "
# The output is followed by the encoding name, an alias to ASCII.
# Examples: "US-ASCII" or "646" (ISO 646, on Solaris).
else
:
raise
AssertionError
(
"Unknown exit code: %s, output=%a"
%
(
p
.
returncode
,
stdout
))
if
not
stdout
.
startswith
(
pattern
):
raise
AssertionError
(
"%a doesn't start with %a"
%
(
stdout
,
pattern
))
def
test_sys_flags
(
self
):
self
.
assertTrue
(
sys
.
flags
)
attrs
=
(
"debug"
,
"division_warning"
,
...
...
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