def test_double_eq_different(): with pytest.raises(ValueError): q(age=20, age__eq=21)
def query(): return q(name="Name", age__lt=100, age__gt=20)
def test_auto_eq_operator(): assert q(age=20, age__lt=50) == {"age": {"$eq": 20, "$lt": 50}}
def test_double_eq_same(): # We want an equality query but the spec does not force a specific query shape assert q(age=20, age__eq=20) in [{"age": 20}, {"age": {"$eq": 20}}]
def test_independent_fields(): assert q(name="Name", age__lt=100) == {"name": "Name", "age": {"$lt": 100}}
def test_camel_operators(): assert q(mask__bits_all_set=15) == {"mask": {"$bitsAllSet": 15}}
def test_operator(op): assert q(**{f"age__{op}": 20}) == {"age": {f"${op}": 20}}
def test_multiple_operators(): assert q(age__gt=20, age__lt=100) == {"age": {"$gt": 20, "$lt": 100}}
def test_multi_id(): assert q(123, None, "Some ID") == {"_id": {"$in": [123, "Some ID"]}}
def test_kwargs(): assert q(name="Name", password="******") == {"name": "Name", "password": "******"}
def test_none_id(): assert q(None) == {"X": {"$in": []}}
def test_single_id(id): assert q(id) == {"_id": id}
def test_nor(): assert q(age=20) ^ q(name="Name") == {"$nor": [{"age": 20}, {"name": "Name"}]}
def test_and(): assert q(age=20) & q(name="Name") == {"$and": [{"age": 20}, {"name": "Name"}]}
def test_instance(): assert isinstance(q(), Query)