diff --git a/son.py b/son.py index e7e437fb1..6217c94ff 100644 --- a/son.py +++ b/son.py @@ -3,7 +3,6 @@ Regular dictionaries can be used instead of SON objects, but not when the order of keys is important.""" -import unittest import datetime import re import binascii @@ -175,69 +174,3 @@ class SON(DictMixin): doc = tree[1] return make_doc(doc) - -class TestSON(unittest.TestCase): - def setUp(self): - pass - - def test_ordered_dict(self): - a = SON() - a["hello"] = "world" - a["mike"] = "awesome" - a["hello_"] = "mike" - self.assertEqual(a.items(), [("hello", "world"), ("mike", "awesome"), ("hello_", "mike")]) - - b = SON({"hello": "world"}) - self.assertEqual(b["hello"], "world") - self.assertRaises(KeyError, lambda: b["goodbye"]) - - def test_from_xml(self): - smorgasbord = """ - - - - 285a664923b5fcd8ec000000 - 42 - foo - true - 3.14159265358979 - - x - y - z - - yup - - - 123144452057 - - namespace - ca5c67496c01d896f7010000 - - - foobar - i - - this is code - - - -""" - self.assertEqual(SON.from_xml(smorgasbord), - SON([(u"_id", ObjectId("\x28\x5A\x66\x49\x23\xB5\xFC\xD8\xEC\x00\x00\x00")), - (u"the_answer", 42), - (u"b", u"foo"), - (u"c", True), - (u"pi", 3.14159265358979), - (u"an_array", [u"x", u"y", u"z", SON([(u"subobject", u"yup")])]), - (u"now", datetime.datetime(1973, 11, 26, 1, 47, 32, 57000)), - (u"dbref", - DBRef("namespace", - ObjectId("\xCA\x5C\x67\x49\x6C\x01\xD8\x96\xF7\x01\x00\x00"))), - (u"regex", re.compile(u"foobar", re.IGNORECASE)), - (u"$where", "this is code"), - (u"mynull", None), - ])) - -if __name__ == "__main__": - unittest.main() diff --git a/test/test_son.py b/test/test_son.py new file mode 100644 index 000000000..3959a343a --- /dev/null +++ b/test/test_son.py @@ -0,0 +1,75 @@ +"""Tests for the son module.""" + +import unittest +import datetime +import re + +from objectid import ObjectId +from dbref import DBRef +from son import SON + +class TestSON(unittest.TestCase): + def setUp(self): + pass + + def test_ordered_dict(self): + a = SON() + a["hello"] = "world" + a["mike"] = "awesome" + a["hello_"] = "mike" + self.assertEqual(a.items(), [("hello", "world"), ("mike", "awesome"), ("hello_", "mike")]) + + b = SON({"hello": "world"}) + self.assertEqual(b["hello"], "world") + self.assertRaises(KeyError, lambda: b["goodbye"]) + + def test_from_xml(self): + smorgasbord = """ + + + + 285a664923b5fcd8ec000000 + 42 + foo + true + 3.14159265358979 + + x + y + z + + yup + + + 123144452057 + + namespace + ca5c67496c01d896f7010000 + + + foobar + i + + this is code + + + +""" + self.assertEqual(SON.from_xml(smorgasbord), + SON([(u"_id", ObjectId("\x28\x5A\x66\x49\x23\xB5\xFC\xD8\xEC\x00\x00\x00")), + (u"the_answer", 42), + (u"b", u"foo"), + (u"c", True), + (u"pi", 3.14159265358979), + (u"an_array", [u"x", u"y", u"z", SON([(u"subobject", u"yup")])]), + (u"now", datetime.datetime(1973, 11, 26, 1, 47, 32, 57000)), + (u"dbref", + DBRef("namespace", + ObjectId("\xCA\x5C\x67\x49\x6C\x01\xD8\x96\xF7\x01\x00\x00"))), + (u"regex", re.compile(u"foobar", re.IGNORECASE)), + (u"$where", "this is code"), + (u"mynull", None), + ])) + +if __name__ == "__main__": + unittest.main()