summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRune Halvorsen <runefh@gmail.com>2009-07-04 23:38:49 +0200
committerRune Halvorsen <runefh@gmail.com>2009-07-04 23:38:49 +0200
commit096055caab2814ff7f0a7698ea951f44fae5f785 (patch)
tree3bd0d00906c3a34130ccf88479ebb8968094704c
parent76fdaa5e7cf67284fedb235b4b353b3ec4a255b9 (diff)
downloadanyjson-096055caab2814ff7f0a7698ea951f44fae5f785.tar.gz
Added some tests
-rw-r--r--tests/test_implementations.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_implementations.py b/tests/test_implementations.py
new file mode 100644
index 0000000..e53e483
--- /dev/null
+++ b/tests/test_implementations.py
@@ -0,0 +1,43 @@
+from nose.tools import assert_raises
+import anyjson
+
+modnames = [e[0] for e in anyjson._modules]
+
+def test_default_serialization():
+ assert anyjson.serialize([1,2,3]).replace(" ", "") == "[1,2,3]"
+
+
+def test_default_deserialization():
+ assert anyjson.deserialize("[1,2,3]") == [1,2,3]
+
+
+def test_forced_serialization():
+ for name in modnames:
+ try:
+ anyjson.force_implementation(name)
+ except ImportError:
+ continue # module can't be tested, try next
+
+ assert anyjson.serialize([1,2,3]).replace(" ", "") == "[1,2,3]"
+
+
+def test_forced_deserialization():
+ for name in modnames:
+ try:
+ anyjson.force_implementation(name)
+ except ImportError:
+ continue # module can't be tested, try next
+
+ assert anyjson.deserialize("[1,2,3]") == [1,2,3]
+
+
+def test_exceptions():
+ for name in modnames:
+ try:
+ anyjson.force_implementation(name)
+ except ImportError:
+ continue # module can't be tested, try next
+
+ assert_raises(TypeError, anyjson.serialize, [object()])
+ assert_raises(ValueError, anyjson.deserialize, "[")
+