diff options
author | Robert Collins <robertc@robertcollins.net> | 2011-08-14 19:02:48 +1200 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2011-08-14 19:02:48 +1200 |
commit | 2c02337753705ff5572f98cf968c17e1f06fd9bb (patch) | |
tree | bc6297cc19ca0d0d5c16affbfa0030f22f71185f | |
parent | 063ea50a5a85d7eba578b98d5d482cc51d31d178 (diff) | |
parent | 54a8f17e1e7a555977109cb3645dce941ec5b553 (diff) | |
download | fixtures-2c02337753705ff5572f98cf968c17e1f06fd9bb.tar.gz |
Merge jml's python 3 branch.
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r-- | NEWS | 7 | ||||
-rw-r--r-- | README | 18 | ||||
-rw-r--r-- | lib/fixtures/_fixtures/pythonpackage.py | 4 | ||||
-rw-r--r-- | lib/fixtures/fixture.py | 5 | ||||
-rw-r--r-- | lib/fixtures/testcase.py | 2 | ||||
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_popen.py | 9 | ||||
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_pythonpackage.py | 9 |
8 files changed, 34 insertions, 21 deletions
@@ -4,3 +4,4 @@ lib/testtools MANIFEST dist .testrepository +__pycache__ @@ -6,6 +6,13 @@ fixtures release notes IN DEVELOPMENT ~~~~~~~~~~~~~~ +CHANGES: + +* Python 3 now supported. (Jonathan Lange, #816665) + +* Updated to match the changed ``gather_details`` API in testtools. See #801027. + (Jonathan Lange) + 0.3.6 ~~~~~ @@ -28,7 +28,7 @@ Dependencies * Python 2.4+ This is the base language fixtures is written in and for. -* testtools <https://launchpad.net/testtools> 0.9.8 or newer. +* testtools <https://launchpad.net/testtools> 0.9.12 or newer. testtools provides helpful glue functions for the details API used to report information about a fixture (whether its used in a testing or production environment). @@ -99,7 +99,7 @@ puts the result of the function in fn_result:: ... shutil.rmtree(fixture) >>> fixture = fixtures.FunctionFixture(setup_function, teardown_function) >>> fixture.setUp() - >>> print os.path.isdir(fixture.fn_result) + >>> print (os.path.isdir(fixture.fn_result)) True >>> fixture.cleanUp() @@ -107,7 +107,7 @@ This can be expressed even more pithily: >>> fixture = fixtures.FunctionFixture(tempfile.mkdtemp, shutil.rmtree) >>> fixture.setUp() - >>> print os.path.isdir(fixture.fn_result) + >>> print (os.path.isdir(fixture.fn_result)) True >>> fixture.cleanUp() @@ -159,14 +159,14 @@ TestCase.addCleanup method. ... self.assertEqual(42, fixture.frobnozzle) >>> result = unittest.TestResult() >>> _ = NoddyTest('test_example').run(result) - >>> print result.wasSuccessful() + >>> print (result.wasSuccessful()) True Fixtures implement the context protocol, so you can also use a fixture as a context manager:: >>> with fixtures.FunctionFixture(setup_function, teardown_function) as fixture: - ... print os.path.isdir(fixture.fn_result) + ... print (os.path.isdir(fixture.fn_result)) True When multiple cleanups error, fixture.cleanUp() will raise a wrapper exception @@ -185,8 +185,8 @@ rather than choosing an arbitrary single exception to raise:: ... fixture.cleanUp() ... except MultipleExceptions: ... exc_info = sys.exc_info() - >>> print exc_info[1].args[0][0] - <type 'exceptions.ZeroDivisionError'> + >>> print (exc_info[1].args[0][0].__name__) + ZeroDivisionError Shared Dependencies +++++++++++++++++++ @@ -298,8 +298,8 @@ PopenFixture Pretend to run an external command rather than needing it to be present to run tests. - >>> from StringIO import StringIO - >>> fixture = fixtures.PopenFixture(lambda _:{'stdout': StringIO('foobar')}) + >>> from testtools.compat import BytesIO + >>> fixture = fixtures.PopenFixture(lambda _:{'stdout': BytesIO('foobar')}) PythonPackage +++++++++++++ diff --git a/lib/fixtures/_fixtures/pythonpackage.py b/lib/fixtures/_fixtures/pythonpackage.py index 58e3636..4fbd278 100644 --- a/lib/fixtures/_fixtures/pythonpackage.py +++ b/lib/fixtures/_fixtures/pythonpackage.py @@ -55,7 +55,7 @@ class PythonPackage(Fixture): os.mkdir(root) init_seen = not self.init for modulename, contents in self.modulelist: - stream = file(os.path.join(root, modulename), 'wb') + stream = open(os.path.join(root, modulename), 'wb') try: stream.write(contents) finally: @@ -63,4 +63,4 @@ class PythonPackage(Fixture): if modulename == '__init__.py': init_seen = True if not init_seen: - file(os.path.join(root, '__init__.py'), 'wb').close() + open(os.path.join(root, '__init__.py'), 'wb').close() diff --git a/lib/fixtures/fixture.py b/lib/fixtures/fixture.py index 14da061..04bcb5d 100644 --- a/lib/fixtures/fixture.py +++ b/lib/fixtures/fixture.py @@ -23,6 +23,7 @@ __all__ = [ import itertools import sys +from testtools.compat import reraise from testtools.helpers import try_import class MultipleExceptions(Exception): @@ -115,7 +116,7 @@ class Fixture(object): if result and raise_first: if 1 == len(result): error = result[0] - raise error[0], error[1], error[2] + reraise(error[0], error[1], error[2]) else: raise MultipleExceptions(*result) if not raise_first: @@ -199,7 +200,7 @@ class Fixture(object): # The child failed to come up, capture any details it has (copying # the content, it may go away anytime). if gather_details is not None: - gather_details(fixture, self) + gather_details(fixture.getDetails(), self._details) raise else: self.addCleanup(fixture.cleanUp) diff --git a/lib/fixtures/testcase.py b/lib/fixtures/testcase.py index 0a6bb61..6a84ddf 100644 --- a/lib/fixtures/testcase.py +++ b/lib/fixtures/testcase.py @@ -45,7 +45,7 @@ class TestWithFixtures(unittest.TestCase): except: if use_details: # Capture the details now, in case the fixture goes away. - gather_details(fixture, self) + gather_details(fixture.getDetails(), self.getDetails()) raise else: self.addCleanup(fixture.cleanUp) diff --git a/lib/fixtures/tests/_fixtures/test_popen.py b/lib/fixtures/tests/_fixtures/test_popen.py index 33d5e74..f1ab835 100644 --- a/lib/fixtures/tests/_fixtures/test_popen.py +++ b/lib/fixtures/tests/_fixtures/test_popen.py @@ -13,10 +13,13 @@ # license you chose for the specific language governing permissions and # limitations under that license. -import StringIO import subprocess import testtools +from testtools.compat import ( + _b, + BytesIO, + ) import fixtures from fixtures import PopenFixture, TestWithFixtures @@ -63,6 +66,6 @@ class TestFakeProcess(testtools.TestCase): self.assertEqual(0, proc.returncode) def test_communicate_with_out(self): - proc = FakeProcess({}, {'stdout': StringIO.StringIO('foo')}) - self.assertEqual(('foo', ''), proc.communicate()) + proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) + self.assertEqual((_b('foo'), ''), proc.communicate()) self.assertEqual(0, proc.returncode) diff --git a/lib/fixtures/tests/_fixtures/test_pythonpackage.py b/lib/fixtures/tests/_fixtures/test_pythonpackage.py index d7de5f5..b235b3d 100644 --- a/lib/fixtures/tests/_fixtures/test_pythonpackage.py +++ b/lib/fixtures/tests/_fixtures/test_pythonpackage.py @@ -16,6 +16,7 @@ import os.path import testtools +from testtools.compat import _b import fixtures from fixtures import PythonPackage, TempDir, TestWithFixtures @@ -32,18 +33,18 @@ class TestPythonPackage(testtools.TestCase, TestWithFixtures): fixture.cleanUp() def test_writes_package(self): - fixture = PythonPackage('foo', [('bar.py', 'woo')]) + fixture = PythonPackage('foo', [('bar.py', _b('woo'))]) fixture.setUp() try: - self.assertEqual('', file(os.path.join(fixture.base, 'foo', + self.assertEqual('', open(os.path.join(fixture.base, 'foo', '__init__.py')).read()) - self.assertEqual('woo', file(os.path.join(fixture.base, 'foo', + self.assertEqual('woo', open(os.path.join(fixture.base, 'foo', 'bar.py')).read()) finally: fixture.cleanUp() def test_no__init__(self): - fixture = PythonPackage('foo', [('bar.py', 'woo')], init=False) + fixture = PythonPackage('foo', [('bar.py', _b('woo'))], init=False) fixture.setUp() try: self.assertFalse(os.path.exists(os.path.join(fixture.base, 'foo', |