Skip to content

Commit 54be5db

Browse files
author
Mike Dirolf
committed
removing all support for mongo-qa tests
allows us to remove SON.from_xml - not deprecating this as it was used internally only AFAIK therefore eliminates driver dependency on elementtree
1 parent 9529271 commit 54be5db

File tree

10 files changed

+7
-492
lines changed

10 files changed

+7
-492
lines changed

Diff for: README.rst

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ C extension will not be built. This will negatively affect performance, but ever
2222

2323
Additional dependencies are:
2424

25-
- `ElementTree <http://effbot.org/zone/element-index.htm>`_ (this is included with Python >= 2.5)
2625
- (to generate documentation) sphinx_
2726
- (to auto-discover tests) `nose <http://somethingaboutorange.com/mrl/projects/nose/>`_
2827

Diff for: pymongo/errors.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class InvalidBSON(ValueError):
6161
"""Raised when trying to create a BSON object from invalid data.
6262
"""
6363

64+
6465
class InvalidStringData(ValueError):
6566
"""Raised when trying to encode a string containing non-UTF8 data.
6667
"""
@@ -71,11 +72,6 @@ class InvalidDocument(ValueError):
7172
"""
7273

7374

74-
class UnsupportedTag(ValueError):
75-
"""Raised when trying to parse an unsupported tag in an XML document.
76-
"""
77-
78-
7975
class InvalidId(ValueError):
8076
"""Raised when trying to create an ObjectId from invalid data.
8177
"""

Diff for: pymongo/son.py

+2-125
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
of keys is important. A SON object can be used just like a normal Python
1919
dictionary."""
2020

21-
import datetime
22-
import re
23-
import binascii
24-
import base64
25-
import types
26-
2721

2822
class SON(dict):
2923
"""SON data.
@@ -190,7 +184,6 @@ def __cmp__(self, other):
190184
def __len__(self):
191185
return len(self.keys())
192186

193-
# Thanks to Jeff Jenkins for the idea and original implementation
194187
def to_dict(self):
195188
"""Convert a SON document to a normal Python dictionary instance.
196189
@@ -199,129 +192,13 @@ def to_dict(self):
199192
"""
200193

201194
def transform_value(value):
202-
if isinstance(value, types.ListType):
195+
if isinstance(value, list):
203196
return [transform_value(v) for v in value]
204197
if isinstance(value, SON):
205198
value = dict(value)
206-
if isinstance(value, types.DictType):
199+
if isinstance(value, dict):
207200
for k, v in value.iteritems():
208201
value[k] = transform_value(v)
209202
return value
210203

211204
return transform_value(dict(self))
212-
213-
def from_xml(cls, xml):
214-
"""Create an instance of SON from an xml document.
215-
216-
This is really only used for testing, and is probably unnecessary.
217-
"""
218-
try:
219-
import xml.etree.ElementTree as ET
220-
except ImportError:
221-
import elementtree.ElementTree as ET
222-
223-
from code import Code
224-
from binary import Binary
225-
from objectid import ObjectId
226-
from dbref import DBRef
227-
from errors import UnsupportedTag
228-
229-
def pad(list, index):
230-
while index >= len(list):
231-
list.append(None)
232-
233-
def make_array(array):
234-
doc = make_doc(array)
235-
array = []
236-
for (key, value) in doc.items():
237-
index = int(key)
238-
pad(array, index)
239-
array[index] = value
240-
return array
241-
242-
def make_string(string):
243-
return string.text is not None and unicode(string.text) or u""
244-
245-
def make_code(code):
246-
return code.text is not None and Code(code.text) or Code("")
247-
248-
def make_binary(binary):
249-
if binary.text is not None:
250-
return Binary(base64.decodestring(binary.text))
251-
return Binary("")
252-
253-
def make_boolean(bool):
254-
return bool.text == "true"
255-
256-
def make_date(date):
257-
return datetime.datetime.utcfromtimestamp(float(date.text) /
258-
1000.0)
259-
260-
def make_ref(dbref):
261-
return DBRef(make_elem(dbref[0]), make_elem(dbref[1]))
262-
263-
def make_oid(oid):
264-
return ObjectId(binascii.unhexlify(oid.text))
265-
266-
def make_int(data):
267-
return int(data.text)
268-
269-
def make_null(null):
270-
return None
271-
272-
def make_number(number):
273-
return float(number.text)
274-
275-
def make_regex(regex):
276-
return re.compile(make_elem(regex[0]), make_elem(regex[1]))
277-
278-
def make_options(data):
279-
options = 0
280-
if not data.text:
281-
return options
282-
if "i" in data.text:
283-
options |= re.IGNORECASE
284-
if "l" in data.text:
285-
options |= re.LOCALE
286-
if "m" in data.text:
287-
options |= re.MULTILINE
288-
if "s" in data.text:
289-
options |= re.DOTALL
290-
if "u" in data.text:
291-
options |= re.UNICODE
292-
if "x" in data.text:
293-
options |= re.VERBOSE
294-
return options
295-
296-
def make_elem(elem):
297-
try:
298-
return {"array": make_array,
299-
"doc": make_doc,
300-
"string": make_string,
301-
"binary": make_binary,
302-
"boolean": make_boolean,
303-
"code": make_code,
304-
"date": make_date,
305-
"ref": make_ref,
306-
"ns": make_string,
307-
"oid": make_oid,
308-
"int": make_int,
309-
"null": make_null,
310-
"number": make_number,
311-
"pattern": make_string,
312-
"options": make_options,
313-
}[elem.tag](elem)
314-
except KeyError:
315-
raise UnsupportedTag("cannot parse tag: %s" % elem.tag)
316-
317-
def make_doc(doc):
318-
son = SON()
319-
for elem in doc:
320-
son[elem.attrib["name"]] = make_elem(elem)
321-
return son
322-
323-
tree = ET.XML(xml)
324-
doc = tree[1]
325-
326-
return make_doc(doc)
327-
from_xml = classmethod(from_xml)

Diff for: setup.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@
2121

2222
from pymongo import version
2323

24-
requirements = []
25-
try:
26-
import xml.etree.ElementTree
27-
except ImportError:
28-
try:
29-
import elementtree
30-
except ImportError:
31-
requirements.append("elementtree")
32-
3324
f = open("README.rst")
3425
try:
3526
try:
@@ -158,7 +149,7 @@ def build_extension(self, ext):
158149
url="http://github.com/mongodb/mongo-python-driver",
159150
keywords=["mongo", "mongodb", "pymongo", "gridfs"],
160151
packages=["pymongo", "gridfs"],
161-
install_requires=requirements,
152+
install_requires=[],
162153
features=features,
163154
license="Apache License, Version 2.0",
164155
test_suite="nose.collector",

Diff for: test/test_bson.py

+3-44
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,24 @@
1919
import unittest
2020
import datetime
2121
import re
22-
import glob
2322
import sys
24-
import types
25-
2623
try:
2724
import uuid
2825
should_test_uuid = True
2926
except ImportError:
3027
should_test_uuid = False
28+
sys.path[0:0] = [""]
3129

3230
from nose.plugins.skip import SkipTest
3331

34-
sys.path[0:0] = [""]
35-
3632
import qcheck
3733
from pymongo.binary import Binary
3834
from pymongo.code import Code
3935
from pymongo.objectid import ObjectId
4036
from pymongo.dbref import DBRef
4137
from pymongo.son import SON
4238
from pymongo.bson import BSON, is_valid, _to_dicts
43-
from pymongo.errors import UnsupportedTag, InvalidDocument, InvalidStringData
39+
from pymongo.errors import InvalidDocument, InvalidStringData
4440

4541

4642
class TestBSON(unittest.TestCase):
@@ -149,7 +145,7 @@ def helper(dict):
149145
helper({"test": u"hello"})
150146
self.assert_(isinstance(BSON.from_dict({"hello": "world"})
151147
.to_dict()["hello"],
152-
types.UnicodeType))
148+
unicode))
153149
helper({"mike": -10120})
154150
helper({"long": long(10)})
155151
helper({"really big long": 2147483648})
@@ -173,43 +169,6 @@ def from_then_to_dict(dict):
173169
qcheck.check_unittest(self, from_then_to_dict,
174170
qcheck.gen_mongo_dict(3))
175171

176-
def test_data_files(self):
177-
# TODO don't hardcode this, actually clone the repo
178-
data_files = "../mongo-qa/modules/bson_tests/tests/*/*.xson"
179-
generate = True
180-
181-
for file_name in glob.glob(data_files):
182-
f = open(file_name, "r")
183-
xml = f.read()
184-
f.close()
185-
186-
try:
187-
doc = SON.from_xml(xml)
188-
bson = BSON.from_dict(doc)
189-
except UnsupportedTag:
190-
print "skipped file %s: %s" % (file_name, sys.exc_info()[1])
191-
continue
192-
193-
try:
194-
f = open(file_name.replace(".xson", ".bson"), "rb")
195-
expected = f.read()
196-
f.close()
197-
198-
self.assertEqual(bson, expected,
199-
"(in %s) %r != %r" % (file_name, bson,
200-
expected))
201-
self.assertEqual(doc, bson.to_dict(),
202-
"(in %s) %r != %r" % (file_name, doc,
203-
bson.to_dict()))
204-
205-
except IOError:
206-
if generate:
207-
print "generating .bson for %s" % file_name
208-
209-
f = open(file_name.replace(".xson", ".bson"), "w")
210-
f.write(bson)
211-
f.close()
212-
213172
def test_bad_encode(self):
214173
self.assertRaises(InvalidStringData, BSON.from_dict,
215174
{"lalala": '\xf4\xe0\xf0\xe1\xc0 Color Touch'})

Diff for: test/test_son.py

-51
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
"""Tests for the son module."""
1616

1717
import unittest
18-
import datetime
19-
import re
2018
import sys
2119
sys.path[0:0] = [""]
2220

23-
from pymongo.objectid import ObjectId
24-
from pymongo.dbref import DBRef
2521
from pymongo.son import SON
26-
from pymongo.code import Code
2722

2823

2924
class TestSON(unittest.TestCase):
@@ -58,52 +53,6 @@ def test_to_dict(self):
5853
self.assertEqual(dict, c.to_dict()["blah"][0].__class__)
5954
self.assertEqual(dict, d.to_dict()["blah"]["foo"].__class__)
6055

61-
def test_from_xml(self):
62-
smorgasbord = """
63-
<twonk>
64-
<meta/>
65-
<doc>
66-
<oid name="_id">285a664923b5fcd8ec000000</oid>
67-
<int name="the_answer">42</int>
68-
<string name="b">foo</string>
69-
<boolean name="c">true</boolean>
70-
<number name="pi">3.14159265358979</number>
71-
<array name="an_array">
72-
<string name="0">x</string>
73-
<string name="1">y</string>
74-
<string name="2">z</string>
75-
<doc name="3">
76-
<string name="subobject">yup</string>
77-
</doc>
78-
</array>
79-
<date name="now">123144452057</date>
80-
<ref name="dbref">
81-
<ns>namespace</ns>
82-
<oid>ca5c67496c01d896f7010000</oid>
83-
</ref>
84-
<code name="$where">this is code</code>
85-
<null name="mynull"/>
86-
</doc>
87-
</twonk>
88-
"""
89-
self.assertEqual(SON.from_xml(smorgasbord),
90-
SON([(u"_id", ObjectId("\x28\x5A\x66\x49\x23\xB5\xFC"
91-
"\xD8\xEC\x00\x00\x00")),
92-
(u"the_answer", 42),
93-
(u"b", u"foo"),
94-
(u"c", True),
95-
(u"pi", 3.14159265358979),
96-
(u"an_array", [u"x", u"y", u"z",
97-
SON([(u"subobject", u"yup")])]),
98-
(u"now", datetime.datetime(1973, 11, 26, 6,
99-
47, 32, 57000)),
100-
(u"dbref",
101-
DBRef("namespace",
102-
ObjectId("\xCA\x5C\x67\x49\x6C\x01"
103-
"\xD8\x96\xF7\x01\x00\x00"))),
104-
(u"$where", Code("this is code")),
105-
(u"mynull", None),
106-
]))
10756

10857
if __name__ == "__main__":
10958
unittest.main()

Diff for: tools/README.rst

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
Tools
22
=====
33
This directory contains tools for use with the ``pymongo`` module.
4-
5-
validate and validate.py
6-
========================
7-
These scripts are used by 10gen's driver testing tools to verify the
8-
correctness of ``pymongo`` BSON module (``pymongo.bson``).
9-
10-
driver_tests.py
11-
===============
12-
This script is used by 10gen's
13-
`driver testing framework. <http://mongodb.onconfluence.com/display/DOCS/Mongo+Driver+Test+Framework>`_

0 commit comments

Comments
 (0)