[New-bugs-announce] [issue4824] test_cmd_line failure on Mac OS X for py3k

Skip Montanaro report at bugs.python.org
Sun Jan 4 00:30:39 CET 2009

New submission from Skip Montanaro <skip at pobox.com>:

test_cmd_line.test_run_code fails for me on Mac OS X:

    % ./python.exe -bb  Lib/test/regrtest.py -v test_cmd_line
    test_directories (test.test_cmd_line.CmdLineTest) ... ok
    test_optimize (test.test_cmd_line.CmdLineTest) ... ok
    test_q (test.test_cmd_line.CmdLineTest) ... ok
    test_run_code (test.test_cmd_line.CmdLineTest) ... FAIL
    test_run_module (test.test_cmd_line.CmdLineTest) ... ok
    test_run_module_bug1764407 (test.test_cmd_line.CmdLineTest) ... ok
    test_site_flag (test.test_cmd_line.CmdLineTest) ... ok
    test_usage (test.test_cmd_line.CmdLineTest) ... ok
    test_verbose (test.test_cmd_line.CmdLineTest) ... ok
    test_version (test.test_cmd_line.CmdLineTest) ... ok

    FAIL: test_run_code (test.test_cmd_line.CmdLineTest)
    Traceback (most recent call last):
      File "/Users/skip/src/python/py3k/Lib/test/test_cmd_line.py", line 143, in test_run_code
    AssertionError: 1 != 0

    Ran 10 tests in 1.282s

Manually running what that test executes shows the problem:

    % ./python.exe 
    Python 3.1a0 (py3k:68218, Jan  3 2009, 15:06:30) 
    [GCC 4.0.1 (Apple Inc. build 5490)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> sys.executable
    >>> import subprocess
    >>> import sys
    >>> cmd_line = [sys.executable, '-E']
    >>> cmd_line.extend(['-c', "assert(ord('\xe9') == 0xe9)"])
    >>> cmd_line
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/skip/src/python/py3k/Lib/io.py", line 1488, in write
        b = encoder.encode(s)
      File "/Users/skip/src/python/py3k/Lib/encodings/ascii.py", line 22, in encode
        return codecs.ascii_encode(input, self.errors)[0]
    UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 68: ordinal not in range(128)
    >>> sys.getfilesystemencoding()
    >>> subprocess.call(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

If I execute that command from the shell prompt I do get a zero exit code no
matter what I try to mimic the scenario in the test:

    py3k% ./python.exe -E -c 'assert(ord("\xe9") == 0xe9)'
    py3k% echo $?
    py3k% ./python.exe -E -c 'assert(ord("\xe9") == 0xe9)' > /tmp/trash 2>&1
    py3k% echo $?
    py3k% ./python.exe -E -c 'assert(ord("\xe9") == 0xe9)' 2>&1 | cat > /dev/null
    py3k% echo $?

I'm not sure where the problem lies.

messages: 79023
nosy: skip.montanaro
severity: normal
status: open
title: test_cmd_line failure on Mac OS X for py3k

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list