From 94686bd510a25bfb7624f8087eb33769f01c3bad Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 24 Nov 2026 11:02:58 -0600 Subject: [PATCH 1/3] PYTHON-6293 Bump unified test runner to schema version 1.30 --- test/asynchronous/test_unified_format.py | 52 ++++++++++++++++++++++++ test/asynchronous/unified_format.py | 2 +- test/test_unified_format.py | 52 ++++++++++++++++++++++++ test/unified_format.py | 2 +- test/unified_format_shared.py | 5 +++ 5 files changed, 111 insertions(+), 2 deletions(-) diff --git a/test/asynchronous/test_unified_format.py b/test/asynchronous/test_unified_format.py index e03ca1cc0e..411f8e8040 100644 --- a/test/asynchronous/test_unified_format.py +++ b/test/asynchronous/test_unified_format.py @@ -13,6 +13,7 @@ # limitations under the License. from __future__ import annotations +import json import os import sys from pathlib import Path @@ -24,9 +25,11 @@ from test import UnitTest, unittest from test.asynchronous.unified_format import ( MatchEvaluatorUtil, + UnifiedSpecTestMixinV1, generate_test_classes, get_test_path, ) +from test.version import Version _IS_SYNC = False @@ -55,6 +58,41 @@ ) +class TestSchemaVersionCoverage(UnitTest): + def test_all_spec_files_are_supported(self): + # PYTHON-6293: a spec resync that bumps a file's schemaVersion past + # the runner's SCHEMA_VERSION otherwise only surfaces as a runtime + # failure in asyncSetUp. Every consumed spec file must declare a + # schema version the runner supports. + # test/unified-test-format/invalid/ is not consumed by the runner and + # valid-fail/ files (including schemaVersion-unsupported.json) are + # deliberately invalid, so both are skipped. + runner_version = UnifiedSpecTestMixinV1.SCHEMA_VERSION + root = get_test_path() + skipped = ( + os.path.join("unified-test-format", "invalid"), + os.path.join("unified-test-format", "valid-fail"), + ) + unsupported = [] + for dirpath, dirnames, filenames in os.walk(root): + rel = os.path.relpath(dirpath, root) + if any(rel == prefix or rel.startswith(prefix + os.sep) for prefix in skipped): + continue + for filename in sorted(filenames): + if not filename.endswith(".json"): + continue + with open(os.path.join(dirpath, filename)) as fpath: + spec = json.load(fpath) + version = spec.get("schemaVersion") if isinstance(spec, dict) else None + if not isinstance(version, str): + continue + parsed = Version.from_string(version) + if parsed[0] != runner_version[0] or parsed > runner_version: + unsupported.append((os.path.join(rel, filename), version)) + + self.assertEqual(unsupported, []) + + class TestMatchEvaluatorUtil(UnitTest): def setUp(self): self.match_evaluator = MatchEvaluatorUtil(self) @@ -88,6 +126,20 @@ def test_type(self): }, ) + def test_lte(self): + # Added in schema version 1.9. + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 5}) + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 3}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + + def test_gte(self): + # Added in schema version 1.29. + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 5}) + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 6}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + if __name__ == "__main__": unittest.main() diff --git a/test/asynchronous/unified_format.py b/test/asynchronous/unified_format.py index 9e5afb6d98..e1c43d3c32 100644 --- a/test/asynchronous/unified_format.py +++ b/test/asynchronous/unified_format.py @@ -491,7 +491,7 @@ class UnifiedSpecTestMixinV1(AsyncIntegrationTest): a class attribute ``TEST_SPEC``. """ - SCHEMA_VERSION = Version.from_string("1.28") + SCHEMA_VERSION = Version.from_string("1.30") RUN_ON_LOAD_BALANCER = True TEST_SPEC: Any TEST_PATH = "" # This gets filled in by generate_test_classes diff --git a/test/test_unified_format.py b/test/test_unified_format.py index a02df1c560..39df00eb68 100644 --- a/test/test_unified_format.py +++ b/test/test_unified_format.py @@ -13,6 +13,7 @@ # limitations under the License. from __future__ import annotations +import json import os import sys from pathlib import Path @@ -24,9 +25,11 @@ from test import UnitTest, unittest from test.unified_format import ( MatchEvaluatorUtil, + UnifiedSpecTestMixinV1, generate_test_classes, get_test_path, ) +from test.version import Version _IS_SYNC = True @@ -55,6 +58,41 @@ ) +class TestSchemaVersionCoverage(UnitTest): + def test_all_spec_files_are_supported(self): + # PYTHON-6293: a spec resync that bumps a file's schemaVersion past + # the runner's SCHEMA_VERSION otherwise only surfaces as a runtime + # failure in setUp. Every consumed spec file must declare a + # schema version the runner supports. + # test/unified-test-format/invalid/ is not consumed by the runner and + # valid-fail/ files (including schemaVersion-unsupported.json) are + # deliberately invalid, so both are skipped. + runner_version = UnifiedSpecTestMixinV1.SCHEMA_VERSION + root = get_test_path() + skipped = ( + os.path.join("unified-test-format", "invalid"), + os.path.join("unified-test-format", "valid-fail"), + ) + unsupported = [] + for dirpath, dirnames, filenames in os.walk(root): + rel = os.path.relpath(dirpath, root) + if any(rel == prefix or rel.startswith(prefix + os.sep) for prefix in skipped): + continue + for filename in sorted(filenames): + if not filename.endswith(".json"): + continue + with open(os.path.join(dirpath, filename)) as fpath: + spec = json.load(fpath) + version = spec.get("schemaVersion") if isinstance(spec, dict) else None + if not isinstance(version, str): + continue + parsed = Version.from_string(version) + if parsed[0] != runner_version[0] or parsed > runner_version: + unsupported.append((os.path.join(rel, filename), version)) + + self.assertEqual(unsupported, []) + + class TestMatchEvaluatorUtil(UnitTest): def setUp(self): self.match_evaluator = MatchEvaluatorUtil(self) @@ -88,6 +126,20 @@ def test_type(self): }, ) + def test_lte(self): + # Added in schema version 1.9. + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 5}) + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 3}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + + def test_gte(self): + # Added in schema version 1.29. + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 5}) + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 6}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + if __name__ == "__main__": unittest.main() diff --git a/test/unified_format.py b/test/unified_format.py index 244d58514c..c4542de403 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -489,7 +489,7 @@ class UnifiedSpecTestMixinV1(IntegrationTest): a class attribute ``TEST_SPEC``. """ - SCHEMA_VERSION = Version.from_string("1.28") + SCHEMA_VERSION = Version.from_string("1.30") RUN_ON_LOAD_BALANCER = True TEST_SPEC: Any TEST_PATH = "" # This gets filled in by generate_test_classes diff --git a/test/unified_format_shared.py b/test/unified_format_shared.py index d860d345fc..7b5d5a2704 100644 --- a/test/unified_format_shared.py +++ b/test/unified_format_shared.py @@ -453,6 +453,11 @@ def _operation_lte(self, spec, actual, key_to_compare): self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") self.test.assertLessEqual(actual[key_to_compare], spec) + def _operation_gte(self, spec, actual, key_to_compare): + if key_to_compare not in actual: + self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") + self.test.assertGreaterEqual(actual[key_to_compare], spec) + def _operation_matchAsDocument(self, spec, actual, key_to_compare): self._match_document(spec, json_util.loads(actual[key_to_compare]), False, test=True) From 102bcf8c6a1b49f0ac37adc357afe4563bdd6b15 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 24 Nov 2026 11:22:26 -0600 Subject: [PATCH 2/3] Handle missing comparison key in 21215gte/21215lte matchers --- test/asynchronous/test_unified_format.py | 20 ++++++++++++++++++++ test/test_unified_format.py | 20 ++++++++++++++++++++ test/unified_format_shared.py | 10 ++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/test/asynchronous/test_unified_format.py b/test/asynchronous/test_unified_format.py index 411f8e8040..e9237d94a4 100644 --- a/test/asynchronous/test_unified_format.py +++ b/test/asynchronous/test_unified_format.py @@ -133,6 +133,16 @@ def test_lte(self): with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + def test_lte_whole_result(self): + # A special operator can match an entire operation result or an + # array element, in which case there is no field key to compare. + self.match_evaluator.match_result({"$$lte": 5}, 5) + self.match_evaluator.match_result([{"$$lte": 5}], [5]) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"$$lte": 5}, 6) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result([{"$$lte": 5}], [6]) + def test_gte(self): # Added in schema version 1.29. self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 5}) @@ -140,6 +150,16 @@ def test_gte(self): with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + def test_gte_whole_result(self): + # A special operator can match an entire operation result or an + # array element, in which case there is no field key to compare. + self.match_evaluator.match_result({"$$gte": 5}, 5) + self.match_evaluator.match_result([{"$$gte": 5}], [5]) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"$$gte": 5}, 3) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result([{"$$gte": 5}], [3]) + if __name__ == "__main__": unittest.main() diff --git a/test/test_unified_format.py b/test/test_unified_format.py index 39df00eb68..7537a06544 100644 --- a/test/test_unified_format.py +++ b/test/test_unified_format.py @@ -133,6 +133,16 @@ def test_lte(self): with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + def test_lte_whole_result(self): + # A special operator can match an entire operation result or an + # array element, in which case there is no field key to compare. + self.match_evaluator.match_result({"$$lte": 5}, 5) + self.match_evaluator.match_result([{"$$lte": 5}], [5]) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"$$lte": 5}, 6) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result([{"$$lte": 5}], [6]) + def test_gte(self): # Added in schema version 1.29. self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 5}) @@ -140,6 +150,16 @@ def test_gte(self): with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + def test_gte_whole_result(self): + # A special operator can match an entire operation result or an + # array element, in which case there is no field key to compare. + self.match_evaluator.match_result({"$$gte": 5}, 5) + self.match_evaluator.match_result([{"$$gte": 5}], [5]) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"$$gte": 5}, 3) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result([{"$$gte": 5}], [3]) + if __name__ == "__main__": unittest.main() diff --git a/test/unified_format_shared.py b/test/unified_format_shared.py index 7b5d5a2704..2bff5c51b3 100644 --- a/test/unified_format_shared.py +++ b/test/unified_format_shared.py @@ -449,14 +449,16 @@ def _operation_sessionLsid(self, spec, actual, key_to_compare): self.test.assertEqual(expected_lsid, actual[key_to_compare]) def _operation_lte(self, spec, actual, key_to_compare): - if key_to_compare not in actual: + if key_to_compare is not None and key_to_compare not in actual: self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") - self.test.assertLessEqual(actual[key_to_compare], spec) + value = actual[key_to_compare] if key_to_compare else actual + self.test.assertLessEqual(value, spec) def _operation_gte(self, spec, actual, key_to_compare): - if key_to_compare not in actual: + if key_to_compare is not None and key_to_compare not in actual: self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") - self.test.assertGreaterEqual(actual[key_to_compare], spec) + value = actual[key_to_compare] if key_to_compare else actual + self.test.assertGreaterEqual(value, spec) def _operation_matchAsDocument(self, spec, actual, key_to_compare): self._match_document(spec, json_util.loads(actual[key_to_compare]), False, test=True) From 45fce3ff0a012e8d9696fe15bce1944c4163ca67 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 24 Nov 2026 11:31:18 -0600 Subject: [PATCH 3/3] Compare empty-string field keys directly in 21215gte/21215lte --- test/asynchronous/test_unified_format.py | 8 ++++++++ test/test_unified_format.py | 8 ++++++++ test/unified_format_shared.py | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/asynchronous/test_unified_format.py b/test/asynchronous/test_unified_format.py index e9237d94a4..6c652e5167 100644 --- a/test/asynchronous/test_unified_format.py +++ b/test/asynchronous/test_unified_format.py @@ -132,6 +132,10 @@ def test_lte(self): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 3}) with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + # An empty field name is a valid field key, not whole-result matching. + self.match_evaluator.match_result({"": {"$$lte": 5}}, {"": 5}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"": {"$$lte": 5}}, {"": 6}) def test_lte_whole_result(self): # A special operator can match an entire operation result or an @@ -149,6 +153,10 @@ def test_gte(self): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 6}) with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + # An empty field name is a valid field key, not whole-result matching. + self.match_evaluator.match_result({"": {"$$gte": 5}}, {"": 5}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"": {"$$gte": 5}}, {"": 3}) def test_gte_whole_result(self): # A special operator can match an entire operation result or an diff --git a/test/test_unified_format.py b/test/test_unified_format.py index 7537a06544..190746bddf 100644 --- a/test/test_unified_format.py +++ b/test/test_unified_format.py @@ -132,6 +132,10 @@ def test_lte(self): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 3}) with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$lte": 5}}, {"x": 6}) + # An empty field name is a valid field key, not whole-result matching. + self.match_evaluator.match_result({"": {"$$lte": 5}}, {"": 5}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"": {"$$lte": 5}}, {"": 6}) def test_lte_whole_result(self): # A special operator can match an entire operation result or an @@ -149,6 +153,10 @@ def test_gte(self): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 6}) with self.assertRaises(AssertionError): self.match_evaluator.match_result({"x": {"$$gte": 5}}, {"x": 3}) + # An empty field name is a valid field key, not whole-result matching. + self.match_evaluator.match_result({"": {"$$gte": 5}}, {"": 5}) + with self.assertRaises(AssertionError): + self.match_evaluator.match_result({"": {"$$gte": 5}}, {"": 3}) def test_gte_whole_result(self): # A special operator can match an entire operation result or an diff --git a/test/unified_format_shared.py b/test/unified_format_shared.py index 2bff5c51b3..e72611d6f0 100644 --- a/test/unified_format_shared.py +++ b/test/unified_format_shared.py @@ -451,13 +451,13 @@ def _operation_sessionLsid(self, spec, actual, key_to_compare): def _operation_lte(self, spec, actual, key_to_compare): if key_to_compare is not None and key_to_compare not in actual: self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") - value = actual[key_to_compare] if key_to_compare else actual + value = actual[key_to_compare] if key_to_compare is not None else actual self.test.assertLessEqual(value, spec) def _operation_gte(self, spec, actual, key_to_compare): if key_to_compare is not None and key_to_compare not in actual: self.test.fail(f"Actual command is missing the {key_to_compare} field: {spec}") - value = actual[key_to_compare] if key_to_compare else actual + value = actual[key_to_compare] if key_to_compare is not None else actual self.test.assertGreaterEqual(value, spec) def _operation_matchAsDocument(self, spec, actual, key_to_compare):