Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pyparsing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
pyparsing
Commits
42a69491bdc8
Commit
42a69491bdc8
authored
8 years ago
by
Paul McGuire
Browse files
Options
Downloads
Patches
Plain Diff
reformat test comments for runTests; example of using results from runTests in wordsToNum.py
parent
509b1afacf04
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/examples/datetimeParseActions.py
+18
-6
18 additions, 6 deletions
src/examples/datetimeParseActions.py
src/examples/simpleSQL.py
+39
-16
39 additions, 16 deletions
src/examples/simpleSQL.py
src/examples/wordsToNum.py
+10
-2
10 additions, 2 deletions
src/examples/wordsToNum.py
with
67 additions
and
24 deletions
src/examples/datetimeParseActions.py
+
18
−
6
View file @
42a69491
...
@@ -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
This diff is collapsed.
Click to expand it.
src/examples/simpleSQL.py
+
39
−
16
View file @
42a69491
...
@@ -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
"""
)
This diff is collapsed.
Click to expand it.
src/examples/wordsToNum.py
+
10
−
2
View file @
42a69491
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment