def test_uses_repr_format(self): KEY = ['a', 1] VALUE = {'foo': {'bar': 3}, 'baz': None} ENCODED = ('%r\t%r' % (KEY, VALUE)).encode('ascii') self.assertEqual((KEY, VALUE), ReprProtocol().read(ENCODED)) self.assertEqual(ENCODED, ReprProtocol().write(KEY, VALUE))
def test_uses_repr_format(self): KEY = ['a', 1] VALUE = {'foo': {'bar': 3}, 'baz': None} ENCODED = '%r\t%r' % (KEY, VALUE) self.assertEqual((KEY, VALUE), ReprProtocol.read(ENCODED)) self.assertEqual(ENCODED, ReprProtocol.write(KEY, VALUE))
def test_protocol_instance(self): # see if we can use the repr protocol mr_job = MRJob() output = "0\t1\n['a', 'b']\tset(['c', 'd'])\n" mr_job.stdout = StringIO(output) self.assertEqual(mr_job.parse_output(ReprProtocol()), [(0, 1), (['a', 'b'], set(['c', 'd']))]) # verify that stdout is not cleared self.assertEqual(mr_job.stdout.getvalue(), output)
def test_parse_output_with_protocol_instance(self): # see if we can use the repr protocol mr_job = MRJob() output = b"0\t1\n['a', 'b']\tset(['c', 'd'])\n" mr_job.stdout = BytesIO(output) with logger_disabled('mrjob.job'): self.assertEqual(mr_job.parse_output(ReprProtocol()), [(0, 1), (['a', 'b'], set(['c', 'd']))]) # verify that stdout is not cleared self.assertEqual(mr_job.stdout.getvalue(), output)
def internal_protocol(self): return ReprProtocol()
def test_can_encode_point_but_not_decode(self): points_encoded = ReprProtocol.write(Point(2, 3), Point(1, 4)) self.assertCantDecode(ReprProtocol, points_encoded)
def test_can_encode_point_but_not_decode(self): points_encoded = ReprProtocol().write(Point(2, 3), Point(1, 4)) self.assertCantDecode(ReprProtocol(), points_encoded)
def test_bad_data(self): self.assertCantDecode(ReprProtocol(), b'{@#$@#!^&*$%^')
def test_round_trip_with_trailing_tab(self): for k, v in REPR_KEYS_AND_VALUES: self.assertRoundTripWithTrailingTabOK(ReprProtocol(), k, v)
def test_round_trip(self): for k, v in REPR_KEYS_AND_VALUES: self.assertRoundTripOK(ReprProtocol(), k, v)
def input_protocol(self): return ReprProtocol()