def test_reading_junk(self):
     # Junk lines (lines with no JSON-encoded message) are ignored.
     log = """\
         this is junk
         and so is this
         me too!""".split('\n')
     self.assertEqual([], list(read_frames(log)))
Esempio n. 2
0
 def test_reading_junk(self):
     # Junk lines (lines with no JSON-encoded message) are ignored.
     log = """\
         this is junk
         and so is this
         me too!""".split('\n')
     self.assertEqual([], list(read_frames(log)))
Esempio n. 3
0
 def test_result_is_iterator(self):
     # The object returned from read_frames() is an iterator.  This is so
     # we can consume it incrementally without having to keep up with how
     # far we have progressed along the log.
     frames = read_frames('')
     # We test this by asserting that the frames object is its own
     # iterator.
     self.assertEqual(frames, iter(frames))
 def test_result_is_iterator(self):
     # The object returned from read_frames() is an iterator.  This is so
     # we can consume it incrementally without having to keep up with how
     # far we have progressed along the log.
     frames = read_frames('')
     # We test this by asserting that the frames object is its own
     # iterator.
     self.assertEqual(frames, iter(frames))
Esempio n. 5
0
 def test_included_direction_is_used(self):
     # If the log contains direction info (whether or not the message was
     # sent from the client and to the server or vice versa) that info will
     # be used.
     log = """\
         junk
         to mars
         {"foo": 1}
         junk
         to venus
         {"foo": 2}
         junk""".split('\n')
     self.assertEqual([
         Frame(message={u'foo': 1}, direction='to mars'),
         Frame(message={u'foo': 2}, direction='to venus')
     ], list(read_frames(log)))
Esempio n. 6
0
 def test_missing_direction_is_infered(self):
     # If the log does not contain direction info, the directionality of
     # each message will deduced from the message's contents.
     log = """\
         junk
         {"foo": 1, "request_id": 1}
         junk
         {"foo": 2}
         junk""".split('\n')
     self.assertEqual([
         Frame(message={
             u'foo': 1,
             u'request_id': 1
         }, direction='to server'),
         Frame(message={u'foo': 2}, direction='to client')
     ], list(read_frames(log)))
Esempio n. 7
0
 def test_reading_frames(self):
     # Frames interspersed with junk are read correctly.
     log = """\
         this is junk
         {"foo": 1, "bar": 2, "request_id": 42}
         more junk
         {"response": "hi", "request_id": 42}
         the last junk""".split('\n')
     self.assertEqual(
         [Frame(
             message={u'foo': 1, u'bar': 2, u'request_id': 42},
             direction='to server'),
          Frame(
             message={u'response': u'hi', u'request_id': 42},
             direction='to client')],
         list(read_frames(log)))
 def test_reading_frames(self):
     # Frames interspersed with junk are read correctly.
     log = """\
         this is junk
         {"foo": 1, "bar": 2, "request_id": 42}
         more junk
         {"response": "hi", "request_id": 42}
         the last junk""".split('\n')
     self.assertEqual(
         [Frame(
             message={u'foo': 1, u'bar': 2, u'request_id': 42},
             direction='to server'),
          Frame(
             message={u'response': u'hi', u'request_id': 42},
             direction='to client')],
         list(read_frames(log)))
 def test_missing_direction_is_infered(self):
     # If the log does not contain direction info, the directionality of
     # each message will deduced from the message's contents.
     log = """\
         junk
         {"foo": 1, "request_id": 1}
         junk
         {"foo": 2}
         junk""".split('\n')
     self.assertEqual(
         [Frame(
             message={u'foo': 1, u'request_id': 1},
             direction='to server'),
          Frame(
             message={u'foo': 2},
             direction='to client')],
         list(read_frames(log)))
Esempio n. 10
0
 def test_included_direction_is_used(self):
     # If the log contains direction info (whether or not the message was
     # sent from the client and to the server or vice versa) that info will
     # be used.
     log = """\
         junk
         to mars
         {"foo": 1}
         junk
         to venus
         {"foo": 2}
         junk""".split('\n')
     self.assertEqual(
         [Frame(
             message={u'foo': 1},
             direction='to mars'),
          Frame(
             message={u'foo': 2},
             direction='to venus')],
         list(read_frames(log)))