| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import os
- import sys
- import io
- from drawio2py import parser, abstract_syntax, generator
- import pprint
- import tempfile
- if __name__ == "__main__":
- DATADIR = os.path.join(os.path.dirname(__file__), "data")
- class DummyOutput:
- def write(self, text: str):
- # sys.stdout.write(text)
- pass
- def run_test(filename):
- # Parse (1st time):
- asyntax = parser.Parser.parse(os.path.join(DATADIR,filename))
- # Print abstract syntax:
- # pprint.pprint(asyntax, indent=2, compact=True)
- # Generate .drawio (1st time):
- csyntax = io.BytesIO()
- generator.generate(asyntax, csyntax)
- csyntax.seek(0)
- # Print generated .drawio
- # print(csyntax.getvalue())
- # Parse (2nd time):
- asyntax2 = parser.Parser.parse(csyntax)
- # Generate .drawio (2nd time):
- csyntax2 = io.BytesIO()
- generator.generate(asyntax2, csyntax2)
- csyntax2.seek(0)
- if (csyntax.getvalue() != csyntax2.getvalue()):
- # print(csyntax.getvalue())
- # print(csyntax2.getvalue())
- raise Exception("Files differ after round-trip!")
-
- print(filename, "OK")
- # Just see if these files parse without throwing an exception :)
- run_test("test.drawio")
- run_test("overview.drawio") # we eat our own dog food :)
- print("Tests passed.")
|