(where_clause, expected_tokens)
| 515 | |
| 516 | def 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)] |
no test coverage detected
searching dependent graphs…