comparison Resources/CodeGeneration/stonegentool_test.py @ 473:628941d63b8c bgo-commands-codegen

Ongoing work. Parsing tests work
author bgo-osimis
date Wed, 13 Feb 2019 12:07:00 +0100
parents 3db3289e1c25
children 38997ceb9bc6
comparison
equal deleted inserted replaced
472:3db3289e1c25 473:628941d63b8c
1 from stonegentool import EatToken 1 from stonegentool import EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema
2 import unittest 2 import unittest
3 import os
3 4
4 class TestStonegentool(unittest.TestCase): 5 class TestStonegentool(unittest.TestCase):
5 def test_EatToken_empty(self): 6 def test_EatToken_empty(self):
6 c = r"" 7 c = r""
7 a,b = EatToken(c) 8 a,b = EatToken(c)
33 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>") 34 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>")
34 a,b = EatToken(b) 35 a,b = EatToken(b)
35 self.assertEqual(a,r"map<int32,string>") 36 self.assertEqual(a,r"map<int32,string>")
36 self.assertEqual(b,r"map<map<int32,string>,string>") 37 self.assertEqual(b,r"map<map<int32,string>,string>")
37 38
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
38 # def test(self): 91 # def test(self):
39 # s = 'hello world' 92 # s = 'hello world'
40 # self.assertEqual(s.split(), ['hello', 'world']) 93 # self.assertEqual(s.split(), ['hello', 'world'])
41 # # check that s.split fails when the separator is not a string 94 # # check that s.split fails when the separator is not a string
42 # with self.assertRaises(TypeError): 95 # with self.assertRaises(TypeError):