Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cde9adf

Browse files
PYTHON-3527 + PYTHON-3528 Fix no-server tests (#1118)
Fix TestCreateEntities when no server is running. Fix no-server test_typeddict_find_notrequired.
1 parent b290f7b commit cde9adf

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

‎test/test_create_entities.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
1415
import unittest
16+
17+
sys.path[0:0] = [""]
18+
19+
from test import IntegrationTest
1520
from test.unified_format import UnifiedSpecTestMixinV1
1621

1722

18-
class TestCreateEntities(unittest.TestCase):
23+
class TestCreateEntities(IntegrationTest):
1924
def test_store_events_as_entities(self):
2025
self.scenario_runner = UnifiedSpecTestMixinV1()
2126
spec = {
@@ -91,7 +96,7 @@ def test_store_all_others_as_entities(self):
9196
{
9297
"name": "insertOne",
9398
"object": "collection0",
94-
"arguments": {"document": {"_id": 1, "x": 44}},
99+
"arguments": {"document": {"_id": 2, "x": 44}},
95100
},
96101
],
97102
},
@@ -101,15 +106,19 @@ def test_store_all_others_as_entities(self):
101106
],
102107
}
103108

109+
self.client.dat.dat.delete_many({})
104110
self.scenario_runner.TEST_SPEC = spec
105111
self.scenario_runner.setUp()
106112
self.scenario_runner.run_scenario(spec["tests"][0])
107113
self.scenario_runner.entity_map["client0"].close()
108-
final_entity_map = self.scenario_runner.entity_map
109-
for entity in ["errors", "failures"]:
110-
self.assertIn(entity, final_entity_map)
111-
self.assertGreaterEqual(len(final_entity_map[entity]), 0)
112-
self.assertEqual(type(final_entity_map[entity]), list)
113-
for entity in ["successes", "iterations"]:
114-
self.assertIn(entity, final_entity_map)
115-
self.assertEqual(type(final_entity_map[entity]), int)
114+
entity_map = self.scenario_runner.entity_map
115+
self.assertEqual(len(entity_map["errors"]), 4)
116+
for error in entity_map["errors"]:
117+
self.assertEqual(error["type"], "DuplicateKeyError")
118+
self.assertEqual(entity_map["failures"], [])
119+
self.assertEqual(entity_map["successes"], 2)
120+
self.assertEqual(entity_map["iterations"], 5)
121+
122+
123+
if __name__ == "__main__":
124+
unittest.main()

‎test/test_mypy.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Test that each file in mypy_fails/ actually fails mypy, and test some
1616
sample client code that uses PyMongo typings."""
1717
import os
18+
import sys
1819
import tempfile
1920
import unittest
2021
from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, Union
@@ -51,7 +52,9 @@ class ImplicitMovie(TypedDict):
5152
except ImportError:
5253
api = None # type: ignore[assignment]
5354

54-
from test import IntegrationTest
55+
sys.path[0:0] = [""]
56+
57+
from test import IntegrationTest, client_context
5558
from test.utils import rs_or_single_client
5659

5760
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:
430433
# This should fail because _id is not included in our TypedDict definition.
431434
assert out["_id"] # type:ignore[typeddict-item]
432435

436+
@client_context.require_connection
433437
def test_typeddict_find_notrequired(self):
434438
if NotRequired is None or ImplicitMovie is None:
435439
raise unittest.SkipTest("Python 3.11+ is required to use NotRequired.")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /