33from twiml_generator import TwimlCodeGenerator , load_language_spec
44from pathlib import Path
55from lxml import etree
6+ from contextlib import suppress
67
78import argparse
89import shutil
910import subprocess
1011
1112LANGUAGES_VERSIONS = {
1213 'python' : '6.x' ,
13- 'java' : '7 .x' ,
14+ 'java' : '8 .x' ,
1415 'csharp' : '5.x' ,
1516 'node' : '3.x' ,
1617 'php' : '5.x' ,
@@ -25,7 +26,7 @@ def generate_code_sample_filepath(twiml_filepath, language):
2526 language_spec = load_language_spec (language )
2627 version = LANGUAGES_VERSIONS [language ]
2728 return twiml_filepath .parent .parent / (
28- twiml_filepath .name [: - 5 ] + version + language_spec ['extension' ]
29+ twiml_filepath .parent . parent . name + '.' + version + language_spec ['extension' ]
2930 )
3031
3132
@@ -56,6 +57,7 @@ def generate_code_sample_filepath(twiml_filepath, language):
5657 languages = args .languages
5758
5859 filepaths = Path (args .root_twiml_filepath ).glob ('**/*.twiml' )
60+ ok = failed = error = 0
5961 for twiml_filepath in filepaths :
6062 try :
6163 for language in languages :
@@ -80,18 +82,24 @@ def generate_code_sample_filepath(twiml_filepath, language):
8082 code_generator .write_code ()
8183
8284 if args .test :
83- result , stdout , input_tree , output_tree = code_generator .verify (
84- )
85+ result , stdout , input_tree , output_tree = code_generator .verify ()
8586 if result == TwimlCodeGenerator .VERIFY_SUCCESS :
8687 print (' \x1B [92m[passed]\x1B [39m' )
87- elif result == TwimlCodeGenerator .VERIFY_FAILURE :
88- print (' \x1B [91m[failed]\x1B [39m' )
89- print ('INPUT:\n ' + input_tree )
90- print ('OUTPUT:\n ' + output_tree )
88+ ok += 1
9189 else :
92- print (' \x1B [91m[error]\x1B [39m' )
93- print (stdout )
90+ with suppress (IOError ):
91+ code_generator .code_filepath .unlink ()
92+ if result == TwimlCodeGenerator .VERIFY_FAILURE :
93+ print (' \x1B [91m[failed]\x1B [39m' )
94+ print ('INPUT:\n ' + input_tree )
95+ print ('OUTPUT:\n ' + output_tree )
96+ failed += 1
97+ else :
98+ print (' \x1B [91m[error]\x1B [39m' )
99+ print (stdout )
100+ error += 1
94101 else :
95102 print ('' )
96103 except etree .XMLSyntaxError as e :
97104 print ('\n Error parsing : {}' .format (twiml_filepath ))
105+ print (f'Total: { ok + error + failed } , Ok: { ok } , Failed: { failed } , Error: { error } ' )
0 commit comments