diff options
author | Free Ekanayaka <free@ekanayaka.io> | 2016-09-28 22:52:45 +0000 |
---|---|---|
committer | Free Ekanayaka <free@ekanayaka.io> | 2016-11-09 09:06:37 +0000 |
commit | 1b88db0c939fe161242d2a2092a20af00c011e77 (patch) | |
tree | 4711d96af1d600b255152b8eae5987b93cb50398 /fixtures/tests | |
parent | c2c28a1d478fe01003bef6a4f3fc000e3640aa69 (diff) | |
download | fixtures-git-1b88db0c939fe161242d2a2092a20af00c011e77.tar.gz |
Add missing APIs to FakeProcess, making it match Popen (LP #1373224)
Diffstat (limited to 'fixtures/tests')
-rw-r--r-- | fixtures/tests/_fixtures/test_popen.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/fixtures/tests/_fixtures/test_popen.py b/fixtures/tests/_fixtures/test_popen.py index 98b762f..6b629e1 100644 --- a/fixtures/tests/_fixtures/test_popen.py +++ b/fixtures/tests/_fixtures/test_popen.py @@ -76,6 +76,7 @@ class TestFakePopen(testtools.TestCase, TestWithFixtures): fixture = self.useFixture(FakePopen()) with subprocess.Popen(['ls -lh']) as proc: self.assertEqual(None, proc.returncode) + self.assertEqual(['ls -lh'], proc.args) class TestFakeProcess(testtools.TestCase): @@ -95,10 +96,41 @@ class TestFakeProcess(testtools.TestCase): self.assertEqual((_b('foo'), ''), proc.communicate()) self.assertEqual(0, proc.returncode) + def test_communicate_with_input(self): + proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) + self.assertEqual((_b('foo'), ''), proc.communicate(input=_b("bar"))) + + def test_communicate_with_input_and_stdin(self): + stdin = BytesIO() + proc = FakeProcess({}, {'stdin': stdin}) + proc.communicate(input=_b("hello")) + self.assertEqual(_b("hello"), stdin.getvalue()) + + def test_communicate_with_timeout(self): + proc = FakeProcess({}, {'stdout': BytesIO(_b('foo'))}) + self.assertEqual((_b('foo'), ''), proc.communicate(timeout=10)) + + def test_args(self): + proc = FakeProcess({"args": ["ls", "-lh"]}, {}) + proc.returncode = 45 + self.assertEqual(45, proc.wait()) + self.assertEqual(proc.args, ["ls", "-lh"]) + def test_kill(self): proc = FakeProcess({}, {}) self.assertIs(None, proc.kill()) + def test_poll(self): + proc = FakeProcess({}, {}) + self.assertIs(None, proc.poll()) + proc.communicate() + self.assertEqual(0, proc.poll()) + + def test_poll_with_returncode(self): + proc = FakeProcess({}, {}) + proc.communicate() + self.assertEqual(0, proc.poll()) + def test_wait_with_timeout_and_endtime(self): proc = FakeProcess({}, {}) self.assertEqual(0 , proc.wait(timeout=4, endtime=7)) |