PYTHON-3527 + PYTHON-3528 Fix no-server tests (#1118)
Fix TestCreateEntities when no server is running. Fix no-server test_typeddict_find_notrequired.
This commit is contained in:
parent
b290f7b1a1
commit
cde9adf6ab
@ -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 = {
|
||||
@ -91,7 +96,7 @@ class TestCreateEntities(unittest.TestCase):
|
||||
{
|
||||
"name": "insertOne",
|
||||
"object": "collection0",
|
||||
"arguments": {"document": {"_id": 1, "x": 44}},
|
||||
"arguments": {"document": {"_id": 2, "x": 44}},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -101,15 +106,19 @@ class TestCreateEntities(unittest.TestCase):
|
||||
],
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
@ -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 @@ try:
|
||||
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 @@ class TestDocumentType(unittest.TestCase):
|
||||
# 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.")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user