From d5ccdb48b0f4479d2ac3d4d4d0fa2ca7000ee82f Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Mon, 6 Mar 2017 12:40:54 -0800 Subject: [PATCH] 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). --- test/test_binary.py | 20 +++++++++++++------- test/test_collection.py | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test_binary.py b/test/test_binary.py index 86fc75963..500ff95c3 100644 --- a/test/test_binary.py +++ b/test/test_binary.py @@ -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' diff --git a/test/test_collection.py b/test/test_collection.py index 9ef3c2678..79e6c83db 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -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):