d378a65b5e90b6448eb775d3256b643a55c83389
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 make test var names more ge...

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

15)                          "Not running online tests")
16)     def test_freewvs_testdata(self):
Hanno Böck make test var names more ge...

Hanno Böck authored 3 years ago

17)         tmp = tempfile.mkdtemp(prefix="testdata")
18)         if os.environ.get("TESTDATA_REPOSITORY"):
19)             os.symlink(os.environ.get("TESTDATA_REPOSITORY"),
20)                        tmp + "/testdata")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

21)         else:
22)             subprocess.run(["git", "clone", "--depth=1",
23)                             TESTDATA_REPO,
Hanno Böck make test var names more ge...

Hanno Böck authored 3 years ago

24)                             tmp + "/testdata"],
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

25)                            check=True)
26) 
Hanno Böck accidentally disabled most...

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 2 years ago

30)                 tname = os.path.basename(tarball)
31)                 shutil.unpack_archive(tarball,
32)                                       f"{tmp}/{bdir}/{tname}-src")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

33)             fwrun = subprocess.run(["./freewvs", "-a", tmp + "/" + bdir],
34)                                    stdout=subprocess.PIPE, check=True)
35)             fwdata = re.sub(tmp, "[dir]", fwrun.stdout.decode("utf-8"))
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()
40)             refclean = re.sub(r' \(.* ', " ", refdata)
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 assertEqual to make pyl...

Hanno Böck authored 4 years ago

45)             self.assertEqual(refclean, fwclean,
Hanno Böck fix f-strings in tests

Hanno Böck authored 2 years ago

46)                              msg=f"Output in {bdir} does not match")
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

48)         # misc tests, for read errors, garbage data etc.
Hanno Böck fix test - wrong bdir var here

Hanno Böck authored 3 years ago

49)         subprocess.run(["./freewvs", "-a", tmp + "/testdata/misc/"],
Hanno Böck run misc tests from testdat...

Hanno Böck authored 3 years ago

50)                        stdout=subprocess.PIPE, check=True)
51)