Пример #1
0
 def test__propagates_errors_from_command(self):
     proto = JSONPerLineProtocol(callback=lambda obj: None)
     proto.connectionMade()
     reason = Failure(ProcessTerminated(1))
     proto.processEnded(reason)
     with ExpectedException(ProcessTerminated):
         yield proto.done
Пример #2
0
 def test__logs_only_full_lines_from_stderr(self):
     message = factory.make_name("message")
     callback = Mock()
     proto = JSONPerLineProtocol(callback=callback)
     proto.connectionMade()
     with TwistedLoggerFixture() as logger:
         proto.errReceived(message.encode("ascii"))
     self.assertThat(logger.output, Equals(""))
Пример #3
0
 def test__logs_non_json_output(self):
     callback = Mock()
     proto = JSONPerLineProtocol(callback=callback)
     proto.connectionMade()
     with TwistedLoggerFixture() as logger:
         proto.outReceived(b"{\n")
     self.assertThat(logger.output,
                     DocTestMatches("Failed to parse JSON: ..."))
Пример #4
0
 def test__logs_stderr_at_process_end(self):
     message = factory.make_name("message")
     callback = Mock()
     proto = JSONPerLineProtocol(callback=callback)
     proto.connectionMade()
     with TwistedLoggerFixture() as logger:
         proto.errReceived(message.encode("ascii"))
         self.assertThat(logger.output, Equals(""))
         proto.processEnded(Failure(ProcessDone(0)))
     self.assertThat(logger.output, Equals(message))
Пример #5
0
 def test__ignores_interspersed_zero_length_writes(self):
     callback = Mock()
     proto = JSONPerLineProtocol(callback=callback)
     proto.connectionMade()
     proto.outReceived(b"")
     self.expectThat(callback, MockCallsMatch())
     proto.outReceived(b"{}\n")
     self.expectThat(callback, MockCallsMatch(call([{}])))
     proto.outReceived(b"")
     self.expectThat(callback, MockCallsMatch(call([{}])))
     proto.outReceived(b"{}\n")
     self.expectThat(callback, MockCallsMatch(call([{}]), call([{}])))
Пример #6
0
 def test__parses_only_full_lines(self):
     callback = Mock()
     proto = JSONPerLineProtocol(callback=callback)
     proto.connectionMade()
     # Send an empty JSON dictionary using 3 separate writes.
     proto.outReceived(b"{")
     # No callback yet...
     self.expectThat(callback, MockCallsMatch())
     proto.outReceived(b"}")
     # Still no callback...
     self.expectThat(callback, MockCallsMatch())
     proto.outReceived(b"\n")
     # After a newline, we expect the JSON to be parsed and the callback
     # to receive an empty Python dictionary (which corresponds to the JSON
     # that was sent.)
     self.expectThat(callback, MockCallsMatch(call([{}])))