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 |
Related bugs: |
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.
Unmerged revisions
- 51. By Jerry Seutter
-
Changes to make the fixtures library work in Python 3.
On May 20, 2012, at 04:14 AM, Jerry Seutter wrote:
=== modified file 'lib/fixtures/ tests/_ fixtures/ test_pythonpack age.py' tests/_ fixtures/ test_pythonpack age.py 2011-07-26 23:07:48 +0000 tests/_ fixtures/ test_pythonpack age.py 2012-05-20 04:12:17 +0000 'foo', [('bar.py', _b('woo'))]) l('', open(os. path.join( fixture. base, 'foo', _.py')) .read() ) l('woo' , open(os. path.join( fixture. base, 'foo', path.join( fixture. base, 'foo', '__init__.py')) l('', f.read()) path.join( fixture. base, 'foo', 'bar.py')) l('woo' , f.read())
--- lib/fixtures/
+++ lib/fixtures/
> @@ -36,10 +36,13 @@
> fixture = PythonPackage(
> fixture.setUp()
> try:
> - self.assertEqua
> - '__init_
> - self.assertEqua
> - 'bar.py')).read())
> + f = open(os.
> + self.assertEqua
> + f.close()
> +
> + f = open(os.
> + self.assertEqua
> + f.close()
> finally:
> fixture.cleanUp()
A couple of suggestions here. If you can target Python 2.7 as your minimum addCleanup( ). In any case, wrapping the f.read()s in a
version (or you're using unittest2), you can avoid the outer try/finally by
using TestCase.
with-statement is probably better. E.g. for 2.7, I'd write this like so:
fixture = PythonPackage('foo, [('bar.py', _b('woo'))]) addCleanup( fixture. cleanUp) path.join( fixture. base, 'foo', '__init__.py')) as fp:
self.assertEqu al('', fp.read()) path.join( fixture. base, 'foo', 'bar.py')) as fp:
self.assertEqu al('woo' , fp.read())
fixture.setUp()
self.
with open(os.
with open(os.
=== modified file 'setup.py' path.join( os.path. dirname( __file_ _), 'README'), 'rb').read() join(os. path.dirname( __file_ _), 'README') ).decode( 'utf-8' ) "fixtures" ,
--- 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.
> +readme_path = os.path.
> +description = open(readme_path, 'rb').read(
>
> setup(name=
> version="0.3.8",
Again, a with-statement is safer:
with open(readme_path, 'rb') as fp: ).decode( 'utf-8' )
description = fp.read(
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_pythonpack age.py' tests/_ fixtures/ test_pythonpack age.py 2011-07-26 23:07:48 +0000 tests/_ fixtures/ test_pythonpack age.py 2012-05-20 04:12:17 +0000 'foo', [('bar.py', _b('woo'))]) l('', open(os. path.join( fixture. base, 'foo', _.py')) .read() ) l('woo' , open(os. path.join( fixture. base, 'foo', path.join( fixture. base, 'foo', '__init__.py')) l('', f.read()) path.join( f...
--- lib/fixtures/
+++ lib/fixtures/
> @@ -36,10 +36,13 @@
> fixture = PythonPackage(
> fixture.setUp()
> try:
> - self.assertEqua
> - '__init_
> - self.assertEqua
> - 'bar.py')).read())
> + f = open(os.
> + self.assertEqua
> + f.close()
> +
> + f = open(os.