move son tests to test directory
This commit is contained in:
parent
91ed02bf5e
commit
55886c9d81
67
son.py
67
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 = """
|
||||
<twonk>
|
||||
<meta/>
|
||||
<doc>
|
||||
<oid name="_id">285a664923b5fcd8ec000000</oid>
|
||||
<int name="the_answer">42</int>
|
||||
<string name="b">foo</string>
|
||||
<boolean name="c">true</boolean>
|
||||
<number name="pi">3.14159265358979</number>
|
||||
<array name="an_array">
|
||||
<string name="0">x</string>
|
||||
<string name="1">y</string>
|
||||
<string name="2">z</string>
|
||||
<doc name="3">
|
||||
<string name="subobject">yup</string>
|
||||
</doc>
|
||||
</array>
|
||||
<date name="now">123144452057</date>
|
||||
<ref name="dbref">
|
||||
<ns>namespace</ns>
|
||||
<oid>ca5c67496c01d896f7010000</oid>
|
||||
</ref>
|
||||
<regex name="regex">
|
||||
<pattern>foobar</pattern>
|
||||
<options>i</options>
|
||||
</regex>
|
||||
<code name="$where">this is code</code>
|
||||
<null name="mynull"/>
|
||||
</doc>
|
||||
</twonk>
|
||||
"""
|
||||
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()
|
||||
|
||||
75
test/test_son.py
Normal file
75
test/test_son.py
Normal file
@ -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 = """
|
||||
<twonk>
|
||||
<meta/>
|
||||
<doc>
|
||||
<oid name="_id">285a664923b5fcd8ec000000</oid>
|
||||
<int name="the_answer">42</int>
|
||||
<string name="b">foo</string>
|
||||
<boolean name="c">true</boolean>
|
||||
<number name="pi">3.14159265358979</number>
|
||||
<array name="an_array">
|
||||
<string name="0">x</string>
|
||||
<string name="1">y</string>
|
||||
<string name="2">z</string>
|
||||
<doc name="3">
|
||||
<string name="subobject">yup</string>
|
||||
</doc>
|
||||
</array>
|
||||
<date name="now">123144452057</date>
|
||||
<ref name="dbref">
|
||||
<ns>namespace</ns>
|
||||
<oid>ca5c67496c01d896f7010000</oid>
|
||||
</ref>
|
||||
<regex name="regex">
|
||||
<pattern>foobar</pattern>
|
||||
<options>i</options>
|
||||
</regex>
|
||||
<code name="$where">this is code</code>
|
||||
<null name="mynull"/>
|
||||
</doc>
|
||||
</twonk>
|
||||
"""
|
||||
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()
|
||||
Loading…
Reference in New Issue
Block a user