diff --git a/src/test_text2diagram.py b/src/test_text2diagram.py index d39d8cf..106c548 100644 --- a/src/test_text2diagram.py +++ b/src/test_text2diagram.py @@ -14,10 +14,22 @@ def prep_for_test(filename: str): return os.path.join(path, filename) -def generate_diagram(input_syntax: str): - output_file = prep_for_test(f"{inspect.currentframe().f_back.f_code.co_name}.png") - gen_code, img = text2diagram.render(input_syntax, output_file, show_code=True) - img.save(output_file) +def generate_diagram(input_syntax: str, painter_type: str = "PNG"): + if painter_type == "PNG": + output_file = prep_for_test( + f"{inspect.currentframe().f_back.f_code.co_name}.png" + ) + else: + output_file = prep_for_test( + f"{inspect.currentframe().f_back.f_code.co_name}.svg" + ) + _, img = text2diagram.render(input_syntax, output_file, show_code=True) + if painter_type == "PNG": + img.save(output_file) + else: + # save gen_code as SVG file + with open(output_file, "w") as f: + f.write(img) def test_text2diagram_01(): @@ -371,8 +383,8 @@ def test_text2diagram_14(): footer: Generated by ProcessPiper """ - - generate_diagram(input_syntax) + generate_diagram(input_syntax, "PNG") + generate_diagram(input_syntax, "SVG") if __name__ == "__main__": @@ -396,4 +408,4 @@ def test_text2diagram_14(): print("Thank you for using ProcessPiper!") print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") print("XXXXXXXXXXXXXXXXXXXXXXXX") - print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")