def test_deserialize_array(self): self.assertRaises(ValueError, lambda: serek.deserialize('a:2:{i:0;}')) self.assertRaises(ValueError, lambda: serek.deserialize('a:1:{i:0;i:2}')) self.assertRaises(ValueError, lambda: serek.deserialize('a:1:{i:0;i:2;};')) self.assertRaises(ValueError, lambda: serek.deserialize('a:2:{i:0;i:1;}')) self.assertRaises( ValueError, lambda: serek.deserialize('a:2:{i:0;i:1;i:1;i:2;i:3;i:4;}'))
def test_int(self): self._make_pair('i:123;', 123) self._make_pair('i:-123;', -123) self._make_pair('i:0;', 0) self.assertEquals(type(1), type(serek.deserialize('i:4312;'))) self.assertTrue(isinstance(serek.deserialize('i:4312;'), int)) self.assertRaises(ValueError, lambda: serek.deserialize('i:123;x')) # Garbage data at the end self.assertRaises(ValueError, lambda: serek.deserialize('ii:123;')) self.assertRaises(ValueError, lambda: serek.deserialize('i')) self.assertRaises(ValueError, lambda: serek.deserialize('i1')) self.assertRaises(ValueError, lambda: serek.deserialize('i:123')) self.assertRaises(ValueError, lambda: serek.deserialize('i:123{;')) self.assertRaises(ValueError, lambda: serek.deserialize('i123{;'))
def test_int(self): self._make_pair('i:123;', 123) self._make_pair('i:-123;', -123) self._make_pair('i:0;', 0) self.assertEquals(type(1), type(serek.deserialize('i:4312;'))) self.assertTrue(isinstance(serek.deserialize('i:4312;'), int)) self.assertRaises( ValueError, lambda: serek.deserialize('i:123;x')) # Garbage data at the end self.assertRaises(ValueError, lambda: serek.deserialize('ii:123;')) self.assertRaises(ValueError, lambda: serek.deserialize('i')) self.assertRaises(ValueError, lambda: serek.deserialize('i1')) self.assertRaises(ValueError, lambda: serek.deserialize('i:123')) self.assertRaises(ValueError, lambda: serek.deserialize('i:123{;')) self.assertRaises(ValueError, lambda: serek.deserialize('i123{;'))
def test_long(self): self._make_pair('i:12399999999999999999999999;', 12399999999999999999999999) self._make_pair('i:-12399999999999999999999999;', -12399999999999999999999999) self.assertEquals(type(199999999999999999999999), type(serek.deserialize('i:431299999999999999999999999;'))) self.assertTrue(serek.deserialize('i:431299999999999999999999999;'), long) self.assertRaises(ValueError, lambda: serek.deserialize('i:12399999999999999999999999;x')) # Garbage data at the end self.assertRaises(ValueError, lambda: serek.deserialize('ii:12399999999999999999999999;')) self.assertRaises(ValueError, lambda: serek.deserialize('i:12399999999999999999999999')) self.assertRaises(ValueError, lambda: serek.deserialize('i:12399999999999999999999999{;')) self.assertRaises(ValueError, lambda: serek.deserialize('i12399999999999999999999999{;'))
def test_string(self): self._make_pair('s:3:"abc";', 'abc') self._make_pair('s:0:"";', '') self._make_pair('s:1:""";', '"') self._make_pair('s:6:"ab"cd"";', 'ab"cd"') self.assertRaises(ValueError, lambda: serek.deserialize('s:3:"abc";x')) self.assertRaises(ValueError, lambda: serek.deserialize('s:5:"abc";')) self.assertRaises(ValueError, lambda: serek.deserialize('s:3:"abcde";')) self.assertRaises(ValueError, lambda: serek.deserialize('s3:"abc";')) self.assertRaises(ValueError, lambda: serek.deserialize('s:3"abc";')) self.assertRaises(ValueError, lambda: serek.deserialize('s:3:"abc"'))
def test_long(self): self._make_pair('i:12399999999999999999999999;', 12399999999999999999999999) self._make_pair('i:-12399999999999999999999999;', -12399999999999999999999999) self.assertEquals( type(199999999999999999999999), type(serek.deserialize('i:431299999999999999999999999;'))) self.assertTrue(serek.deserialize('i:431299999999999999999999999;'), long) self.assertRaises(ValueError, lambda: serek.deserialize( 'i:12399999999999999999999999;x')) # Garbage data at the end self.assertRaises( ValueError, lambda: serek.deserialize('ii:12399999999999999999999999;')) self.assertRaises( ValueError, lambda: serek.deserialize('i:12399999999999999999999999')) self.assertRaises( ValueError, lambda: serek.deserialize('i:12399999999999999999999999{;')) self.assertRaises( ValueError, lambda: serek.deserialize('i12399999999999999999999999{;'))
def test_general_parse(self): self.assertRaises(ValueError, lambda: serek.deserialize('#')) self.assertRaises(ValueError, lambda: serek.deserialize('#i:123;')) self.assertEquals(None, serek.deserialize(''))
def test_bool(self): self._make_pair('b:1;', True) self._make_pair('b:0;', False) self.assertRaises(ValueError, lambda: serek.deserialize('b:1;x')) self.assertRaises(ValueError, lambda: serek.deserialize('b:0;x')) self.assertRaises(ValueError, lambda: serek.deserialize('b1;')) self.assertRaises(ValueError, lambda: serek.deserialize('b:1')) self.assertRaises(ValueError, lambda: serek.deserialize('b:10')) self.assertRaises(ValueError, lambda: serek.deserialize('b:11')) self.assertRaises(ValueError, lambda: serek.deserialize('b11')) self.assertRaises(ValueError, lambda: serek.deserialize('b')) self.assertRaises(ValueError, lambda: serek.deserialize('b:2;')) self.assertRaises(ValueError, lambda: serek.deserialize('b:-1;')) self.assertRaises(ValueError, lambda: serek.deserialize('b:a;')) self.assertRaises(ValueError, lambda: serek.deserialize('b:2'))
def test_none(self): self._make_pair('N;', None) self.assertRaises(ValueError, lambda: serek.deserialize('N;x')) self.assertRaises(ValueError, lambda: serek.deserialize('N')) self.assertRaises(ValueError, lambda: serek.deserialize('Na;')) self.assertRaises(ValueError, lambda: serek.deserialize('NN'))
def _make_pair(self, dst, src): self.assertEquals(dst, serek.serialize(src)) self.assertEquals(src, serek.deserialize(dst))
def test_deserialize_array(self): self.assertRaises(ValueError, lambda: serek.deserialize('a:2:{i:0;}')) self.assertRaises(ValueError, lambda: serek.deserialize('a:1:{i:0;i:2}')) self.assertRaises(ValueError, lambda: serek.deserialize('a:1:{i:0;i:2;};')) self.assertRaises(ValueError, lambda: serek.deserialize('a:2:{i:0;i:1;}')) self.assertRaises(ValueError, lambda: serek.deserialize('a:2:{i:0;i:1;i:1;i:2;i:3;i:4;}'))