a3e985fc81e20c7b7c001a379384a2336ee246d3
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

1) import unittest
2) import subprocess
3) import glob
4) import os
5) import tempfile
6) import shutil
7) import re
8) import difflib
9) 
10) TESTDATA_REPO = "https://github.com/schokokeksorg/freewvs-testdata"
11) 
12) 
13) class TestFreewvsData(unittest.TestCase):
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

14)     @unittest.skipUnless(os.environ.get("RUN_ONLINETESTS"), "Not running online tests")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

15)     def test_freewvs_testdata(self):
Hanno Böck make test var names more ge...

Hanno Böck authored 3 years ago

16)         tmp = tempfile.mkdtemp(prefix="testdata")
17)         if os.environ.get("TESTDATA_REPOSITORY"):
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

18)             os.symlink(os.environ.get("TESTDATA_REPOSITORY"), tmp + "/testdata")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

19)         else:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

20)             subprocess.run(
21)                 ["git", "clone", "--depth=1", TESTDATA_REPO, tmp + "/testdata"],
22)                 check=True,
23)             )
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

24) 
Hanno Böck accidentally disabled most...

Hanno Böck authored 3 years ago

25)         for tdir in glob.glob(tmp + "/testdata/webapps/*"):
Hanno Böck avoid some pylint warnings

Hanno Böck authored 4 years ago

26)             bdir = os.path.basename(tdir)
27)             for tarball in glob.glob(tdir + "/dist/*"):
Hanno Böck fix f-strings in tests

Hanno Böck authored 2 years ago

28)                 tname = os.path.basename(tarball)
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

29)                 shutil.unpack_archive(tarball, f"{tmp}/{bdir}/{tname}-src")
30)             fwrun = subprocess.run(
31)                 ["./freewvs", "-a", tmp + "/" + bdir],
32)                 stdout=subprocess.PIPE,
33)                 check=True,
34)             )
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

35)             fwdata = re.sub(tmp, "[dir]", fwrun.stdout.decode("utf-8"))
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

36)             fwclean = re.sub(r" \(.* ", " ", fwdata)
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

37)             f = open(tdir + "/refdata-a.txt", encoding="ascii")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

38)             refdata = f.read()
39)             f.close()
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

40)             refclean = re.sub(r" \(.* ", " ", refdata)
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

41)             fwclean = sorted(fwclean.split("\n"))
42)             refclean = sorted(refclean.split("\n"))
43)             if refclean != fwclean:
44)                 print("\n".join(difflib.ndiff(refclean, fwclean)))
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

45)             self.assertEqual(refclean, fwclean, msg=f"Output in {bdir} does not match")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

46) 
Hanno Böck run misc tests from testdat...

Hanno Böck authored 3 years ago

47)         # misc tests, for read errors, garbage data etc.
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

48)         subprocess.run(
49)             ["./freewvs", "-a", tmp + "/testdata/misc/"],
50)             stdout=subprocess.PIPE,
51)             check=True,
52)         )
Hanno Böck run misc tests from testdat...

Hanno Böck authored 3 years ago

53) 
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

54) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

55) if __name__ == "__main__":