Merge lp:~stevenk/python-fixtures/fakeopen-with into lp:~python-fixtures/python-fixtures/trunk

Proposed by Steve Kowalik
Status: Merged
Merged at revision: 77
Proposed branch: lp:~stevenk/python-fixtures/fakeopen-with
Merge into: lp:~python-fixtures/python-fixtures/trunk
Diff against target: 48 lines (+17/-0)
3 files modified
NEWS (+6/-0)
lib/fixtures/_fixtures/popen.py (+6/-0)
lib/fixtures/tests/_fixtures/test_popen.py (+5/-0)
To merge this branch: bzr merge lp:~stevenk/python-fixtures/fakeopen-with
Reviewer Review Type Date Requested Status
python-fixtures committers Pending
Review via email: mp+231149@code.launchpad.net

Description of the change

Add __enter__() and __exit__() methods to FakeProcess (which is returned by FakePopen) to allow FakePopen to be used within a context manager itself.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2013-08-16 03:04:37 +0000
+++ NEWS 2014-08-18 06:16:30 +0000
@@ -6,6 +6,12 @@
6NEXT6NEXT
7~~~~7~~~~
88
9CHANGES
10-------
11
12* ``FakePopen`` now supports being called under a context manager (IE: with).
13 (Steve Kowalik)
14
90.3.14150.3.14
10~~~~~~16~~~~~~
1117
1218
=== modified file 'lib/fixtures/_fixtures/popen.py'
--- lib/fixtures/_fixtures/popen.py 2013-08-16 03:03:08 +0000
+++ lib/fixtures/_fixtures/popen.py 2014-08-18 06:16:30 +0000
@@ -48,6 +48,12 @@
48 err = ''48 err = ''
49 return out, err49 return out, err
5050
51 def __enter__(self):
52 return self
53
54 def __exit__(self, exc_type, exc_value, traceback):
55 self.wait()
56
51 def wait(self):57 def wait(self):
52 if self.returncode is None:58 if self.returncode is None:
53 self.communicate()59 self.communicate()
5460
=== modified file 'lib/fixtures/tests/_fixtures/test_popen.py'
--- lib/fixtures/tests/_fixtures/test_popen.py 2013-08-16 03:03:08 +0000
+++ lib/fixtures/tests/_fixtures/test_popen.py 2014-08-18 06:16:30 +0000
@@ -72,6 +72,11 @@
72 self.assertEqual(1, proc.wait())72 self.assertEqual(1, proc.wait())
73 self.assertEqual(1, proc.returncode)73 self.assertEqual(1, proc.returncode)
7474
75 def test_with_popen_custom(self):
76 fixture = self.useFixture(FakePopen())
77 with subprocess.Popen(['ls -lh']) as proc:
78 self.assertEqual(None, proc.returncode)
79
7580
76class TestFakeProcess(testtools.TestCase):81class TestFakeProcess(testtools.TestCase):
7782

Subscribers

People subscribed via source and target branches