Fix UUID tests with the pypi uuid module
This change skips tests of CSHARP_LEGACY when the third party uuid module from pypi is installed (or any other uuid module that doesn't support bytes_le).
This commit is contained in:
parent
c6b1c2854e
commit
d5ccdb48b0
@ -23,8 +23,10 @@ import warnings
|
||||
try:
|
||||
import uuid
|
||||
should_test_uuid = True
|
||||
uuid_has_bytes_le = hasattr(uuid.UUID, "bytes_le")
|
||||
except ImportError:
|
||||
should_test_uuid = False
|
||||
uuid_has_bytes_le = False
|
||||
|
||||
sys.path[0:0] = [""]
|
||||
|
||||
@ -41,7 +43,6 @@ from test import skip_restricted_localhost
|
||||
from test.test_client import get_client
|
||||
from test.utils import catch_warnings
|
||||
|
||||
|
||||
setUpModule = skip_restricted_localhost
|
||||
|
||||
|
||||
@ -142,9 +143,10 @@ class TestBinary(unittest.TestCase):
|
||||
for d in docs:
|
||||
self.assertNotEqual(d['newguid'], uuid.UUID(d['newguidstring']))
|
||||
|
||||
docs = bson.decode_all(data, SON, False, CSHARP_LEGACY)
|
||||
for d in docs:
|
||||
self.assertNotEqual(d['newguid'], uuid.UUID(d['newguidstring']))
|
||||
if uuid_has_bytes_le:
|
||||
docs = bson.decode_all(data, SON, False, CSHARP_LEGACY)
|
||||
for d in docs:
|
||||
self.assertNotEqual(d['newguid'], uuid.UUID(d['newguidstring']))
|
||||
|
||||
docs = bson.decode_all(data, SON, False, JAVA_LEGACY)
|
||||
for d in docs:
|
||||
@ -160,9 +162,10 @@ class TestBinary(unittest.TestCase):
|
||||
for doc in docs])
|
||||
self.assertNotEqual(data, encoded)
|
||||
|
||||
encoded = b('').join([bson.BSON.encode(doc, uuid_subtype=CSHARP_LEGACY)
|
||||
for doc in docs])
|
||||
self.assertNotEqual(data, encoded)
|
||||
if uuid_has_bytes_le:
|
||||
encoded = b('').join([bson.BSON.encode(doc, uuid_subtype=CSHARP_LEGACY)
|
||||
for doc in docs])
|
||||
self.assertNotEqual(data, encoded)
|
||||
|
||||
encoded = b('').join([bson.BSON.encode(doc, uuid_subtype=JAVA_LEGACY)
|
||||
for doc in docs])
|
||||
@ -187,6 +190,9 @@ class TestBinary(unittest.TestCase):
|
||||
def test_legacy_csharp_uuid(self):
|
||||
if not should_test_uuid:
|
||||
raise SkipTest("No uuid module")
|
||||
if not uuid_has_bytes_le:
|
||||
raise SkipTest(
|
||||
"The uuid module from pypi doesn't support bytes_le")
|
||||
|
||||
# Generated by the .net driver
|
||||
from_csharp = b('ZAAAABBfaWQAAAAAAAVuZXdndWlkABAAAAAD+MkoCd/Jy0iYJ7Vhl'
|
||||
|
||||
@ -2058,12 +2058,12 @@ class TestCollection(unittest.TestCase):
|
||||
if have_uuid:
|
||||
doc = {'_id': 2, 'uuid': uuid.uuid4()}
|
||||
uuid_sub_args = (name, [doc],
|
||||
True, True, {'w': 1}, True, 6)
|
||||
True, True, {'w': 1}, True, 5)
|
||||
do_insert(uuid_sub_args)
|
||||
coll = self.db.test
|
||||
self.assertNotEqual(doc, coll.find_one({'_id': 2}))
|
||||
coll = self.db.get_collection('test',
|
||||
CodecOptions(uuid_representation=6))
|
||||
CodecOptions(uuid_representation=5))
|
||||
self.assertEqual(doc, coll.find_one({'_id': 2}))
|
||||
|
||||
def test_message_backport_codec_options(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user