tests/test_freewvs_testdata.py
c58390b3
 import unittest
 import subprocess
 import glob
 import os
 import tempfile
 import shutil
 import re
 import difflib
 
 TESTDATA_REPO = "https://github.com/schokokeksorg/freewvs-testdata"
 
 
 class TestFreewvsData(unittest.TestCase):
2fd68dea
     @unittest.skipUnless(os.environ.get("RUN_ONLINETESTS"),
c58390b3
                          "Not running online tests")
     def test_freewvs_testdata(self):
2fd68dea
         tmp = tempfile.mkdtemp(prefix="testdata")
         if os.environ.get("TESTDATA_REPOSITORY"):
             os.symlink(os.environ.get("TESTDATA_REPOSITORY"),
                        tmp + "/testdata")
c58390b3
         else:
             subprocess.run(["git", "clone", "--depth=1",
                             TESTDATA_REPO,
2fd68dea
                             tmp + "/testdata"],
c58390b3
                            check=True)
 
9d80e030
         #for tdir in glob.glob(tmp + "/testdata/webapps/*"):
         if 0:
0aeada3c
             bdir = os.path.basename(tdir)
             for tarball in glob.glob(tdir + "/dist/*"):
c58390b3
                 shutil.unpack_archive(tarball, "%s/%s/%s-src"
                                       % (tmp, bdir, os.path.basename(tarball)))
             fwrun = subprocess.run(["./freewvs", "-a", tmp + "/" + bdir],
                                    stdout=subprocess.PIPE, check=True)
             fwdata = re.sub(tmp, "[dir]", fwrun.stdout.decode("utf-8"))
             fwclean = re.sub(r' \(.* ', " ", fwdata)
0aeada3c
             f = open(tdir + "/refdata-a.txt")
c58390b3
             refdata = f.read()
             f.close()
             refclean = re.sub(r' \(.* ', " ", refdata)
             fwclean = sorted(fwclean.split("\n"))
             refclean = sorted(refclean.split("\n"))
             if refclean != fwclean:
                 print("\n".join(difflib.ndiff(refclean, fwclean)))
bb76e0d0
             self.assertEqual(refclean, fwclean,
                              msg="Output in %s does not match" % bdir)
c58390b3
 
ce1f5387
         # misc tests, for read errors, garbage data etc.
9d80e030
         subprocess.run(["./freewvs", "-a", tmp + "/testdata/misc/"],
ce1f5387
                        stdout=subprocess.PIPE, check=True)
 
c58390b3
 
 if __name__ == '__main__':
     unittest.main()