Commits

Jason R. Coombs committed 272802d

Added a couple simple tests

  • Participants
  • Parent commits b4de053

Comments (0)

Files changed (1)

File jaraco/json/test_encoding.py

+
+from jaraco.json.main import encode, decode
+
+class MyCollection(object):
+	"""
+	A list of items, specifically not subclassed from list to demonstrate
+	a custom collection.
+	"""
+	def __init__(self):
+		self.items = []
+
+	def append(self, item):
+		self.items.append(item)
+
+class MyItem(object):
+	def __init__(self, value):
+		self.value = value
+
+def test_encode_object():
+	coll = MyCollection()
+	coll.append(MyItem(63))
+	coll.append({'a': 'dict'})
+	coll.append((1,2,3))
+	
+	serialized = encode(coll)
+	return serialized
+
+def test_decode_serialized():
+	serialized = test_encode_object()
+	coll = decode(serialized)
+	assert len(coll.items) == 3
+	custom, d, t = coll.items
+	assert isinstance(custom, MyItem)
+	assert 'a' in d
+	assert t == range(1,4)
+	assert custom.value == 63