msyavuz commented on code in PR #36983:
URL: https://github.com/apache/superset/pull/36983#discussion_r2672622466


##########
tests/unit_tests/utils/date_parser_tests.py:
##########
@@ -611,3 +611,47 @@ def test_date_range_migration() -> None:
 
     field = "10 years ago"
     assert not re.search(DateRangeMigration.x_dateunit, field)
+
+
+# Tests for bounded whitespace regex patterns in time_range_lookup
[email protected](
+    "time_range,should_parse",
+    [
+        ("last 7 days : ", True),
+        ("this week : ", True),
+        ("start of next month : ", True),
+        ("prior quarter : ", True),
+        ("last  7 days : ", True),
+        ("last   7 days : ", True),
+        ("last    7 days : ", True),
+        ("last     7 days : ", True),
+        ("last      7 days : ", False),  # 6 spaces - exceeds bound
+        ("start of     next     month : ", True),  # 5 spaces - valid
+        ("last week : ", True),
+        ("last  week : ", True),
+        ("last     week : ", True),
+        ("next 12 months : ", True),
+        ("next  12  months : ", True),
+        ("next     12     months : ", True),
+        ("last7days : ", False),  # no space after scope - invalid
+        ("last 7days : ", True),  # \s{0,5} allows 0 spaces after number - 
valid
+        ("lastweek : ", False),  # no space after scope - invalid
+        # === Negative Tests: Partial matches ===
+        ("last : ", False),
+        ("start of : ", False),
+        ("last 7 days extra : ", False),
+    ],
+)
+@patch("superset.utils.date_parser.parse_human_datetime", 
mock_parse_human_datetime)
+def test_time_range_bounded_whitespace_regex(
+    time_range: str, should_parse: bool
+) -> None:
+    """
+    1. Match expressions with 1-5 spaces between tokens
+    2. Reject expressions with 0 or 6+ spaces (fall back to DATETIME wrapping)
+    """
+    result = get_since_until(time_range)
+    if should_parse:
+        assert result[0] is not None, f"Expected '{time_range}' to parse 
successfully"
+    else:
+        assert result[0] is None, f"Expected '{time_range}' to NOT match 
bounded regex"

Review Comment:
   Let's not add conditionals inside unit tests



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to