def test_unregister(self): with self.assertRaises(SerializerNotInstalled): unregister("nonexisting") registry.encode("foo", serializer="pickle") unregister("pickle") with self.assertRaises(SerializerNotInstalled): registry.encode("foo", serializer="pickle") register_pickle()
def test_content_type_encoding(self): # Using the 'raw' serializer self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string, serializer="raw")[-1]) self.assertEqual(latin_string_as_utf8, registry.encode(latin_string, serializer="raw")[-1]) # And again w/o a specific serializer to check the # code where we force unicode objects into a string. self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string)[-1]) self.assertEqual(latin_string_as_utf8, registry.encode(latin_string)[-1])
def test_unregister(self): self.assertRaises(SerializerNotInstalled, unregister, "nonexisting") registry.encode("foo", serializer="pickle") unregister("pickle") self.assertRaises(SerializerNotInstalled, registry.encode, "foo", serializer="pickle") register_pickle()
def test_unregister(self): with self.assertRaises(SerializerNotInstalled): unregister('nonexisting') registry.encode('foo', serializer='pickle') unregister('pickle') with self.assertRaises(SerializerNotInstalled): registry.encode('foo', serializer='pickle') register_pickle()
def test_content_type_encoding(self): # Using the "raw" serializer self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string, serializer="raw")[-1]) self.assertEqual(latin_string_as_utf8, registry.encode(latin_string, serializer="raw")[-1]) # And again w/o a specific serializer to check the # code where we force unicode objects into a string. self.assertEqual(unicode_string_as_utf8, registry.encode(unicode_string)[-1]) self.assertEqual(latin_string_as_utf8, registry.encode(latin_string)[-1])
def test_json_encode(self): self.assertEquals( registry.decode(registry.encode(py_data, serializer="json")[-1], content_type='application/json', content_encoding='utf-8'), registry.decode(json_data, content_type='application/json', content_encoding='utf-8'))
def test_msgpack_decode(self): register_msgpack() decoded = registry.decode( registry.encode(msgpack_py_data, serializer='msgpack')[-1], content_type='application/x-msgpack', content_encoding='binary') self.assertEqual(msgpack_py_data, decoded)
def test_msgpack_decode(self): register_msgpack() decoded = registry.decode( registry.encode(msgpack_py_data, serializer='msgpack')[-1], content_type='application/x-msgpack', content_encoding='binary', ) self.assertEqual(msgpack_py_data, decoded)
def test_json_encode(self): self.assertEqual(registry.decode( registry.encode(py_data, serializer='json')[-1], content_type='application/json', content_encoding='utf-8'), registry.decode( json_data, content_type='application/json', content_encoding='utf-8'))
def test_yaml_encode(self): register_yaml() self.assertEqual( registry.decode(registry.encode(py_data, serializer="yaml")[-1], content_type='application/x-yaml', content_encoding='utf-8'), registry.decode(yaml_data, content_type='application/x-yaml', content_encoding='utf-8'))
def test_json_encode(self): self.assertEqual( registry.decode( registry.encode(py_data, serializer="json")[-1], content_type="application/json", content_encoding="utf-8", ), registry.decode(json_data, content_type="application/json", content_encoding="utf-8"), )
def test_yaml_encode(self): register_yaml() self.assertEqual( registry.decode( registry.encode(py_data, serializer="yaml")[-1], content_type="application/x-yaml", content_encoding="utf-8", ), registry.decode(yaml_data, content_type="application/x-yaml", content_encoding="utf-8"), )
def test_yaml_encode(self): register_yaml() self.assertEqual(registry.decode( registry.encode(py_data, serializer='yaml')[-1], content_type='application/x-yaml', content_encoding='utf-8'), registry.decode( yaml_data, content_type='application/x-yaml', content_encoding='utf-8'))
def test_msgpack_encode(self): register_msgpack() self.assertEquals(registry.decode( registry.encode(msgpack_py_data, serializer="msgpack")[-1], content_type='application/x-msgpack', content_encoding='binary'), registry.decode( msgpack_data, content_type='application/x-msgpack', content_encoding='binary'))
def test_yaml_encode(self): register_yaml() try: __import__("yaml") except ImportError: say("* PyYAML not installed, will not execute related tests.") raise SkipTest("PyYAML not installed") self.assertEquals( registry.decode(registry.encode(py_data, serializer="yaml")[-1], content_type='application/x-yaml', content_encoding='utf-8'), registry.decode(yaml_data, content_type='application/x-yaml', content_encoding='utf-8'))
def test_yaml_encode(self): try: import yaml except ImportError: say("* PyYAML not installed, will not execute related tests.") raise SkipTest("PyYAML not installed") self.assertEquals(registry.decode( registry.encode(py_data, serializer="yaml")[-1], content_type='application/x-yaml', content_encoding='utf-8'), registry.decode( yaml_data, content_type='application/x-yaml', content_encoding='utf-8'))
def test_msgpack_encode(self): try: import msgpack except ImportError: say("* msgpack-python not installed, will not execute " "related tests.") raise SkipTest("msgpack-python not installed") self.assertEquals(registry.decode( registry.encode(msgpack_py_data, serializer="msgpack")[-1], content_type='application/x-msgpack', content_encoding='binary'), registry.decode( msgpack_data, content_type='application/x-msgpack', content_encoding='binary'))
def test_msgpack_encode(self): register_msgpack() try: __import__("msgpack") except ImportError: say("* msgpack-python not installed, will not execute " "related tests.") raise SkipTest("msgpack-python not installed") self.assertEquals( registry.decode(registry.encode(msgpack_py_data, serializer="msgpack")[-1], content_type='application/x-msgpack', content_encoding='binary'), registry.decode(msgpack_data, content_type='application/x-msgpack', content_encoding='binary'))
def test_pickle_encode(self): self.assertEqual(pickle_data, registry.encode(py_data, serializer='pickle')[-1])
def test_pickle_encode(self): self.assertEqual(pickle.loads(pickle_data), pickle.loads(registry.encode(py_data, serializer="pickle")[-1]))
def test_pickle_encode(self): self.assertEquals(pickle_data, registry.encode(py_data, serializer="pickle")[-1])
def test_encode_missing(self): with self.assertRaises(SerializerNotInstalled): registry.encode('foo', serializer='nonexisting')
def test_pickle_encode(self): self.assertEqual( pickle.loads(pickle_data), pickle.loads(registry.encode(py_data, serializer='pickle')[-1]), )
def test_encode__no_serializer(self): ctyp, cenc, data = registry.encode(str_to_bytes('foo')) self.assertEqual(ctyp, 'application/data') self.assertEqual(cenc, 'binary')