Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmasterplan authored and andialbrecht committed Jan 2, 2023
1 parent e0d3928 commit 4efdc03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def clear(self):
def set_SQL_REGEX(self, SQL_REGEX):
"""Set the list of regex that will parse the SQL."""
FLAGS = re.IGNORECASE | re.UNICODE
self._SQL_REGEX = [(re.compile(rx, FLAGS).match, tt) for rx, tt in SQL_REGEX]
self._SQL_REGEX = [
(re.compile(rx, FLAGS).match, tt)
for rx, tt in SQL_REGEX
]

def add_keywords(self, keywords):
"""Add keyword dictionaries. Keywords are looked up in the same order
Expand Down
1 change: 0 additions & 1 deletion tests/test_keywords.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from sqlparse import tokens
from sqlparse.keywords import SQL_REGEX
from sqlparse.lexer import Lexer


Expand Down
19 changes: 15 additions & 4 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,15 @@ def test_parenthesis():
T.Newline,
T.Punctuation]


def test_configurable_keywords():
sql = """select * from foo BACON SPAM EGGS;"""
tokens = sqlparse.parse(sql)[0]

assert list(
(t.ttype, t.value) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
(t.ttype, t.value)
for t in tokens
if t.ttype not in sqlparse.tokens.Whitespace
) == [
(sqlparse.tokens.Keyword.DML, "select"),
(sqlparse.tokens.Wildcard, "*"),
Expand All @@ -520,7 +523,9 @@ def test_configurable_keywords():
Lexer().default_initialization()

assert list(
(t.ttype, t.value) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
(t.ttype, t.value)
for t in tokens
if t.ttype not in sqlparse.tokens.Whitespace
) == [
(sqlparse.tokens.Keyword.DML, "select"),
(sqlparse.tokens.Wildcard, "*"),
Expand All @@ -539,7 +544,11 @@ def test_configurable_regex():

my_regex = (r"ZORDER\s+BY\b", sqlparse.tokens.Keyword)

lex.set_SQL_REGEX(keywords.SQL_REGEX[:38] + [my_regex] + keywords.SQL_REGEX[38:])
lex.set_SQL_REGEX(
keywords.SQL_REGEX[:38]
+ [my_regex]
+ keywords.SQL_REGEX[38:]
)
lex.add_keywords(keywords.KEYWORDS_COMMON)
lex.add_keywords(keywords.KEYWORDS_ORACLE)
lex.add_keywords(keywords.KEYWORDS_PLPGSQL)
Expand All @@ -553,5 +562,7 @@ def test_configurable_regex():
Lexer().default_initialization()

assert list(
(t.ttype, t.value) for t in tokens if t.ttype not in sqlparse.tokens.Whitespace
(t.ttype, t.value)
for t in tokens
if t.ttype not in sqlparse.tokens.Whitespace
)[4] == (sqlparse.tokens.Keyword, "zorder by")

0 comments on commit 4efdc03

Please sign in to comment.