-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_ashval.py
92 lines (77 loc) · 3.19 KB
/
test_ashval.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
import unittest
import ashval
import data
class TestAshval(unittest.TestCase):
def setUp(self):
print "test ashval start..."
def tearDown(self):
print "tear down..."
def test_raw_ashval(self):
question = "click [100 200]"
right_answer = ["click", ["100", "200"]]
self.assertEqual(ashval.ashval(question), right_answer)
question = "test [100 [100 200] [ [100 200] 300] [400]] [ [200] ]"
right_answer = ["test", ["100", ["100", "200"],
[["100", "200"], "300"], ["400"]], [["200"]]]
self.assertEqual(ashval.ashval(question), right_answer)
def test_get_code(self):
f = ashval._get_code(["arg"])
self.assertTrue(f and hasattr(f, '__call__'))
def test_ashval_function(self):
data.add_callback("", "alias", "c",
[
["_mock_function",
["arg", "1"], ["arg", "2"], ["arg", "3"]]
])
self.assertEqual(ashval.ashval("c 100 200 300"),
"_mock_function : 100, 200, 300")
self.assertEqual(ashval.ashval("c 110 0 350"),
"_mock_function : 110, 0, 350")
data.add_callback("", "alias", "d",
[
["_mock_function",
["arg", "1"], ["arg", "2"], ["arg", "3"]],
["_mock_function",
["arg", "2"], ["arg", "3"], ["arg", "1"]]
])
self.assertEqual(ashval.ashval("d 100 200 300"),
"_mock_function : 200, 300, 100")
self.assertEqual(ashval.ashval("d 110 0 350"),
"_mock_function : 0, 350, 110")
data.add_callback("", "alias", "d",
[
["_mock_function",
["arg", "1"], ["arg", "2"], ["arg", "3"]],
["c",
["arg", "2"], ["arg", "3"], ["arg", "1"]]
])
print data._callbacks[data.DEFAULT_EVENT_MODE]["alias"]
self.assertEqual(ashval.ashval("d 100 200 300"),
"_mock_function : 200, 300, 100")
self.assertEqual(ashval.ashval("d 110 0 350"),
"_mock_function : 0, 350, 110")
self.assertTrue(ashval.ashval("a b c [[d] [e]]"))
self.assertTrue(ashval.ashval("_mock_function [[d] [e]] f g"))
def test_record(self):
data.add_callback("", "alias", "c",
[
["_mock_function",
["arg", "1"], ["arg", "2"], ["arg", "3"]]
])
ashval.ashval("record abc")
ashval.ashval("c 100 200 300")
ashval.ashval("c 200 200 300")
ashval.ashval("c 100 200 300")
ashval.ashval("record_stop")
self.assertEqual(ashval.ashval("abc"),
"_mock_function : 100, 200, 300")
def test_event(self):
data.clear()
data.add_callback("", "typeB", "valueC",
[
["_mock_function",
["arg", "1"], ["arg", "2"], ["arg", "3"]]
])
self.assertEqual(ashval.ashval("event default typeB valueC 10 20 33"),
"_mock_function : 10, 20, 33")