IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit b020ac74 authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] Handle comments in query req eqaulity

parent b290c6c7
......@@ -25,11 +25,24 @@ class QueryRequest(NamedTuple):
query: str
args: Tuple[Any, ...] | List[Any]
@staticmethod
def _normalize_query_string(q: str) -> list[str]:
return [
word
for line in q\
.strip()\
.split('\n')\
for word in line\
.split('--')[0]\
.lower()\
.split()
]
def __eq__(self, other: object) -> bool:
return\
isinstance(other, QueryRequest) and\
self.args == other.args and\
self.query.lower().split() == other.query.lower().split()\
self._normalize_query_string(self.query) == self._normalize_query_string(other.query)\
or\
isinstance(other, Tuple) and\
other.__len__() == 2 and\
......
......@@ -25,6 +25,23 @@ class TestQueries(unittest.TestCase):
QueryRequest(' hewwo\tworld', (2,)),
QueryRequest('hewwo world', (1, 2))
)
self.assertEqual(
QueryRequest('''
SELECT some_feild --TODO change this
FROM my_table
-- Now the join statement
NATURAL JOIN other_table
''', (1, 2)),
QueryRequest('select some_feild from my_table natural join other_table', (1, 2))
)
self.assertEqual(
QueryRequest('query req', tuple()),
('query req', tuple())
)
self.assertEqual(
('query req', tuple()),
QueryRequest('query req', tuple())
)
def test_noop(self):
str_noop = Noop("hello")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment