Skip to content

Commit ba8a139

Browse files
authored
PYTHON-4651: Migrate test_client_context.py to async (mongodb#1819)
1 parent 3840d9d commit ba8a139

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

.github/workflows/test-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ jobs:
209209
ls
210210
which python
211211
pip install -e ".[test]"
212-
PYMONGO_MUST_CONNECT=1 pytest -v test/test_client_context.py
212+
PYMONGO_MUST_CONNECT=1 pytest -v -k client_context

test/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,11 +947,11 @@ def tearDownClass(cls):
947947

948948
@classmethod
949949
def _setup_class(cls):
950-
cls._setup_class()
950+
pass
951951

952952
@classmethod
953953
def _tearDown_class(cls):
954-
cls._tearDown_class()
954+
pass
955955

956956

957957
class IntegrationTest(PyMongoTestCase):

test/asynchronous/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,11 +949,11 @@ def tearDownClass(cls):
949949

950950
@classmethod
951951
async def _setup_class(cls):
952-
await cls._setup_class()
952+
pass
953953

954954
@classmethod
955955
async def _tearDown_class(cls):
956-
await cls._tearDown_class()
956+
pass
957957

958958

959959
class AsyncIntegrationTest(AsyncPyMongoTestCase):
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2018-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
import os
17+
import sys
18+
19+
sys.path[0:0] = [""]
20+
21+
from test.asynchronous import AsyncUnitTest, SkipTest, async_client_context, unittest
22+
23+
_IS_SYNC = False
24+
25+
26+
class TestAsyncClientContext(AsyncUnitTest):
27+
def test_must_connect(self):
28+
if "PYMONGO_MUST_CONNECT" not in os.environ:
29+
raise SkipTest("PYMONGO_MUST_CONNECT is not set")
30+
31+
self.assertTrue(
32+
async_client_context.connected,
33+
"client context must be connected when "
34+
"PYMONGO_MUST_CONNECT is set. Failed attempts:\n{}".format(
35+
async_client_context.connection_attempt_info()
36+
),
37+
)
38+
39+
def test_serverless(self):
40+
if "TEST_SERVERLESS" not in os.environ:
41+
raise SkipTest("TEST_SERVERLESS is not set")
42+
43+
self.assertTrue(
44+
async_client_context.connected and async_client_context.serverless,
45+
"client context must be connected to serverless when "
46+
f"TEST_SERVERLESS is set. Failed attempts:\n{async_client_context.connection_attempt_info()}",
47+
)
48+
49+
def test_enableTestCommands_is_disabled(self):
50+
if "PYMONGO_DISABLE_TEST_COMMANDS" not in os.environ:
51+
raise SkipTest("PYMONGO_DISABLE_TEST_COMMANDS is not set")
52+
53+
self.assertFalse(
54+
async_client_context.test_commands_enabled,
55+
"enableTestCommands must be disabled when PYMONGO_DISABLE_TEST_COMMANDS is set.",
56+
)
57+
58+
def test_setdefaultencoding_worked(self):
59+
if "SETDEFAULTENCODING" not in os.environ:
60+
raise SkipTest("SETDEFAULTENCODING is not set")
61+
62+
self.assertEqual(sys.getdefaultencoding(), os.environ["SETDEFAULTENCODING"])
63+
64+
65+
if __name__ == "__main__":
66+
unittest.main()

test/test_client_context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
sys.path[0:0] = [""]
2020

21-
from test import SkipTest, client_context, unittest
21+
from test import SkipTest, UnitTest, client_context, unittest
2222

23+
_IS_SYNC = True
2324

24-
class TestClientContext(unittest.TestCase):
25+
26+
class TestClientContext(UnitTest):
2527
def test_must_connect(self):
2628
if "PYMONGO_MUST_CONNECT" not in os.environ:
2729
raise SkipTest("PYMONGO_MUST_CONNECT is not set")

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"test_logger.py",
164164
"test_session.py",
165165
"test_transactions.py",
166+
"test_client_context.py",
166167
]
167168

168169
sync_test_files = [

0 commit comments

Comments
 (0)