mirror of
https://github.com/kennethreitz-archive/anyjson.git
synced 2026-06-05 07:06:15 +00:00
Added dumps/loads as aliases for serializ/deserialize so it's in line with the stdlib json module
This commit is contained in:
@@ -123,3 +123,5 @@ else:
|
||||
|
||||
serialize = lambda value: implementation.serialize(value)
|
||||
deserialize = lambda value: implementation.deserialize(value)
|
||||
dumps = serialize
|
||||
loads = deserialize
|
||||
|
||||
@@ -5,10 +5,12 @@ modnames = [e[0] for e in anyjson._modules]
|
||||
|
||||
def test_default_serialization():
|
||||
assert anyjson.serialize([1,2,3]).replace(" ", "") == "[1,2,3]"
|
||||
assert anyjson.dumps([1,2,3]).replace(" ", "") == "[1,2,3]"
|
||||
|
||||
|
||||
def test_default_deserialization():
|
||||
assert anyjson.deserialize("[1,2,3]") == [1,2,3]
|
||||
assert anyjson.loads("[1,2,3]") == [1,2,3]
|
||||
|
||||
|
||||
def test_forced_serialization():
|
||||
@@ -19,6 +21,7 @@ def test_forced_serialization():
|
||||
continue # module can't be tested, try next
|
||||
|
||||
assert anyjson.serialize([1,2,3]).replace(" ", "") == "[1,2,3]"
|
||||
assert anyjson.dumps([1,2,3]).replace(" ", "") == "[1,2,3]"
|
||||
|
||||
|
||||
def test_forced_deserialization():
|
||||
@@ -29,6 +32,7 @@ def test_forced_deserialization():
|
||||
continue # module can't be tested, try next
|
||||
|
||||
assert anyjson.deserialize("[1,2,3]") == [1,2,3]
|
||||
assert anyjson.loads("[1,2,3]") == [1,2,3]
|
||||
|
||||
|
||||
def test_exceptions():
|
||||
@@ -39,5 +43,7 @@ def test_exceptions():
|
||||
continue # module can't be tested, try next
|
||||
|
||||
assert_raises(TypeError, anyjson.serialize, [object()])
|
||||
assert_raises(TypeError, anyjson.dumps, [object()])
|
||||
assert_raises(ValueError, anyjson.deserialize, "[")
|
||||
assert_raises(ValueError, anyjson.loads, "[")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user