Merge lp://staging/~jseutter/python-fixtures/py3 into lp://staging/~python-fixtures/python-fixtures/trunk

Proposed by Jerry Seutter
Status: Rejected
Rejected by: Robert Collins
Proposed branch: lp://staging/~jseutter/python-fixtures/py3
Merge into: lp://staging/~python-fixtures/python-fixtures/trunk
Diff against target: 72 lines (+20/-8)
4 files modified
lib/fixtures/_fixtures/logger.py (+5/-1)
lib/fixtures/tests/_fixtures/test_logger.py (+5/-1)
lib/fixtures/tests/_fixtures/test_pythonpackage.py (+7/-4)
setup.py (+3/-2)
To merge this branch: bzr merge lp://staging/~jseutter/python-fixtures/py3
Reviewer Review Type Date Requested Status
Robert Collins Disapprove
Barry Warsaw Pending
Review via email: mp+106509@code.staging.launchpad.net

Description of the change

This branch adds support for Python 3 while maintaining support for Python 2.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :
Download full text (3.9 KiB)

On May 20, 2012, at 04:14 AM, Jerry Seutter wrote:

=== modified file 'lib/fixtures/tests/_fixtures/test_pythonpackage.py'
--- lib/fixtures/tests/_fixtures/test_pythonpackage.py 2011-07-26 23:07:48 +0000
+++ lib/fixtures/tests/_fixtures/test_pythonpackage.py 2012-05-20 04:12:17 +0000
> @@ -36,10 +36,13 @@
> fixture = PythonPackage('foo', [('bar.py', _b('woo'))])
> fixture.setUp()
> try:
> - self.assertEqual('', open(os.path.join(fixture.base, 'foo',
> - '__init__.py')).read())
> - self.assertEqual('woo', open(os.path.join(fixture.base, 'foo',
> - 'bar.py')).read())
> + f = open(os.path.join(fixture.base, 'foo', '__init__.py'))
> + self.assertEqual('', f.read())
> + f.close()
> +
> + f = open(os.path.join(fixture.base, 'foo', 'bar.py'))
> + self.assertEqual('woo', f.read())
> + f.close()
> finally:
> fixture.cleanUp()

A couple of suggestions here. If you can target Python 2.7 as your minimum
version (or you're using unittest2), you can avoid the outer try/finally by
using TestCase.addCleanup(). In any case, wrapping the f.read()s in a
with-statement is probably better. E.g. for 2.7, I'd write this like so:

    fixture = PythonPackage('foo, [('bar.py', _b('woo'))])
    fixture.setUp()
    self.addCleanup(fixture.cleanUp)
    with open(os.path.join(fixture.base, 'foo', '__init__.py')) as fp:
        self.assertEqual('', fp.read())
    with open(os.path.join(fixture.base, 'foo', 'bar.py')) as fp:
        self.assertEqual('woo', fp.read())

=== modified file 'setup.py'
--- setup.py 2011-11-22 08:58:38 +0000
+++ setup.py 2012-05-20 04:12:17 +0000
> @@ -1,9 +1,10 @@
> #!/usr/bin/env python
> -
> from distutils.core import setup
> +
> import os.path
>
> -description = file(os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
> +readme_path = os.path.join(os.path.dirname(__file__), 'README')
> +description = open(readme_path, 'rb').read().decode('utf-8')
>
> setup(name="fixtures",
> version="0.3.8",

Again, a with-statement is safer:

with open(readme_path, 'rb') as fp:
    description = fp.read().decode('utf-8')

Also, it might be better to just use codecs.open() if you know you're reading
utf-8, e.g.

with codecs.open(readme_path, 'rb', 'utf-8') as fp:
    description = fp.read()

=== modified file 'lib/fixtures/tests/_fixtures/test_pythonpackage.py'
--- lib/fixtures/tests/_fixtures/test_pythonpackage.py 2011-07-26 23:07:48 +0000
+++ lib/fixtures/tests/_fixtures/test_pythonpackage.py 2012-05-20 04:12:17 +0000
> @@ -36,10 +36,13 @@
> fixture = PythonPackage('foo', [('bar.py', _b('woo'))])
> fixture.setUp()
> try:
> - self.assertEqual('', open(os.path.join(fixture.base, 'foo',
> - '__init__.py')).read())
> - self.assertEqual('woo', open(os.path.join(fixture.base, 'foo',
> - 'bar.py')).read())
> + f = open(os.path.join(fixture.base, 'foo', '__init__.py'))
> + self.assertEqual('', f.read())
> + f.close()
> +
> + f = open(os.path.join(f...

Read more...

Revision history for this message
Robert Collins (lifeless) wrote :

Fixtures *currently* targets Python 2.4. We may change this, but not
without a deprecation period of 1 or more releases. (Thats in the
README :)) Its nice that newer python has fixed problems with older
versions, but the lack of backports of features makes adoption of new
features a slow process.

Revision history for this message
Jerry Seutter (jseutter) wrote :

> Fixtures *currently* targets Python 2.4. We may change this, but not
> without a deprecation period of 1 or more releases. (Thats in the
> README :)) Its nice that newer python has fixed problems with older
> versions, but the lack of backports of features makes adoption of new
> features a slow process.

In light of this, I will hold off on implementing the changes Barry suggested. I did some testing with older python versions:

python 2.4 - Can't run make check because of a dependency on testtools, which no longer works in Python 2.4. Can't "import fixtures" in the interactive interpreter for the same reason.

python 2.5 - Can't run make check because of a with... statement in test_fixture.py. "import fixtures" in the interactive interpreter works.

In both cases, running sudo python2.x setup.py install a second time fails because test_fixture.py is installed in site-packages/fixtures. The second invocation of the command imports this directory at some point during the install process and fails.

I don't really know if my changes work in old versions of Python, but I have a hunch that they do. Do you object to my changes in their current form?

Revision history for this message
Robert Collins (lifeless) wrote :

Thanks for this branch, other incompatible stuff had landed since, and I forgot about it when fixing that - so trunk is now 3.x compatible, or at least I think it is. Sorry that you went to this effort and I took so long to get around to this.

review: Disapprove
Revision history for this message
Jerry Seutter (jseutter) wrote :

No problem. Thanks for the update :)

Unmerged revisions

51. By Jerry Seutter

Changes to make the fixtures library work in Python 3.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches