Пример #1
0
 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)
Пример #2
0
 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}
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
 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}
Пример #6
0
    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"))
Пример #7
0
    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")
Пример #8
0
    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")
Пример #9
0
    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"))
Пример #10
0
    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"))
Пример #11
0
    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)
Пример #12
0
    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'
Пример #13
0
    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")
Пример #14
0
 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)
Пример #15
0
 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'
Пример #16
0
 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'
Пример #17
0
 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"
Пример #18
0
 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)
Пример #19
0
 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"
Пример #20
0
 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)