-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_test.py
executable file
·66 lines (62 loc) · 1.52 KB
/
query_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
'''
Ad-hoc test for query/database implementation
'''
from sys import argv
from parsing import QueryParser
import configuration as config
if __name__ == '__main__':
# Some crude testing
tests = [
'',
'kind == foo',
'room != foo',
'world == X and name != bar',
'name != home or room == Y',
'( room == X )',
'( world == X and room != Y )',
'world != Tallon Overworld North',
'world!=Tallon Overworld|room==North Pole&kind==Space Ship and name!=foo'
]
if len(argv) > 1:
tests.append(argv[1:])
# mock database
l = [
{
'kind':'Space Ship',
'room':'North Pole',
'world': 'Tallon Overworld',
'name':'bar'
},
{
'kind':'foo',
'room':'foo',
'world':'foo',
'name':'foo'
},
{
'kind':'bar',
'room':'bar',
'world':'bar',
'name':'bar'
},
{
'kind':'bar',
'room':'foo',
'world':'X',
'name':'foo'
},
{
'kind':'bar',
'room':'X',
'world':'Z',
'name':'home'
}
]
config.loadConfiguration('metroid_prime/config.json')
for query in tests:
print('Query:', query)
parser = QueryParser()
func = parser.parse(query)
print('\n'.join(str(e) for e in l if func(e)))
print('='*40)