diff options
author | Jonathan Lange <jml@canonical.com> | 2011-07-27 00:07:48 +0100 |
---|---|---|
committer | Jonathan Lange <jml@canonical.com> | 2011-07-27 00:07:48 +0100 |
commit | 0ed40aab13cdfd6e74ffc1c2f6556d251811f84f (patch) | |
tree | 34e5343a7004fe46e36d41b919dc617c4bc951ab | |
parent | edc267a404864260d7e11d586bec472598fa21ca (diff) | |
download | fixtures-0ed40aab13cdfd6e74ffc1c2f6556d251811f84f.tar.gz |
Make the tests run with python 2 and 3
-rw-r--r-- | README | 16 | ||||
-rw-r--r-- | lib/fixtures/_fixtures/pythonpackage.py | 4 | ||||
-rw-r--r-- | lib/fixtures/fixture.py | 3 | ||||
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_popen.py | 9 | ||||
-rw-r--r-- | lib/fixtures/tests/_fixtures/test_pythonpackage.py | 9 |
5 files changed, 23 insertions, 18 deletions
@@ -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 9304602..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: 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', |