| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import os
- import sys
- import io
- from drawio2py import parser, abstract_syntax, generator
- import pprint
- import tempfile
- import unittest
- 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")
- class Tests(unittest.TestCase):
- def test_1(self):
- run_test("test.drawio")
- def test_2(self):
- run_test("overview.drawio") # we eat our own dog food :)
- def test_3(self):
- run_test("TrivialPM.drawio")
|