def test_installs_restores_global(self): fixture = FakePopen() popen = subprocess.Popen fixture.setUp() try: self.assertEqual(subprocess.Popen, fixture) finally: fixture.cleanUp() self.assertEqual(subprocess.Popen, popen)
def test_inject_content_stdout(self): def get_info(args): return {'stdout': 'stdout'} fixture = self.useFixture(FakePopen(get_info)) proc = fixture(['foo']) self.assertEqual('stdout', proc.stdout)
def test_custom_returncode(self): def get_info(proc_args): return dict(returncode=1) proc = self.useFixture(FakePopen(get_info))(['foo']) self.assertEqual(None, proc.returncode) self.assertEqual(1, proc.wait()) self.assertEqual(1, proc.returncode)
def test___call___is_recorded(self): 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, stdin='in', stdout='out', stderr='err'), proc._args)
def test_handles_all_2_7_args(self): all_args = dict(args="args", bufsize="bufsize", executable="executable", stdin="stdin", stdout="stdout", stderr="stderr", preexec_fn="preexec_fn", close_fds="close_fds", shell="shell", cwd="cwd", env="env", universal_newlines="universal_newlines", startupinfo="startupinfo", creationflags="creationflags") def get_info(proc_args): self.assertEqual(all_args, proc_args) return {} fixture = self.useFixture(FakePopen(get_info)) fixture(**all_args)
def test_with_popen_custom(self): self.useFixture(FakePopen()) with subprocess.Popen(['ls -lh']) as proc: self.assertEqual(None, proc.returncode) self.assertEqual(['ls -lh'], proc.args)