Example #1
0
 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;}'))
Example #2
0
File: tests.py Project: mjr27/serek
 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{;'))
Example #3
0
 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{;'))
Example #4
0
File: tests.py Project: mjr27/serek
 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{;'))
Example #5
0
File: tests.py Project: mjr27/serek
 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"'))
Example #6
0
 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"'))
Example #7
0
 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{;'))
Example #8
0
 def test_general_parse(self):
     self.assertRaises(ValueError, lambda: serek.deserialize('#'))
     self.assertRaises(ValueError, lambda: serek.deserialize('#i:123;'))
     self.assertEquals(None, serek.deserialize(''))
Example #9
0
 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'))
Example #10
0
 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'))
Example #11
0
 def _make_pair(self, dst, src):
     self.assertEquals(dst, serek.serialize(src))
     self.assertEquals(src, serek.deserialize(dst))
Example #12
0
File: tests.py Project: mjr27/serek
 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;}'))
Example #13
0
File: tests.py Project: mjr27/serek
 def test_general_parse(self):
     self.assertRaises(ValueError, lambda: serek.deserialize('#'))
     self.assertRaises(ValueError, lambda: serek.deserialize('#i:123;'))
     self.assertEquals(None, serek.deserialize(''))
Example #14
0
File: tests.py Project: mjr27/serek
 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'))
Example #15
0
File: tests.py Project: mjr27/serek
 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'))
Example #16
0
File: tests.py Project: mjr27/serek
 def _make_pair(self, dst, src):
     self.assertEquals(dst, serek.serialize(src))
     self.assertEquals(src, serek.deserialize(dst))