MCPcopy Index your code
hub / github.com/andialbrecht/sqlparse / validate_where_clause

Function validate_where_clause

tests/test_grouping.py:517–529  ·  view source on GitHub ↗
(where_clause, expected_tokens)

Source from the content-addressed store, hash-verified

515
516def test_like_and_ilike_comparison():
517 def validate_where_clause(where_clause, expected_tokens):
518 assert len(where_clause.tokens) == len(expected_tokens)
519 for where_token, expected_token in zip(where_clause, expected_tokens):
520 expected_ttype, expected_value = expected_token
521 if where_token.ttype is not None:
522 assert where_token.match(expected_ttype, expected_value, regex=True)
523 else:
524 # Certain tokens, such as comparison tokens, do not define a ttype that can be
525 # matched against. For these tokens, we ensure that the token instance is of
526 # the expected type and has a value conforming to specified regular expression
527 import re
528 assert (isinstance(where_token, expected_ttype)
529 and re.match(expected_value, where_token.value))
530
531 [p1] = sqlparse.parse("select * from mytable where mytable.mycolumn LIKE 'expr%' limit 5;")
532 [p1_where] = [token for token in p1 if isinstance(token, sql.Where)]

Callers 1

Calls 1

matchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…