From 866639484e32f45da5778ca1029a95bcf1bc10c0 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 17 Nov 2022 10:20:06 -0800 Subject: [PATCH 1/3] PYTHON-3528 Fix TestCreateEntities when no server is running --- test/test_create_entities.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/test_create_entities.py b/test/test_create_entities.py index ad0ac9347e..395bc5e476 100644 --- a/test/test_create_entities.py +++ b/test/test_create_entities.py @@ -11,11 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import sys import unittest + +sys.path[0:0] = [""] + +from test import IntegrationTest from test.unified_format import UnifiedSpecTestMixinV1 -class TestCreateEntities(unittest.TestCase): +class TestCreateEntities(IntegrationTest): def test_store_events_as_entities(self): self.scenario_runner = UnifiedSpecTestMixinV1() spec = { @@ -57,7 +62,7 @@ def test_store_all_others_as_entities(self): { "client": { "id": "client0", - "uriOptions": {"retryReads": True}, + "uriOptions": {"retryReads": True, "serverSelectionTimeoutMS": 500}, } }, {"database": {"id": "database0", "client": "client0", "databaseName": "dat"}}, @@ -91,7 +96,7 @@ def test_store_all_others_as_entities(self): { "name": "insertOne", "object": "collection0", - "arguments": {"document": {"_id": 1, "x": 44}}, + "arguments": {"document": {"_id": 2, "x": 44}}, }, ], }, @@ -101,15 +106,19 @@ def test_store_all_others_as_entities(self): ], } + self.client.dat.dat.delete_many({}) self.scenario_runner.TEST_SPEC = spec self.scenario_runner.setUp() self.scenario_runner.run_scenario(spec["tests"][0]) self.scenario_runner.entity_map["client0"].close() - final_entity_map = self.scenario_runner.entity_map - for entity in ["errors", "failures"]: - self.assertIn(entity, final_entity_map) - self.assertGreaterEqual(len(final_entity_map[entity]), 0) - self.assertEqual(type(final_entity_map[entity]), list) - for entity in ["successes", "iterations"]: - self.assertIn(entity, final_entity_map) - self.assertEqual(type(final_entity_map[entity]), int) + entity_map = self.scenario_runner.entity_map + self.assertEqual(len(entity_map["errors"]), 4) + for error in entity_map["errors"]: + self.assertEqual(error["type"], "DuplicateKeyError") + self.assertEqual(entity_map["failures"], []) + self.assertEqual(entity_map["successes"], 2) + self.assertEqual(entity_map["iterations"], 5) + + +if __name__ == "__main__": + unittest.main() From 019f4f5f5afaaf62ca25d1cb85134717168213c8 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 17 Nov 2022 10:27:37 -0800 Subject: [PATCH 2/3] PYTHON-3527 Fix no-server test_typeddict_find_notrequired --- test/test_mypy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_mypy.py b/test/test_mypy.py index 58e69853ca..3b29bbf20e 100644 --- a/test/test_mypy.py +++ b/test/test_mypy.py @@ -15,6 +15,7 @@ """Test that each file in mypy_fails/ actually fails mypy, and test some sample client code that uses PyMongo typings.""" import os +import sys import tempfile import unittest from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Union @@ -51,7 +52,9 @@ class ImplicitMovie(TypedDict): except ImportError: api = None # type: ignore[assignment] -from test import IntegrationTest +sys.path[0:0] = [""] + +from test import IntegrationTest, client_context from test.utils import rs_or_single_client from bson import CodecOptions, decode, decode_all, decode_file_iter, decode_iter, encode @@ -430,6 +433,7 @@ def test_typeddict_empty_document_type(self) -> None: # This should fail because _id is not included in our TypedDict definition. assert out["_id"] # type:ignore[typeddict-item] + @client_context.require_connection def test_typeddict_find_notrequired(self): if NotRequired is None or ImplicitMovie is None: raise unittest.SkipTest("Python 3.11+ is required to use NotRequired.") From da7f955ccd53ebd7e556948ad75bd8a59ca43f36 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Thu, 17 Nov 2022 10:36:21 -0800 Subject: [PATCH 3/3] PYTHON-3528 Remove unneeded serverSelectionTimeoutMS --- test/test_create_entities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_create_entities.py b/test/test_create_entities.py index 395bc5e476..1e46614da0 100644 --- a/test/test_create_entities.py +++ b/test/test_create_entities.py @@ -62,7 +62,7 @@ def test_store_all_others_as_entities(self): { "client": { "id": "client0", - "uriOptions": {"retryReads": True, "serverSelectionTimeoutMS": 500}, + "uriOptions": {"retryReads": True}, } }, {"database": {"id": "database0", "client": "client0", "databaseName": "dat"}},