1. Brodie Rao
  2. cram
  3. Issues
Issue #23 resolved

Python 3.3 compatibility

Steven Myint
created an issue

cram works with Python 3.2.

$ python3.2 ../cram/cram.py blah.t 
# Ran 1 tests, 0 skipped, 0 failed.

But fails on Python 3.3.

$ python3.3 ../cram/cram.py blah.t 
Traceback (most recent call last):
  File "../cram/cram.py", line 522, in <module>
  File "../cram/cram.py", line 513, in main
    patchcmd, answer, opts.indent)
  File "../cram/cram.py", line 325, in run
    refout, postout, diff = test(abspath, shell, indent)
  File "../cram/cram.py", line 213, in test
    output = p.communicate(input=encodeinput(''.join(stdin)))[0]
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 906, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 1516, in _communicate
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 1640, in _communicate_with_select
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/subprocess.py", line 1547, in _save_input
    self._input = self._input.encode(self.stdin.encoding)
AttributeError: 'bytes' object has no attribute 'encode'
$ cat blah.t 
  $ x=2
  $ echo $x

Comments (4)

  1. Steven Myint reporter

    By the way, this only happens on the development version. If I install 0.5 from PyPi, things work fine.

    $ cram blah.t 
    # Ran 1 tests, 0 skipped, 0 failed.
    $ cat `which cram`
    import sys
    import cram
    $ /opt/local/bin/python --version
    Python 3.3.0
  2. Brodie Rao repo owner

    This is caused by Cram passing a bytes object to Popen.communicate(), which apparently isn't supported when universal_newlines is True. (Cram 0.5 didn't use Popen.communicate() to send input to the shell, but that caused buffering deadlock problems on Windows.)

    The fix would be to pass in the original string object, but there's a bug in Python 3.2 that makes that blow up. The work around I put in place for that is what breaks Python 3.3 support.

    Here's the relevant bug against Python 3.2.x: http://bugs.python.org/issue16903

    I think the right thing to do here would be to use the API correctly, fixing Python 3.3, and wait until Python 3.2.4 is released before releasing a new version of Cram. The README should document the incompatibility with 3.2.3 and older.

  3. Log in to comment