Mercurial > hg > orthanc-stone
comparison Resources/CodeGeneration/stonegentool_test.py @ 494:fc17251477d6 bgo-commands-codegen
TS and CPP tests OK. Ongoing code for C++ program that reads list of serialized messages in N files. Requires conan
author | bgo-osimis |
---|---|
date | Sat, 23 Feb 2019 10:18:13 +0100 |
parents | 6fbf2eae7c88 |
children | 1dbf2d9ed1e4 |
comparison
equal
deleted
inserted
replaced
493:6fbf2eae7c88 | 494:fc17251477d6 |
---|---|
4 # | 4 # |
5 | 5 |
6 from stonegentool import \ | 6 from stonegentool import \ |
7 EatToken,SplitListOfTypes,ParseTemplateType,ProcessSchema, \ | 7 EatToken,SplitListOfTypes,ParseTemplateType,ProcessSchema, \ |
8 CheckSchemaSchema,LoadSchema,trim,ComputeRequiredDeclarationOrder, \ | 8 CheckSchemaSchema,LoadSchema,trim,ComputeRequiredDeclarationOrder, \ |
9 GetTemplatingDictFromSchemaFilename,MakeTemplate | 9 GetTemplatingDictFromSchemaFilename,MakeTemplate,MakeTemplateFromFile |
10 import unittest | 10 import unittest |
11 import os | 11 import os |
12 import re | 12 import re |
13 import pprint | 13 import pprint |
14 from jinja2 import Template | 14 from jinja2 import Template |
256 template = MakeTemplate(""" // end of generic methods | 256 template = MakeTemplate(""" // end of generic methods |
257 {% for struct in structs%} export class {{struct['name']}} { | 257 {% for struct in structs%} export class {{struct['name']}} { |
258 {% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key])}}; | 258 {% for key in struct['fields']%} {{key}}:{{CanonToTs(struct['fields'][key])}}; |
259 {% endfor %} | 259 {% endfor %} |
260 constructor() { | 260 constructor() { |
261 {% for key in struct['fields']%} {{key}} = new {{CanonToTs(struct['fields'][key])}}(); | 261 {% for key in struct['fields']%} this.{{key}} = new {{CanonToTs(struct['fields'][key])}}(); |
262 {% endfor %} } | 262 {% endfor %} } |
263 | 263 |
264 public StoneSerialize(): string { | 264 public StoneSerialize(): string { |
265 let container: object = {}; | 265 let container: object = {}; |
266 container['type'] = '{{rootName}}.{{struct['name']}}'; | 266 container['type'] = '{{rootName}}.{{struct['name']}}'; |
373 # print(renderedCode) | 373 # print(renderedCode) |
374 self.maxDiff = None | 374 self.maxDiff = None |
375 self.assertEqual(renderedCodeRef, renderedCode) | 375 self.assertEqual(renderedCodeRef, renderedCode) |
376 | 376 |
377 def test_generateWholeTsFile(self): | 377 def test_generateWholeTsFile(self): |
378 schemaFile = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') | 378 schemaFile = \ |
379 os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') | |
379 tdico = GetTemplatingDictFromSchemaFilename(schemaFile) | 380 tdico = GetTemplatingDictFromSchemaFilename(schemaFile) |
380 tsTemplateFile = os.path.join(os.path.dirname(__file__), 'test_data', 'test1.yaml') | 381 tsTemplateFile = \ |
382 os.path.join(os.path.dirname(__file__), 'template.in.ts') | |
381 template = MakeTemplateFromFile(tsTemplateFile) | 383 template = MakeTemplateFromFile(tsTemplateFile) |
382 renderedCode = template.render(**tdico) | 384 renderedCode = template.render(**tdico) |
383 | |
384 print(renderedCode) | 385 print(renderedCode) |
385 | 386 |
386 def test_GenerateTypeScriptHandlerInterface(self): | 387 def test_GenerateTypeScriptHandlerInterface(self): |
387 pass | 388 pass |
388 | 389 |