annotate Resources/CodeGeneration/stonegentool_test.py @ 474:38997ceb9bc6 bgo-commands-codegen

Ongoing work on message code generation
author bgo-osimis
date Wed, 13 Feb 2019 20:42:26 +0100
parents 628941d63b8c
children f58fe38c8c04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
1 from stonegentool import \
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
3 import unittest
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
4 import os
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
5
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
6 class TestStonegentool(unittest.TestCase):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
7 def test_EatToken_empty(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
8 c = r""
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
9 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
10 self.assertEqual(a,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
11 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
12
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
13 def test_EatToken_simpleNonTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
14 c = r"int32"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
15 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
16 self.assertEqual(a,r"int32")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
17 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
18
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
19 def test_EatToken_simpleTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
20 c = r"vector<string>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
21 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
22 self.assertEqual(a,r"vector<string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
23 self.assertEqual(b,r"")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
24
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
25 def test_EatToken_complexTemplate(self):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
26 c = r"vector<map<int64,string>>,vector<map<int32,string>>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
27 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
28 self.assertEqual(a,r"vector<map<int64,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
29 self.assertEqual(b,r"vector<map<int32,string>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
30
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
31 def test_EatToken_complexTemplates(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
32 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
33 a,b = EatToken(c)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
34 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
35 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
36 a,b = EatToken(b)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
37 self.assertEqual(a,r"map<int32,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
38 self.assertEqual(b,r"map<map<int32,string>,string>")
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
39
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
40 def test_SplitListOfTypes(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
41 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
42 lot = SplitListOfTypes(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
43 self.assertEqual(3,len(lot))
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
44 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
45 self.assertEqual("map<int32,string>",lot[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
46 self.assertEqual("map<map<int32,string>,string>",lot[2])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
47
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
48 def test_SplitListOfTypes_bogus(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
49 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
50 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
51
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
52 def test_ParseTemplateType_true(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
53 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>"
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
54 (ok,a,b) = ParseTemplateType(c)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
55 self.assertEqual(ok,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
56 self.assertEqual(a,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
57 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
58
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
59 (ok2,a2,b2) = ParseTemplateType(b[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
60 self.assertEqual(ok2,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
61 self.assertEqual(a2,"vector")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
62 self.assertEqual(b2,["map<int,vector<string>>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
63
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
64 (ok3,a3,b3) = ParseTemplateType(b[1])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
65 self.assertEqual(ok3,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
66 self.assertEqual(a3,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
67 self.assertEqual(b3,["vector<int>","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
68
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
69 (ok4,a4,b4) = ParseTemplateType(b2[0])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
70 self.assertEqual(ok4,True)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
71 self.assertEqual(a4,"map")
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
72 self.assertEqual(b4,["int","vector<string>"])
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
73
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
74 def test_ParseSchema(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
75 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
76 obj = LoadSchema(fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
77 # we're happy if it does not crash
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
78 CheckSchemaSchema(obj)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
79
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
80 def test_ParseSchema_bogus_json(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
81 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
82 self.assertRaises(Exception,LoadSchema,fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
83
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
84 def test_ParseSchema_bogus_schema(self):
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
85 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc')
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
86 obj = LoadSchema(fn)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
87 self.assertRaises(Exception,CheckSchemaSchema,obj)
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
88
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
89 def test_GenOrderQueue(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
90 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc')
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
91 obj = LoadSchema(fn)
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
92 genOrderQueue,structTypes = ProcessSchema(obj)
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
93 print(f"genOrderQueue = {genOrderQueue}")
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
94 print("")
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
95
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
96 def test_GenerateTypeScriptEnumeration(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
97 pass
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
98
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
99 def test_GenerateCppEnumeration(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
100 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
101
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
102 def test_GenerateTypeScriptClasses(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
103 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
104
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
105 def test_GenerateCppClasses(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
106 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
107
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
108 def test_GenerateTypeScriptHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
109 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
110
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
111 def test_GenerateCppHandlerInterface(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
112 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
113
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
114 def test_GenerateTypeScriptDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
115 pass
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
116
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
117 def test_GenerateCppDispatcher(self):
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
118 pass
473
628941d63b8c Ongoing work. Parsing tests work
bgo-osimis
parents: 472
diff changeset
119
472
3db3289e1c25 Ongoing codegen work
bgo-osimis
parents: 471
diff changeset
120 # def test(self):
471
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
121 # s = 'hello world'
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
122 # self.assertEqual(s.split(), ['hello', 'world'])
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
123 # # check that s.split fails when the separator is not a string
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
124 # with self.assertRaises(TypeError):
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
125 # s.split(2)
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
126
125c19b294e3 Ongoing codegen work
bgo-osimis
parents:
diff changeset
127 if __name__ == '__main__':
474
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
128 print("")
38997ceb9bc6 Ongoing work on message code generation
bgo-osimis
parents: 473
diff changeset
129 unittest.main()