473
|
1 from stonegentool import EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema
|
471
|
2 import unittest
|
473
|
3 import os
|
471
|
4
|
|
5 class TestStonegentool(unittest.TestCase):
|
|
6 def test_EatToken_empty(self):
|
|
7 c = r""
|
|
8 a,b = EatToken(c)
|
|
9 self.assertEqual(a,r"")
|
|
10 self.assertEqual(b,r"")
|
|
11
|
|
12 def test_EatToken_simpleNonTemplate(self):
|
|
13 c = r"int32"
|
|
14 a,b = EatToken(c)
|
|
15 self.assertEqual(a,r"int32")
|
|
16 self.assertEqual(b,r"")
|
|
17
|
|
18 def test_EatToken_simpleTemplate(self):
|
|
19 c = r"vector<string>"
|
|
20 a,b = EatToken(c)
|
|
21 self.assertEqual(a,r"vector<string>")
|
|
22 self.assertEqual(b,r"")
|
|
23
|
|
24 def test_EatToken_complexTemplate(self):
|
|
25 c = r"vector<map<int64,string>>,vector<map<int32,string>>"
|
|
26 a,b = EatToken(c)
|
|
27 self.assertEqual(a,r"vector<map<int64,string>>")
|
|
28 self.assertEqual(b,r"vector<map<int32,string>>")
|
|
29
|
472
|
30 def test_EatToken_complexTemplates(self):
|
471
|
31 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
|
|
32 a,b = EatToken(c)
|
|
33 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>")
|
|
34 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
|
|
35 a,b = EatToken(b)
|
|
36 self.assertEqual(a,r"map<int32,string>")
|
|
37 self.assertEqual(b,r"map<map<int32,string>,string>")
|
|
38
|
473
|
39 def test_SplitListOfTypes(self):
|
|
40 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
|
|
41 lot = SplitListOfTypes(c)
|
|
42 self.assertEqual(3,len(lot))
|
|
43 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
|
|
44 self.assertEqual("map<int32,string>",lot[1])
|
|
45 self.assertEqual("map<map<int32,string>,string>",lot[2])
|
|
46
|
|
47 def test_SplitListOfTypes_bogus(self):
|
|
48 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string"
|
|
49 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes
|
|
50
|
|
51 def test_ParseTemplateType_true(self):
|
|
52 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
|
|
53 (ok,a,b) = ParseTemplateType(c)
|
|
54 self.assertEqual(ok,True)
|
|
55 self.assertEqual(a,"map")
|
|
56 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"])
|
|
57
|
|
58 (ok2,a2,b2) = ParseTemplateType(b[0])
|
|
59 self.assertEqual(ok2,True)
|
|
60 self.assertEqual(a2,"vector")
|
|
61 self.assertEqual(b2,["map<int,vector<string>>"])
|
|
62
|
|
63 (ok3,a3,b3) = ParseTemplateType(b[1])
|
|
64 self.assertEqual(ok3,True)
|
|
65 self.assertEqual(a3,"map")
|
|
66 self.assertEqual(b3,["vector<int>","vector<string>"])
|
|
67
|
|
68 (ok4,a4,b4) = ParseTemplateType(b2[0])
|
|
69 self.assertEqual(ok4,True)
|
|
70 self.assertEqual(a4,"map")
|
|
71 self.assertEqual(b4,["int","vector<string>"])
|
|
72
|
|
73 def test_ParseSchema(self):
|
|
74 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
|
|
75 obj = LoadSchema(fn)
|
|
76 # we're happy if it does not crash
|
|
77 CheckSchemaSchema(obj)
|
|
78
|
|
79 def test_ParseSchema_bogus_json(self):
|
|
80 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
|
|
81 self.assertRaises(Exception,LoadSchema,fn)
|
|
82
|
|
83 def test_ParseSchema_bogus_schema(self):
|
|
84 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
|
|
85 obj = LoadSchema(fn)
|
|
86 self.assertRaises(Exception,CheckSchemaSchema,obj)
|
|
87
|
|
88
|
|
89
|
|
90
|
472
|
91 # def test(self):
|
471
|
92 # s = 'hello world'
|
|
93 # self.assertEqual(s.split(), ['hello', 'world'])
|
|
94 # # check that s.split fails when the separator is not a string
|
|
95 # with self.assertRaises(TypeError):
|
|
96 # s.split(2)
|
|
97
|
|
98 if __name__ == '__main__':
|
|
99 unittest.main() |