def test_nested_sequence_serialization(self): '''Test serialization of a nested sequence''' expected = ''.join( chr(i) for i in itertools.chain( (5, 0, 0, 0), # Sequence (3, 0, 0, 0), # 3 steps (2, 0, 0, 0), # Delete (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), # Sequence (2, 0, 0, 0), # 2 steps (2, 0, 0, 0), # Delete (3, 0, 0, 0), bytes_('key'), (1, 0, 0, 0), # Set (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), bytes_('value'), (5, 0, 0, 0), # Sequence (0, 0, 0, 0), # 0 steps )) received = ''.join( sequence.Sequence([ sequence.Delete('key'), sequence.Sequence( [sequence.Delete('key'), sequence.Set('key', 'value')]), sequence.Sequence([]) ]).serialize()) self.assertEquals(expected, received)
def test_step(self): '''Test step checks''' self._run_test( protocol.STEP, (sequence.Set('key', 'value'), True), (sequence.Delete('key'), True), (sequence.Sequence([]), True), (sequence.Sequence([sequence.Set('key', 'value')]), True), (sequence.Sequence( [sequence.Set('key', 'value'), sequence.Delete('key')]), True), (sequence.Sequence([ sequence.Set('key', 'value'), sequence.Sequence( [sequence.Set('key', 'value'), sequence.Delete('key')]) ]), True), (object(), False), (None, False), (sequence.Sequence( [sequence.Delete('key'), object()]), False))
def test_delete_step_serialization(self): '''Test serialization of 'delete' steps''' expected = ''.join( chr(i) for i in itertools.chain( (2, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), )) received = ''.join(sequence.Delete('key').serialize()) self.assertEquals(expected, received)
def test_sequence_serialization(self): '''Test serialization of a sequence''' expected = ''.join( chr(i) for i in itertools.chain( (5, 0, 0, 0), (2, 0, 0, 0), (1, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), bytes_('value'), (2, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), )) received = ''.join( sequence.Sequence([ sequence.Set('key', 'value'), sequence.Delete('key'), ]).serialize()) self.assertEquals(expected, received)
def convert_delete(step): return sequence.Delete(step._key)