|
23 | 23 | LOGGER = logging.getLogger(__name__)
|
24 | 24 | logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
|
25 | 25 |
|
26 |
| -# Handle green frameworks first so they can patch modules. |
27 |
| -if GREEN_FRAMEWORK: |
| 26 | + |
| 27 | +def handle_perf(start_time: datetime, end_time: datetime): |
| 28 | + elapsed_secs = (end_time - start_time).total_seconds() |
| 29 | + with open("results.json") as fid: |
| 30 | + results = json.load(fid) |
| 31 | + LOGGER.info("results.json:\n%s", json.dumps(results, indent=2)) |
| 32 | + |
| 33 | + results = dict( |
| 34 | + status="pass", |
| 35 | + exit_code=0, |
| 36 | + test_file="BenchMarkTests", |
| 37 | + start=int(start_time.timestamp()), |
| 38 | + end=int(end_time.timestamp()), |
| 39 | + elapsed=elapsed_secs, |
| 40 | + ) |
| 41 | + report = dict(failures=0, results=results) |
| 42 | + LOGGER.info("report.json\n%s", json.dumps(report, indent=2)) |
| 43 | + |
| 44 | + with open("report.json", "w", newline="\n") as fid: |
| 45 | + json.dump(report, fid) |
| 46 | + |
| 47 | + |
| 48 | +def handle_green_framework() -> None: |
28 | 49 | if GREEN_FRAMEWORK == "eventlet":
|
29 | 50 | import eventlet
|
30 | 51 |
|
|
46 | 67 |
|
47 | 68 | LOGGER.info(f"Running tests with {GREEN_FRAMEWORK}...")
|
48 | 69 |
|
49 |
| -# Ensure C extensions if applicable. |
50 |
| -if not os.environ.get("NO_EXT") and platform.python_implementation() == "CPython": |
51 |
| - sys.path.insert(0, str(ROOT / "tools")) |
52 |
| - from fail_if_no_c import main as fail_if_no_c |
53 | 70 |
|
54 |
| - fail_if_no_c() |
| 71 | +def run() -> None: |
| 72 | + # Handle green frameworks first so they can patch modules. |
| 73 | + if GREEN_FRAMEWORK: |
| 74 | + handle_green_framework() |
55 | 75 |
|
56 |
| -if os.environ.get("PYMONGOCRYPT_LIB"): |
57 |
| - # Ensure pymongocrypt is working properly. |
58 |
| - import pymongocrypt |
| 76 | + # Ensure C extensions if applicable. |
| 77 | + if not os.environ.get("NO_EXT") and platform.python_implementation() == "CPython": |
| 78 | + sys.path.insert(0, str(ROOT / "tools")) |
| 79 | + from fail_if_no_c import main as fail_if_no_c |
59 | 80 |
|
60 |
| - LOGGER.info(f"pymongocrypt version: {pymongocrypt.__version__})") |
61 |
| - LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})") |
| 81 | + fail_if_no_c() |
62 | 82 |
|
63 |
| -LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}") |
| 83 | + if os.environ.get("PYMONGOCRYPT_LIB"): |
| 84 | + # Ensure pymongocrypt is working properly. |
| 85 | + import pymongocrypt |
64 | 86 |
|
65 |
| -# Record the start time for a perf test. |
66 |
| -if TEST_PERF: |
67 |
| - start_time = datetime.now() |
| 87 | + LOGGER.info(f"pymongocrypt version: {pymongocrypt.__version__})") |
| 88 | + LOGGER.info(f"libmongocrypt version: {pymongocrypt.libmongocrypt_version()})") |
68 | 89 |
|
69 |
| -# Run the tests. |
70 |
| -pytest.main(TEST_ARGS) |
| 90 | + LOGGER.info(f"Test setup:\n{AUTH=}\n{SSL=}\n{UV_ARGS=}\n{TEST_ARGS=}") |
71 | 91 |
|
72 |
| -# Handle perf test post actions. |
73 |
| -if TEST_PERF: |
74 |
| - end_time = datetime.now() |
75 |
| - elapsed_secs = (end_time - start_time).total_seconds() |
76 |
| - with open("results.json") as fid: |
77 |
| - results = json.load(fid) |
78 |
| - LOGGER.info("results.json:\n%s", json.dumps(results, indent=2)) |
| 92 | + # Record the start time for a perf test. |
| 93 | + if TEST_PERF: |
| 94 | + start_time = datetime.now() |
79 | 95 |
|
80 |
| - results = dict( |
81 |
| - status="pass", |
82 |
| - exit_code=0, |
83 |
| - test_file="BenchMarkTests", |
84 |
| - start=int(start_time.timestamp()), |
85 |
| - end=int(end_time.timestamp()), |
86 |
| - elapsed=elapsed_secs, |
87 |
| - ) |
88 |
| - report = dict(failures=0, results=results) |
89 |
| - LOGGER.info("report.json\n%s", json.dumps(report, indent=2)) |
| 96 | + # Run the tests. |
| 97 | + pytest.main(TEST_ARGS) |
90 | 98 |
|
91 |
| - with open("report.json", "w", newline="\n") as fid: |
92 |
| - json.dump(report, fid) |
| 99 | + # Handle perf test post actions. |
| 100 | + if TEST_PERF: |
| 101 | + end_time = datetime.now() |
| 102 | + handle_perf(start_time, end_time) |
| 103 | + |
| 104 | + # Handle coverage post actions. |
| 105 | + if os.environ.get("COVERAGE"): |
| 106 | + shutil.rmtree(".pytest_cache", ignore_errors=True) |
93 | 107 |
|
94 | 108 |
|
95 |
| -# Handle coverage post actions. |
96 |
| -if os.environ.get("COVERAGE"): |
97 |
| - shutil.rmtree(".pytest_cache", ignore_errors=True) |
| 109 | +if __name__ == "__main__": |
| 110 | + run() |
0 commit comments