From bdb4735d348b47bf39fdc8268c2c557732ab2d23 Mon Sep 17 00:00:00 2001 From: CS Goh Date: Mon, 12 Feb 2024 14:33:41 +1300 Subject: [PATCH] updated test cases --- src/test_text2diagram.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) 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")