2fbb4b66617c1a008f03f3be8b8079e734df20d7
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 add test with online testdata

Hanno Böck authored 4 years ago

30)                 shutil.unpack_archive(tarball, "%s/%s/%s-src"
31)                                       % (tmp, bdir, os.path.basename(tarball)))
32)             fwrun = subprocess.run(["./freewvs", "-a", tmp + "/" + bdir],
33)                                    stdout=subprocess.PIPE, check=True)
34)             fwdata = re.sub(tmp, "[dir]", fwrun.stdout.decode("utf-8"))
35)             fwclean = re.sub(r' \(.* ', " ", fwdata)
Hanno Böck avoid some pylint warnings

Hanno Böck authored 4 years ago

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

Hanno Böck authored 4 years ago

37)             refdata = f.read()
38)             f.close()
39)             refclean = re.sub(r' \(.* ', " ", refdata)
40)             fwclean = sorted(fwclean.split("\n"))
41)             refclean = sorted(refclean.split("\n"))
42)             if refclean != fwclean:
43)                 print("\n".join(difflib.ndiff(refclean, fwclean)))
Hanno Böck use assertEqual to make pyl...

Hanno Böck authored 4 years ago

44)             self.assertEqual(refclean, fwclean,
45)                              msg="Output in %s does not match" % bdir)
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 fix test - wrong bdir var here

Hanno Böck authored 3 years ago

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

Hanno Böck authored 3 years ago

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