Skip to content

Commit

Permalink
PYTHON-3527 + PYTHON-3528 Fix no-server tests (#1118)
Browse files Browse the repository at this point in the history
Fix TestCreateEntities when no server is running.
Fix no-server test_typeddict_find_notrequired.
  • Loading branch information
ShaneHarvey committed Nov 17, 2022
1 parent b290f7b commit cde9adf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
29 changes: 19 additions & 10 deletions test/test_create_entities.py
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}},
},
],
},
Expand All @@ -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()
6 changes: 5 additions & 1 deletion test/test_mypy.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit cde9adf

Please sign in to comment.