master
Hanno Böck Use isort-style import sorting

Hanno Böck authored 5 months ago

1) import difflib
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

2) import glob
3) import os
4) import re
Hanno Böck Use isort-style import sorting

Hanno Böck authored 5 months ago

5) import shutil
6) import subprocess
Hanno Böck Use filter argument with sh...

Hanno Böck authored 5 months ago

7) import sys
Hanno Böck Use isort-style import sorting

Hanno Böck authored 5 months ago

8) import tempfile
9) import unittest
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

10) 
11) TESTDATA_REPO = "https://github.com/schokokeksorg/freewvs-testdata"
12) 
13) 
14) class TestFreewvsData(unittest.TestCase):
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

15)     @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

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"):
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

20)         else:
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

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

Hanno Böck authored 2 years ago

29)                 tname = os.path.basename(tarball)
Hanno Böck Use filter argument with sh...

Hanno Böck authored 5 months ago

30)                 if sys.version_info < (3, 12) or tarball.endswith(".zip"):
31)                     shutil.unpack_archive(tarball, f"{tmp}/{bdir}/{tname}-src")
32)                 else:
33)                     shutil.unpack_archive(
34)                         tarball, f"{tmp}/{bdir}/{tname}-src", filter="data"
35)                     )
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

36)             fwrun = subprocess.run(
37)                 ["./freewvs", "-a", tmp + "/" + bdir],
38)                 stdout=subprocess.PIPE,
39)                 check=True,
40)             )
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

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

Hanno Böck authored 1 year ago

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

Hanno Böck authored 2 years ago

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

Hanno Böck authored 4 years ago

44)             refdata = f.read()
45)             f.close()
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

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

Hanno Böck authored 4 years ago

47)             fwclean = sorted(fwclean.split("\n"))
48)             refclean = sorted(refclean.split("\n"))
49)             if refclean != fwclean:
50)                 print("\n".join(difflib.ndiff(refclean, fwclean)))
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

51)             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

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

Hanno Böck authored 3 years ago

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

Hanno Böck authored 1 year ago

54)         subprocess.run(
55)             ["./freewvs", "-a", tmp + "/testdata/misc/"],
56)             stdout=subprocess.PIPE,
57)             check=True,
58)         )
Hanno Böck run misc tests from testdat...

Hanno Böck authored 3 years ago

59) 
Hanno Böck add test with online testdata

Hanno Böck authored 4 years ago

60) 
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

61) if __name__ == "__main__":