summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kowalik <steve.kowalik@canonical.com>2014-08-18 16:11:56 +1000
committerSteve Kowalik <steve.kowalik@canonical.com>2014-08-18 16:11:56 +1000
commit1d17cdade0aa8be68b39e79af50f52d273a9fbf2 (patch)
tree799713e27271132557c194746a1e258ffa1c9ded
parent8727fe0376204056557267b13dc073fc571f67f6 (diff)
downloadfixtures-1d17cdade0aa8be68b39e79af50f52d273a9fbf2.tar.gz
* ``FakePopen`` now works under a context manager itself.
(Steve Kowalik, #1358085)
-rw-r--r--NEWS6
-rw-r--r--lib/fixtures/_fixtures/popen.py6
-rw-r--r--lib/fixtures/tests/_fixtures/test_popen.py5
3 files changed, 17 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 7143923..b4ec0cd 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,12 @@ fixtures release notes
NEXT
~~~~
+CHANGES
+-------
+
+* ``FakePopen`` now supports being called under a context manager (IE: with).
+ (Steve Kowalik)
+
0.3.14
~~~~~~
diff --git a/lib/fixtures/_fixtures/popen.py b/lib/fixtures/_fixtures/popen.py
index 708c5fd..80629fd 100644
--- a/lib/fixtures/_fixtures/popen.py
+++ b/lib/fixtures/_fixtures/popen.py
@@ -48,6 +48,12 @@ class FakeProcess(object):
err = ''
return out, err
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ self.wait()
+
def wait(self):
if self.returncode is None:
self.communicate()
diff --git a/lib/fixtures/tests/_fixtures/test_popen.py b/lib/fixtures/tests/_fixtures/test_popen.py
index dc9374c..8eb0174 100644
--- a/lib/fixtures/tests/_fixtures/test_popen.py
+++ b/lib/fixtures/tests/_fixtures/test_popen.py
@@ -72,6 +72,11 @@ class TestFakePopen(testtools.TestCase, TestWithFixtures):
self.assertEqual(1, proc.wait())
self.assertEqual(1, proc.returncode)
+ def test_with_popen_custom(self):
+ fixture = self.useFixture(FakePopen())
+ with subprocess.Popen(['ls -lh']) as proc:
+ self.assertEqual(None, proc.returncode)
+
class TestFakeProcess(testtools.TestCase):