summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2011-11-25 17:42:25 +0000
committerJonathan Lange <jml@canonical.com>2011-11-25 17:42:25 +0000
commit707367c98f315d86cc325bb0b0155a1da8a4f408 (patch)
treee6f6ed7104bac5d085556d3da73b44c9850cad1c
parent3de22d0d614e31697f861861a93cbe5d14a8b935 (diff)
downloadfixtures-707367c98f315d86cc325bb0b0155a1da8a4f408.tar.gz
PopenFixture => FakePopen
-rw-r--r--NEWS8
-rw-r--r--README18
-rw-r--r--lib/fixtures/__init__.py5
-rw-r--r--lib/fixtures/_fixtures/__init__.py8
-rw-r--r--lib/fixtures/_fixtures/popen.py11
-rw-r--r--lib/fixtures/tests/_fixtures/test_popen.py13
6 files changed, 36 insertions, 27 deletions
diff --git a/NEWS b/NEWS
index a9fcbd0..aebd445 100644
--- a/NEWS
+++ b/NEWS
@@ -8,11 +8,11 @@ IN DEVELOPMENT
CHANGES:
-* EnvironmentVariableFixture and LoggerFixture renamed to EnvironmentVariable
- and FakeLogger. Both are still available under their old, deprecated names.
- (Jonathan Lange, #893539)
+* EnvironmentVariableFixture, LoggerFixture, PopenFixture renamed to
+ EnvironmentVariable, FakeLogger and FakePopen respectively. All are still
+ available under their old, deprecated names. (Jonathan Lange, #893539)
-* EnvironmentVariableFixture now upcalls via super().
+* EnvironmentVariable now upcalls via super().
(Jonathan Lange, #881120)
0.3.7
diff --git a/README b/README
index 8a88c1e..2c24db4 100644
--- a/README
+++ b/README
@@ -282,6 +282,15 @@ gets the output from logged messages, but they don't go to e.g. the console.
>>> fixture = fixtures.FakeLogger()
+FakePopen
++++++++++
+
+Pretend to run an external command rather than needing it to be present to run
+tests.
+
+ >>> from testtools.compat import BytesIO
+ >>> fixture = fixtures.FakePopen(lambda _:{'stdout': BytesIO('foobar')})
+
MonkeyPatch
+++++++++++
@@ -300,15 +309,6 @@ happens, if it isn't then it is added on setUp and removed on cleanUp.
>>> fixture = fixtures.PackagePathEntry('package/name', '/foo/bar')
-PopenFixture
-++++++++++++
-
-Pretend to run an external command rather than needing it to be present to run
-tests.
-
- >>> from testtools.compat import BytesIO
- >>> fixture = fixtures.PopenFixture(lambda _:{'stdout': BytesIO('foobar')})
-
PythonPackage
+++++++++++++
diff --git a/lib/fixtures/__init__.py b/lib/fixtures/__init__.py
index 6273984..eb9dfe5 100644
--- a/lib/fixtures/__init__.py
+++ b/lib/fixtures/__init__.py
@@ -1,6 +1,6 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
-# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>
+# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
@@ -42,6 +42,7 @@ __all__ = [
'EnvironmentVariable',
'EnvironmentVariableFixture',
'FakeLogger',
+ 'FakePopen',
'Fixture',
'FunctionFixture',
'LoggerFixture',
@@ -61,6 +62,7 @@ from fixtures._fixtures import (
EnvironmentVariable,
EnvironmentVariableFixture,
FakeLogger,
+ FakePopen,
LoggerFixture,
MonkeyPatch,
PackagePathEntry,
@@ -73,7 +75,6 @@ from fixtures.testcase import TestWithFixtures
def test_suite():
- import unittest
import fixtures.tests
return fixtures.tests.test_suite()
diff --git a/lib/fixtures/_fixtures/__init__.py b/lib/fixtures/_fixtures/__init__.py
index 9b4f0fe..6341d0d 100644
--- a/lib/fixtures/_fixtures/__init__.py
+++ b/lib/fixtures/_fixtures/__init__.py
@@ -1,6 +1,6 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
-# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>
+# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
@@ -20,6 +20,7 @@ __all__ = [
'EnvironmentVariable',
'EnvironmentVariableFixture',
'FakeLogger',
+ 'FakePopen',
'LoggerFixture',
'MonkeyPatch',
'PackagePathEntry',
@@ -39,7 +40,10 @@ from fixtures._fixtures.logger import (
LoggerFixture,
)
from fixtures._fixtures.monkeypatch import MonkeyPatch
-from fixtures._fixtures.popen import PopenFixture
+from fixtures._fixtures.popen import (
+ FakePopen,
+ PopenFixture,
+ )
from fixtures._fixtures.packagepath import PackagePathEntry
from fixtures._fixtures.pythonpackage import PythonPackage
from fixtures._fixtures.pythonpath import PythonPathEntry
diff --git a/lib/fixtures/_fixtures/popen.py b/lib/fixtures/_fixtures/popen.py
index 3dde1f6..6f13a4c 100644
--- a/lib/fixtures/_fixtures/popen.py
+++ b/lib/fixtures/_fixtures/popen.py
@@ -1,6 +1,6 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
-# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>
+# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
@@ -14,6 +14,7 @@
# limitations under that license.
__all__ = [
+ 'FakePopen',
'PopenFixture'
]
@@ -50,7 +51,7 @@ class FakeProcess(object):
return self.returncode
-class PopenFixture(Fixture):
+class FakePopen(Fixture):
"""Replace subprocess.Popen.
Primarily useful for testing, this fixture replaces subprocess.Popen with a
@@ -67,10 +68,11 @@ class PopenFixture(Fixture):
call, and should return a dict with any desired attributes.
e.g. return {'stdin': StringIO('foobar')}
"""
+ super(FakePopen, self).__init__()
self.get_info = get_info
def setUp(self):
- super(PopenFixture, self).setUp()
+ super(FakePopen, self).setUp()
self.addCleanup(setattr, subprocess, 'Popen', subprocess.Popen)
subprocess.Popen = self
self.procs = []
@@ -83,3 +85,6 @@ class PopenFixture(Fixture):
result = FakeProcess(proc_args, proc_info)
self.procs.append(result)
return result
+
+
+PopenFixture = FakePopen
diff --git a/lib/fixtures/tests/_fixtures/test_popen.py b/lib/fixtures/tests/_fixtures/test_popen.py
index f1ab835..59bef71 100644
--- a/lib/fixtures/tests/_fixtures/test_popen.py
+++ b/lib/fixtures/tests/_fixtures/test_popen.py
@@ -1,6 +1,6 @@
# fixtures: Fixtures with cleanups for testing and convenience.
#
-# Copyright (c) 2010, Robert Collins <robertc@robertcollins.net>
+# Copyright (c) 2010, 2011, Robert Collins <robertc@robertcollins.net>
#
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
# license at the users choice. A copy of both licenses are available in the
@@ -21,15 +21,14 @@ from testtools.compat import (
BytesIO,
)
-import fixtures
-from fixtures import PopenFixture, TestWithFixtures
+from fixtures import FakePopen, TestWithFixtures
from fixtures._fixtures.popen import FakeProcess
-class TestPopenFixture(testtools.TestCase, TestWithFixtures):
+class TestFakePopen(testtools.TestCase, TestWithFixtures):
def test_installs_restores_global(self):
- fixture = PopenFixture()
+ fixture = FakePopen()
popen = subprocess.Popen
fixture.setUp()
try:
@@ -39,7 +38,7 @@ class TestPopenFixture(testtools.TestCase, TestWithFixtures):
self.assertEqual(subprocess.Popen, popen)
def test___call___is_recorded(self):
- fixture = self.useFixture(PopenFixture())
+ fixture = self.useFixture(FakePopen())
proc = fixture(['foo', 'bar'], 1, None, 'in', 'out', 'err')
self.assertEqual(1, len(fixture.procs))
self.assertEqual(dict(args=['foo', 'bar'], bufsize=1, executable=None,
@@ -48,7 +47,7 @@ class TestPopenFixture(testtools.TestCase, TestWithFixtures):
def test_inject_content_stdout(self):
def get_info(args):
return {'stdout': 'stdout'}
- fixture = self.useFixture(PopenFixture(get_info))
+ fixture = self.useFixture(FakePopen(get_info))
proc = fixture(['foo'])
self.assertEqual('stdout', proc.stdout)