Add query comparison tests for $eq#696
Conversation
Signed-off-by: Victor [C] Tsang <vitsangp@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage); effort from diff stats (1461+0 LOC, 11 files); LLM: Adds new compatibility test cases for the $eq query operator, expanding test coverage in the tests directory. If a label is wrong, remove it manually and ping |
| ), | ||
| QueryTestCase( | ||
| id="decimal128", | ||
| filter={"a": {"$eq": Decimal128("1.5")}}, |
There was a problem hiding this comment.
Could be DECIMAL128_ONE_AND_HALF
| """Parametrized test for $eq string-equality subtleties.""" | ||
| collection.insert_many(test.doc) | ||
| result = execute_command(collection, {"find": collection.name, "filter": test.filter}) | ||
| assertSuccess(result, test.expected, ignore_doc_order=True) |
There was a problem hiding this comment.
I think the various calls (not just in this file) are not passing through the msg field from the cases which means it won't show up in errors.
| ) | ||
|
|
||
|
|
||
| # (id, docs, value, expected) — the explicit {a: {$eq: value}} and implicit |
There was a problem hiding this comment.
Style nit: it's quite difficult to follow the case definitions here given the lack of types and clarity on what the parameters of the array mean. Consider using something like this which is closer to the style used elsewhere and more explicit imo:
# Property [Form Equivalence]: the implicit {a: v} form selects the same
# documents as the explicit {a: {$eq: v}} form for any non-regex operand.
# (Regex is the one operand where they diverge; see test_eq_regex.)
EQ_FORM_EQUIVALENCE_TESTS: list[QueryTestCase] = [
QueryTestCase(
id="scalar_int",
filter={"a": {"$eq": 1}},
doc=[{"_id": 1, "a": 1}, {"_id": 2, "a": 2}],
msg="$eq int operand should select the same documents in both forms",
),
QueryTestCase(
id="string",
filter={"a": {"$eq": "x"}},
doc=[{"_id": 1, "a": "x"}, {"_id": 2, "a": "y"}],
msg="$eq string operand should select the same documents in both forms",
),
QueryTestCase(
id="null_and_missing",
filter={"a": {"$eq": None}},
doc=[{"_id": 1, "a": None}, {"_id": 2}, {"_id": 3, "a": 1}],
msg="$eq null operand should select the same documents in both forms",
),
QueryTestCase(
id="array",
filter={"a": {"$eq": [1, 2]}},
doc=[{"_id": 1, "a": [1, 2]}, {"_id": 2, "a": [1, 2, 3]}],
msg="$eq array operand should select the same documents in both forms",
),
QueryTestCase(
id="embedded_document",
filter={"a": {"$eq": {"b": 1}}},
doc=[{"_id": 1, "a": {"b": 1}}, {"_id": 2, "a": {"b": 2}}],
msg="$eq document operand should select the same documents in both forms",
),
]
@pytest.mark.parametrize("test", pytest_params(EQ_FORM_EQUIVALENCE_TESTS))
def test_eq_implicit_form_equivalence(collection, test):
"""Test explicit {a: {$eq: v}} and implicit {a: v} forms select the same documents."""
collection.insert_many(test.doc)
value = test.filter["a"]["$eq"]
explicit = execute_command(collection, {"find": collection.name, "filter": test.filter})
implicit = execute_command(collection, {"find": collection.name, "filter": {"a": value}})
assertSuccess(
explicit,
implicit["cursor"]["firstBatch"],
ignore_doc_order=True,
msg=test.msg,
)| """Parametrized test for $eq edge cases involving NaN.""" | ||
| collection.insert_many(test.doc) | ||
| result = execute_command(collection, {"find": collection.name, "filter": test.filter}) | ||
| assertSuccessNaN(result, test.expected, ignore_doc_order=True) |
There was a problem hiding this comment.
Can we use assertResult here with pytest.approx like we do elsewhere? I don't think this case needs its own dedicated method if the one above is swapped to assertResult. This seems to be using the older style still
| ] | ||
|
|
||
|
|
||
| ALL_TESTS = STRING_TESTS |
There was a problem hiding this comment.
Is this needed? Seems redundant
This PR contains:
Ref: