Skip to content

Commit 7108c21

Browse files
authored
PYTHON-5108 - Convert test.test_transactions_unified to async (#2128)
1 parent 02d6cc9 commit 7108c21

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2021-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+
15+
"""Test the Transactions unified spec tests."""
16+
from __future__ import annotations
17+
18+
import os
19+
import sys
20+
from pathlib import Path
21+
22+
sys.path[0:0] = [""]
23+
24+
from test import client_context, unittest
25+
from test.asynchronous.unified_format import generate_test_classes
26+
27+
_IS_SYNC = False
28+
29+
30+
@client_context.require_no_mmap
31+
def setUpModule():
32+
pass
33+
34+
35+
# Location of JSON test specifications.
36+
if _IS_SYNC:
37+
TEST_PATH = os.path.join(Path(__file__).resolve().parent, "transactions/unified")
38+
else:
39+
TEST_PATH = os.path.join(Path(__file__).resolve().parent.parent, "transactions/unified")
40+
41+
# Generate unified tests.
42+
globals().update(generate_test_classes(TEST_PATH, module=__name__))
43+
44+
# Location of JSON test specifications for transactions-convenient-api.
45+
if _IS_SYNC:
46+
TEST_PATH = os.path.join(Path(__file__).resolve().parent, "transactions-convenient-api/unified")
47+
else:
48+
TEST_PATH = os.path.join(
49+
Path(__file__).resolve().parent.parent, "transactions-convenient-api/unified"
50+
)
51+
52+
# Generate unified tests.
53+
globals().update(generate_test_classes(TEST_PATH, module=__name__))
54+
55+
if __name__ == "__main__":
56+
unittest.main()

test/test_transactions_unified.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,37 @@
1717

1818
import os
1919
import sys
20+
from pathlib import Path
2021

2122
sys.path[0:0] = [""]
2223

2324
from test import client_context, unittest
2425
from test.unified_format import generate_test_classes
2526

27+
_IS_SYNC = True
28+
2629

2730
@client_context.require_no_mmap
2831
def setUpModule():
2932
pass
3033

3134

3235
# Location of JSON test specifications.
33-
TEST_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "transactions", "unified")
36+
if _IS_SYNC:
37+
TEST_PATH = os.path.join(Path(__file__).resolve().parent, "transactions/unified")
38+
else:
39+
TEST_PATH = os.path.join(Path(__file__).resolve().parent.parent, "transactions/unified")
3440

3541
# Generate unified tests.
3642
globals().update(generate_test_classes(TEST_PATH, module=__name__))
3743

3844
# Location of JSON test specifications for transactions-convenient-api.
39-
TEST_PATH = os.path.join(
40-
os.path.dirname(os.path.realpath(__file__)), "transactions-convenient-api", "unified"
41-
)
45+
if _IS_SYNC:
46+
TEST_PATH = os.path.join(Path(__file__).resolve().parent, "transactions-convenient-api/unified")
47+
else:
48+
TEST_PATH = os.path.join(
49+
Path(__file__).resolve().parent.parent, "transactions-convenient-api/unified"
50+
)
4251

4352
# Generate unified tests.
4453
globals().update(generate_test_classes(TEST_PATH, module=__name__))

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def async_only_test(f: str) -> bool:
236236
"test_ssl.py",
237237
"test_streaming_protocol.py",
238238
"test_transactions.py",
239+
"test_transactions_unified.py",
239240
"test_unified_format.py",
240241
"unified_format.py",
241242
]

0 commit comments

Comments
 (0)