From fbfff8d319db3e448fdf48f46bf73fec9aaf80fa Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Tue, 12 May 2026 21:03:43 -0700 Subject: [PATCH] fix: coerce numeric query param expectations to string when matching --- src/pook/matchers/query.py | 14 ++++++++++++-- tests/unit/matchers/query_test.py | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/pook/matchers/query.py b/src/pook/matchers/query.py index 185ac9f..fec1943 100644 --- a/src/pook/matchers/query.py +++ b/src/pook/matchers/query.py @@ -3,6 +3,13 @@ from .base import BaseMatcher, ExistsMatcher +def _to_query_value(value): + # Query string values are always strings; coerce numeric expectations + if isinstance(value, (int, float)) and not isinstance(value, bool): + return str(value) + return value + + class QueryMatcher(BaseMatcher): """ QueryMatcher implements an URL query params matcher. @@ -17,8 +24,11 @@ def test(key, param): # Normalize param value param = [param] if not isinstance(param, list) else param - # Compare query params - [[self.compare(value, expect) for expect in match] for value in param] + # Compare query params, coercing numeric expectations to str + [ + [self.compare(_to_query_value(value), expect) for expect in match] + for value in param + ] return True diff --git a/tests/unit/matchers/query_test.py b/tests/unit/matchers/query_test.py index a0b0beb..6f6aec9 100644 --- a/tests/unit/matchers/query_test.py +++ b/tests/unit/matchers/query_test.py @@ -20,3 +20,11 @@ def test_param_exists_empty_allowed(url_404): res = urlopen(f"{url_404}?x") assert res.status == 200 + + +@pytest.mark.pook +def test_params_numeric_value(url_404): + pook.get(url_404).params({"x": 1}).reply(200) + + res = urlopen(f"{url_404}?x=1") + assert res.status == 200