forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_bridge_encoder.py
More file actions
30 lines (22 loc) · 905 Bytes
/
test_bridge_encoder.py
File metadata and controls
30 lines (22 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json_encoder
import json
import unittest
import io
from object_registry import registry
class TestJSONEncoder(unittest.TestCase):
def setUp(self):
self.encoder = json_encoder.JsonEncoder()
def assert_encode_raw(self, obj, expected):
self.assertEqual(self.encoder.encode(obj),expected)
def assert_encode(self, obj, expected):
self.assertEqual(json.loads(self.encoder.encode(obj)),expected)
def test_encode_int(self):
self.assert_encode_raw(3,'3')
def test_encode_float(self):
self.assert_encode_raw(5.5,'5.5')
def test_add_mapping(self):
json_encoder.addMapping(type(self), lambda obj: 'Foooo!')
self.assert_encode(self,'Foooo!')
def test_encode_obj(self):
registry().register_with_id(self.encoder,'337')
self.assert_encode(self.encoder,{'__pyclass__': "JsonEncoder", "__pyid__": '337'})