diff options
-rw-r--r-- | contrib/Makefile.am | 2 | ||||
-rw-r--r-- | contrib/pydiffer.py.in | 39 | ||||
-rwxr-xr-x | src/fs/test_gnunet_fs_rec.py.in | 12 |
3 files changed, 50 insertions, 3 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index aaab287a8..6a6c1e7ab 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am | |||
@@ -14,6 +14,7 @@ endif | |||
14 | 14 | ||
15 | noinst_SCRIPTS = \ | 15 | noinst_SCRIPTS = \ |
16 | terminate.py \ | 16 | terminate.py \ |
17 | pydiffer.py \ | ||
17 | gnunet_pyexpect.py \ | 18 | gnunet_pyexpect.py \ |
18 | gnunet_janitor.py | 19 | gnunet_janitor.py |
19 | 20 | ||
@@ -32,6 +33,7 @@ EXTRA_DIST = \ | |||
32 | terminate.py.in \ | 33 | terminate.py.in \ |
33 | gnunet_pyexpect.py.in \ | 34 | gnunet_pyexpect.py.in \ |
34 | gnunet_janitor.py.in \ | 35 | gnunet_janitor.py.in \ |
36 | pydiffer.py.in \ | ||
35 | gnunet-gns-import.sh | 37 | gnunet-gns-import.sh |
36 | 38 | ||
37 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | 39 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' |
diff --git a/contrib/pydiffer.py.in b/contrib/pydiffer.py.in new file mode 100644 index 000000000..23d546b25 --- /dev/null +++ b/contrib/pydiffer.py.in | |||
@@ -0,0 +1,39 @@ | |||
1 | #!@PYTHON@ | ||
2 | import os | ||
3 | import sys | ||
4 | import difflib | ||
5 | import filecmp | ||
6 | |||
7 | def getdiff (old, new): | ||
8 | diff = [] | ||
9 | with open (old) as a: | ||
10 | with open (new) as b: | ||
11 | for l in difflib.unified_diff (a.read ().splitlines (), b.read ().splitlines ()): | ||
12 | diff.append (l) | ||
13 | return diff | ||
14 | |||
15 | def dc_getdiff (dc, old, new): | ||
16 | diff = [] | ||
17 | for f in dc.left_only: | ||
18 | diff.append ("Only in {}: {}".format (old, f)) | ||
19 | for f in dc.right_only: | ||
20 | diff.append ("Only in {}: {}".format (new, f)) | ||
21 | for f in dc.diff_files: | ||
22 | r = getdiff (os.path.join (old, f), os.path.join (new, f)) | ||
23 | diff.extend (r) | ||
24 | for dn, dc in dc.subdirs.items (): | ||
25 | r = dc_getdiff (dc, os.path.join (old, dn), os.path.join (new, dn)) | ||
26 | diff.extend (r) | ||
27 | return diff | ||
28 | |||
29 | def dcdiff (old, new): | ||
30 | dc = filecmp.dircmp (old, new) | ||
31 | diff = dc_getdiff (dc, old, new) | ||
32 | return diff | ||
33 | |||
34 | def main (): | ||
35 | for l in dcdiff (sys.argv[1], sys.argv[2]): | ||
36 | print (l) | ||
37 | |||
38 | if __name__ == '__main__': | ||
39 | main () | ||
diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in index e86bb0ab2..09e55c144 100755 --- a/src/fs/test_gnunet_fs_rec.py.in +++ b/src/fs/test_gnunet_fs_rec.py.in | |||
@@ -23,6 +23,9 @@ import os | |||
23 | import subprocess | 23 | import subprocess |
24 | import re | 24 | import re |
25 | import shutil | 25 | import shutil |
26 | import tarfile | ||
27 | import filecmp | ||
28 | import pydiffer | ||
26 | 29 | ||
27 | srcdir = "../.." | 30 | srcdir = "../.." |
28 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") | 31 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib") |
@@ -30,6 +33,7 @@ if gnunet_pyexpect_dir not in sys.path: | |||
30 | sys.path.append (gnunet_pyexpect_dir) | 33 | sys.path.append (gnunet_pyexpect_dir) |
31 | 34 | ||
32 | from gnunet_pyexpect import pexpect | 35 | from gnunet_pyexpect import pexpect |
36 | from pydiffer import dcdiff | ||
33 | 37 | ||
34 | if os.name == 'posix': | 38 | if os.name == 'posix': |
35 | download = 'gnunet-download' | 39 | download = 'gnunet-download' |
@@ -55,7 +59,8 @@ arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf'] | |||
55 | arm.communicate () | 59 | arm.communicate () |
56 | 60 | ||
57 | # pray that `tar' is in PATH | 61 | # pray that `tar' is in PATH |
58 | os.system ('tar xfz test_gnunet_fs_rec_data.tgz') | 62 | tar = tarfile.open ('test_gnunet_fs_rec_data.tgz') |
63 | tar.extractall () | ||
59 | # first, basic publish-search-download run | 64 | # first, basic publish-search-download run |
60 | try: | 65 | try: |
61 | pub = pexpect () | 66 | pub = pexpect () |
@@ -93,8 +98,9 @@ try: | |||
93 | 98 | ||
94 | os.remove ("rdir/b.gnd") | 99 | os.remove ("rdir/b.gnd") |
95 | os.remove ("rdir/a.gnd") | 100 | os.remove ("rdir/a.gnd") |
96 | if 0 != os.system ("diff -r dir rdir"): | 101 | diff = dcdiff ('dir', 'rdir') |
97 | raise Exception ("Unexpected difference between source directory and downloaded result") | 102 | if len (diff) != 0: |
103 | raise Exception ("Unexpected difference between source directory and downloaded result:\n{}".format (diff)) | ||
98 | 104 | ||
99 | 105 | ||
100 | finally: | 106 | finally: |