gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22819 - in gnunet: contrib src/fs


From: gnunet
Subject: [GNUnet-SVN] r22819 - in gnunet: contrib src/fs
Date: Sun, 22 Jul 2012 15:47:14 +0200

Author: LRN
Date: 2012-07-22 15:47:14 +0200 (Sun, 22 Jul 2012)
New Revision: 22819

Added:
   gnunet/contrib/pydiffer.py.in
Modified:
   gnunet/contrib/Makefile.am
   gnunet/src/fs/test_gnunet_fs_rec.py.in
Log:
Use Python batteries in fs_rec test

Modified: gnunet/contrib/Makefile.am
===================================================================
--- gnunet/contrib/Makefile.am  2012-07-22 13:47:09 UTC (rev 22818)
+++ gnunet/contrib/Makefile.am  2012-07-22 13:47:14 UTC (rev 22819)
@@ -14,6 +14,7 @@
 
 noinst_SCRIPTS = \
  terminate.py \
+ pydiffer.py \
  gnunet_pyexpect.py \
  gnunet_janitor.py
 
@@ -32,6 +33,7 @@
  terminate.py.in \
  gnunet_pyexpect.py.in \
  gnunet_janitor.py.in \
+ pydiffer.py.in \
  gnunet-gns-import.sh
 
 do_subst = $(SED) -e 's,address@hidden@],$(PYTHON),g'

Added: gnunet/contrib/pydiffer.py.in
===================================================================
--- gnunet/contrib/pydiffer.py.in                               (rev 0)
+++ gnunet/contrib/pydiffer.py.in       2012-07-22 13:47:14 UTC (rev 22819)
@@ -0,0 +1,39 @@
address@hidden@
+import os
+import sys
+import difflib
+import filecmp
+
+def getdiff (old, new):
+  diff = []
+  with open (old) as a:
+    with open (new) as b:
+      for l in difflib.unified_diff (a.read ().splitlines (), b.read 
().splitlines ()):
+        diff.append (l)
+  return diff
+
+def dc_getdiff (dc, old, new):
+  diff = []
+  for f in dc.left_only:
+    diff.append ("Only in {}: {}".format (old, f))
+  for f in dc.right_only:
+    diff.append ("Only in {}: {}".format (new, f))
+  for f in dc.diff_files:
+    r = getdiff (os.path.join (old, f), os.path.join (new, f))
+    diff.extend (r)
+  for dn, dc in dc.subdirs.items ():
+    r = dc_getdiff (dc, os.path.join (old, dn), os.path.join (new, dn))
+    diff.extend (r)
+  return diff
+
+def dcdiff (old, new):
+  dc = filecmp.dircmp (old, new)
+  diff = dc_getdiff (dc, old, new)
+  return diff
+
+def main ():
+  for l in dcdiff (sys.argv[1], sys.argv[2]):
+    print (l)
+
+if __name__ == '__main__':
+  main ()

Modified: gnunet/src/fs/test_gnunet_fs_rec.py.in
===================================================================
--- gnunet/src/fs/test_gnunet_fs_rec.py.in      2012-07-22 13:47:09 UTC (rev 
22818)
+++ gnunet/src/fs/test_gnunet_fs_rec.py.in      2012-07-22 13:47:14 UTC (rev 
22819)
@@ -23,6 +23,9 @@
 import subprocess
 import re
 import shutil
+import tarfile
+import filecmp
+import pydiffer
 
 srcdir = "../.."
 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
@@ -30,6 +33,7 @@
   sys.path.append (gnunet_pyexpect_dir)
 
 from gnunet_pyexpect import pexpect
+from pydiffer import dcdiff
 
 if os.name == 'posix':
   download = 'gnunet-download'
@@ -55,7 +59,8 @@
 arm.communicate ()
 
 # pray that `tar' is in PATH
-os.system ('tar xfz test_gnunet_fs_rec_data.tgz')
+tar = tarfile.open ('test_gnunet_fs_rec_data.tgz')
+tar.extractall ()
 # first, basic publish-search-download run
 try:
   pub = pexpect ()
@@ -93,8 +98,9 @@
 
   os.remove ("rdir/b.gnd")
   os.remove ("rdir/a.gnd")
-  if 0 != os.system ("diff -r dir rdir"):
-    raise Exception ("Unexpected difference between source directory and 
downloaded result")
+  diff = dcdiff ('dir', 'rdir')
+  if len (diff) != 0:
+    raise Exception ("Unexpected difference between source directory and 
downloaded result:\n{}".format (diff))
   
 
 finally:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]