19
19
import sys
20
20
import uuid
21
21
22
- sys .path .insert (0 , "" )
23
-
24
- if sys .version_info [0 ] == 2 :
25
- from StringIO import StringIO
26
- else :
27
- from io import StringIO
28
-
29
- if sys .version_info [:2 ] == (2 , 6 ):
30
- import unittest2 as unittest
31
- else :
32
- import unittest
33
-
34
22
import bson
35
23
from bson import json_util , EPOCH_AWARE
36
24
from bson .binary import Binary , MD5_SUBTYPE , USER_DEFINED_SUBTYPE
46
34
from bson .timestamp import Timestamp
47
35
from bson .tz_util import utc
48
36
37
+ sys .path .insert (0 , "" )
38
+
49
39
import bsonjs
50
40
41
+ from test import StringIO , unittest
42
+
51
43
52
44
def to_object (bson_bytes ):
53
45
"""Return deserialized object from BSON bytes"""
@@ -80,8 +72,11 @@ def round_trip(self, doc):
80
72
bson_bytes = to_bson (doc )
81
73
self .assertEqual (bson_bytes , bsonjs .loads (bsonjs .dumps (bson_bytes )))
82
74
# Check compatibility between bsonjs and json_util
83
- self .assertEqual (doc , json_util .loads (bsonjs .dumps (bson_bytes )))
84
- self .assertEqual (bson_bytes , bsonjs .loads (json_util .dumps (doc )))
75
+ self .assertEqual (doc , json_util .loads (
76
+ bsonjs .dumps (bson_bytes ),
77
+ json_options = json_util .STRICT_JSON_OPTIONS ))
78
+ self .assertEqual (bson_bytes , bsonjs .loads (json_util .dumps (
79
+ doc , json_options = json_util .STRICT_JSON_OPTIONS )))
85
80
86
81
def test_basic (self ):
87
82
self .round_trip ({"hello" : "world" })
@@ -173,7 +168,6 @@ def test_timestamp(self):
173
168
rtdct = bsonjs_loads (res )
174
169
self .assertEqual (dct , rtdct )
175
170
176
- @unittest .skip ("PYTHON-1103" )
177
171
def test_uuid (self ):
178
172
self .round_trip ({"uuid" :
179
173
uuid .UUID ("f47ac10b-58cc-4372-a567-0e02b2c3d479" )})
@@ -203,15 +197,15 @@ def test_binary(self):
203
197
self .assertRaises (ValueError , bsonjs .loads ,
204
198
'{"a": {"$binary": "invalid", "$type": "80"}}' )
205
199
206
- @unittest .skip ("CDRIVER-1335" )
207
200
def test_code (self ):
208
201
self .round_trip ({"code" : Code ("function x() { return 1; }" )})
209
202
code = {"code" : Code ("return z" , z = 2 )}
210
203
self .round_trip (code )
211
204
212
205
# Check order.
213
- self .assertEqual ('{"$code": "return z", "$scope": {"z": 2}}' ,
214
- bsonjs_dumps (code ))
206
+ self .assertEqual (
207
+ '{ "code" : { "$code" : "return z", "$scope" : { "z" : 2 } } }' ,
208
+ bsonjs_dumps (code ))
215
209
216
210
def test_undefined (self ):
217
211
json_str = '{"name": {"$undefined": true}}'
@@ -229,14 +223,12 @@ def test_numberlong(self):
229
223
self .assertRaises (ValueError , bsonjs .loads ,
230
224
'{"a": {"$numberLong": "not-a-number"}}' )
231
225
232
- @unittest .skip ("CDRIVER-1366" )
233
226
def test_load_mongodb_extended_type_at_top_level (self ):
234
227
self .assertRaises (ValueError , bsonjs .loads ,
235
228
'{"$numberLong": "42"}' )
236
229
self .assertRaises (ValueError , bsonjs .loads ,
237
230
'{"$numberLong": "42", "a": 1}' )
238
- self .assertRaises (ValueError , bsonjs .loads ,
239
- '{"a": 1, "$numberLong": "42"}' )
231
+ _ = bsonjs .loads ('{"a": 1, "$numberLong": "42"}' )
240
232
241
233
def test_dumps_multiple_bson_documents (self ):
242
234
json_str = '{ "test" : "me" }'
0 commit comments