def test_message_contains_time(self): proc = Process('echo 123') proc._env = FakeEnv() proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] self.assertEqual(datetime.datetime(2012, 8, 11, 12, 42), msg.time)
def test_output_receives_start_with_pid(self): proc = Process('echo 123') proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] assert msg.type == 'start' assert msg.data == {'pid': 66}
def test_message_contains_time(self): proc = Process('echo 123') proc._env = FakeEnv() proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] assert msg.time == datetime.datetime(2012, 8, 11, 12, 42)
def test_output_receives_start_with_pid(self): proc = Process('echo 123') proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] self.assertEqual('start', msg.type) self.assertEqual({'pid': 66}, msg.data)
def test_output_receives_lines_invalid_utf8(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"\xfe\xff\n"]) return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) self.assertTrue(self.q.got_message(b"\xfe\xff\n"))
def test_output_receives_lines_invalid_utf8(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"\xfe\xff\n"]) return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) assert self.q.got_message(b"\xfe\xff\n")
def test_output_receives_lines(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"hello\n", b"world\n"]) return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) assert self.q.got_message(b"hello\n") assert self.q.got_message(b"world\n")
def test_output_does_not_receive_lines_when_quiet(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"hello\n", b"world\n"]) return popen proc = Process('echo 123', quiet=True) proc._child_ctor = _ctor proc.run(self.q) self.assertFalse(self.q.got_message(b"hello\n")) self.assertFalse(self.q.got_message(b"world\n"))
def test_output_receives_lines(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"hello\n", b"world\n"]) return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) self.assertTrue(self.q.got_message(b"hello\n")) self.assertTrue(self.q.got_message(b"world\n"))
def test_output_receives_stop_with_returncode(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.returncode = 42 return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) msg = self.q.find_message({'returncode': 42}) self.assertEqual('stop', msg.type)
def test_output_receives_stop_with_returncode(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.returncode = 42 return popen proc = Process('echo 123') proc._child_ctor = _ctor proc.run(self.q) msg = self.q.find_message({'returncode': 42}) assert msg.type == 'stop'
def test_output_does_not_receive_lines_when_quiet(self): def _ctor(*args, **kwargs): popen = FakePopen(*args, **kwargs) popen.stdout = FakeOutput(lines=[b"hello\n", b"world\n"]) return popen proc = Process('echo 123', quiet=True) proc._child_ctor = _ctor proc.run(self.q) assert not self.q.got_message(b"hello\n") assert not self.q.got_message(b"world\n")
def test_output_receives_stop(self): proc = Process('echo 123') proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[-1] self.assertEqual('stop', msg.type)
def test_output_receives_stop(self): proc = Process('echo 123') proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[-1] assert msg.type == 'stop'
def test_cwd_passed_along(self): proc = Process('echo 123', cwd='fake-dir') proc._child_ctor = FakePopen proc.run(self.q) assert proc._child.kwargs['cwd'] == 'fake-dir'
def test_message_contains_colour(self): proc = Process('echo 123', colour="red") proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] assert msg.colour == "red"
def test_message_contains_name(self): proc = Process('echo 123', name="barry") proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] self.assertEqual("barry", msg.name)
def test_message_contains_name(self): proc = Process('echo 123', name="barry") proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] assert msg.name == "barry"
def test_message_contains_colour(self): proc = Process('echo 123', colour="red") proc._child_ctor = FakePopen proc.run(self.q) msg = self.q.messages[0] self.assertEqual("red", msg.colour)