add test with online testdata
Hanno Böck

Hanno Böck commited on 2019-12-13 10:46:01
Zeige 1 geänderte Dateien mit 49 Einfügungen und 0 Löschungen.

... ...
@@ -0,0 +1,49 @@
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):
14
+    @unittest.skipUnless(os.environ.get("FREEWVS_ONLINETESTS"),
15
+                         "Not running online tests")
16
+    def test_freewvs_testdata(self):
17
+        tmp = tempfile.mkdtemp(prefix="freewvs-testdata")
18
+        print(tmp)
19
+        if os.environ.get("FREEWVS_TESTDATA_REPOSITORY"):
20
+            os.symlink(os.environ.get("FREEWVS_TESTDATA_REPOSITORY"),
21
+                       tmp + "/freewvs-testdata")
22
+        else:
23
+            subprocess.run(["git", "clone", "--depth=1",
24
+                            TESTDATA_REPO,
25
+                            tmp + "/freewvs-testdata"],
26
+                           check=True)
27
+
28
+        for dir in glob.glob(tmp + "/freewvs-testdata/webapps/*"):
29
+            bdir = os.path.basename(dir)
30
+            for tarball in glob.glob(dir + "/dist/*"):
31
+                shutil.unpack_archive(tarball, "%s/%s/%s-src"
32
+                                      % (tmp, bdir, os.path.basename(tarball)))
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)
37
+            f = open(dir + "/refdata-a.txt")
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)))
45
+                raise Exception("Output in %s does not match" % bdir)
46
+
47
+
48
+if __name__ == '__main__':
49
+    unittest.main()
0 50