Skip to content
Snippets Groups Projects
Commit 42a69491bdc8 authored by Paul McGuire's avatar Paul McGuire
Browse files

reformat test comments for runTests; example of using results from runTests in wordsToNum.py

parent 509b1afacf04
Branches
No related tags found
No related merge requests found
...@@ -38,9 +38,15 @@ ...@@ -38,9 +38,15 @@
date_expr.runTests("""\ date_expr.runTests("""\
2000/1/1 2000/1/1
2000/13/1 # invalid month
1900/2/29 # 1900 was not a leap year # invalid month
2000/2/29 # but 2000 was 2000/13/1
# 1900 was not a leap year
1900/2/29
# but 2000 was
2000/2/29
""") """)
...@@ -50,7 +56,13 @@ ...@@ -50,7 +56,13 @@
date_expr.runTests("""\ date_expr.runTests("""\
2000-01-01 2000-01-01
2000-13-01 # invalid month
1900-02-29 # 1900 was not a leap year # invalid month
2000-02-29 # but 2000 was 2000-13-01
# 1900 was not a leap year
1900-02-29
# but 2000 was
2000-02-29
""") """)
\ No newline at end of file
...@@ -16,5 +16,5 @@ ...@@ -16,5 +16,5 @@
WHERE = Keyword("where", caseless=True) WHERE = Keyword("where", caseless=True)
ident = Word( alphas, alphanums + "_$" ).setName("identifier") ident = Word( alphas, alphanums + "_$" ).setName("identifier")
columnName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens) columnName = ( delimitedList( ident, ".", combine=True ) ).setName("column name").addParseAction(upcaseTokens)
columnNameList = Group( delimitedList( columnName ) ) columnNameList = Group( delimitedList( columnName ) )
...@@ -20,5 +20,5 @@ ...@@ -20,5 +20,5 @@
columnNameList = Group( delimitedList( columnName ) ) columnNameList = Group( delimitedList( columnName ) )
tableName = ( delimitedList( ident, ".", combine=True ) ).addParseAction(upcaseTokens) tableName = ( delimitedList( ident, ".", combine=True ) ).setName("table name").addParseAction(upcaseTokens)
tableNameList = Group( delimitedList( tableName ) ) tableNameList = Group( delimitedList( tableName ) )
whereExpression = Forward() whereExpression = Forward()
...@@ -57,4 +57,6 @@ ...@@ -57,4 +57,6 @@
if __name__ == "__main__": if __name__ == "__main__":
simpleSQL.runTests("""\ simpleSQL.runTests("""\
# multiple tables
SELECT * from XYZZY, ABC SELECT * from XYZZY, ABC
...@@ -60,2 +62,4 @@ ...@@ -60,2 +62,4 @@
SELECT * from XYZZY, ABC SELECT * from XYZZY, ABC
# dotted table name
select * from SYS.XYZZY select * from SYS.XYZZY
...@@ -61,2 +65,3 @@ ...@@ -61,2 +65,3 @@
select * from SYS.XYZZY select * from SYS.XYZZY
Select A from Sys.dual Select A from Sys.dual
...@@ -62,3 +67,3 @@ ...@@ -62,3 +67,3 @@
Select A from Sys.dual Select A from Sys.dual
Select A,B,C from Sys.dual
Select A,B,C from Sys.dual Select A,B,C from Sys.dual
...@@ -64,2 +69,3 @@ ...@@ -64,2 +69,3 @@
Select A,B,C from Sys.dual Select A,B,C from Sys.dual
Select A, B, C from Sys.dual, Table2 Select A, B, C from Sys.dual, Table2
...@@ -65,2 +71,4 @@ ...@@ -65,2 +71,4 @@
Select A, B, C from Sys.dual, Table2 Select A, B, C from Sys.dual, Table2
# FAIL - invalid SELECT keyword
Xelect A, B, C from Sys.dual Xelect A, B, C from Sys.dual
...@@ -66,2 +74,4 @@ ...@@ -66,2 +74,4 @@
Xelect A, B, C from Sys.dual Xelect A, B, C from Sys.dual
# FAIL - invalid FROM keyword
Select A, B, C frox Sys.dual Select A, B, C frox Sys.dual
...@@ -67,2 +77,4 @@ ...@@ -67,2 +77,4 @@
Select A, B, C frox Sys.dual Select A, B, C frox Sys.dual
# FAIL - incomplete statement
Select Select
...@@ -68,2 +80,7 @@ ...@@ -68,2 +80,7 @@
Select Select
# FAIL - incomplete statement
Select * from
# FAIL - invalid column
Select &&& frox Sys.dual Select &&& frox Sys.dual
...@@ -69,2 +86,4 @@ ...@@ -69,2 +86,4 @@
Select &&& frox Sys.dual Select &&& frox Sys.dual
# where clause
Select A from Sys.dual where a in ('RED','GREEN','BLUE') Select A from Sys.dual where a in ('RED','GREEN','BLUE')
...@@ -70,2 +89,4 @@ ...@@ -70,2 +89,4 @@
Select A from Sys.dual where a in ('RED','GREEN','BLUE') Select A from Sys.dual where a in ('RED','GREEN','BLUE')
# compound where clause
Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30) Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30)
...@@ -71,2 +92,4 @@ ...@@ -71,2 +92,4 @@
Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30) Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30)
Select A,b from table1,table2 where table1.id eq table2.id -- test out comparison operators""")
# where clause with comparison operator
Select A,b from table1,table2 where table1.id eq table2.id""")
...@@ -78,8 +78,16 @@ ...@@ -78,8 +78,16 @@
numWords.ignore(CaselessLiteral("and")) numWords.ignore(CaselessLiteral("and"))
def test(s,expected): def test(s,expected):
print ("Expecting %s" % expected) try:
numWords.runTests(s) fail_expected = (expected is None)
success, results_tup = numWords.runTests(s, failureTests=fail_expected)
assert success, "Failed test!"
if not fail_expected:
teststr, results = results_tup[0]
observed = results[0]
assert expected == observed, "incorrect parsed value, {} -> {}, should be {}".format(teststr, observed, expected)
except Exception as exc:
print("{}: {}".format(type(exc).__name__, exc))
test("one hundred twenty hundred", None) test("one hundred twenty hundred", None)
test("one hundred and twennty", None) test("one hundred and twennty", None)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment