Beispiel #1
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: ..."))
Beispiel #2
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([{}])))
Beispiel #3
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([{}])))