Anonymous avatar Anonymous committed 90be228

Modified run_tests__test.py to use difflib.Differ().compare() to show any differences on failures.

Comments (0)

Files changed (1)

test/run_tests__tests/run_tests__test.py

-import subprocess, os, sys, re
+################################################################################
 
-DIFF_PROGRAM = r"H:\PortableApps\WinMergePortable\\WinMergePortable.exe"
+import subprocess, os, sys, re, difflib
+
+################################################################################
 
 IGNORE =  (
     '.svn',
     'infinite_loop',
 )
-
 NORMALIZERS = (
     (r"Ran (\d+) tests in (\d+\.\d+)s", "Ran XXX tests in X.XXXs" ),
     (r'File ".*?py",', 'File "XXXX.py",')  #TODO: look into why os.path.sep differs
 )
 
-main_dir  = os.path.split(os.path.abspath(sys.argv[0]))[0]
-trunk_dir = os.path.normpath(os.path.join(main_dir, '../../'))
+################################################################################
 
-test_suite_dirs = [x for x in os.listdir(main_dir) if os.path.isdir(x)
-                                                  and x not in IGNORE ]
 def norm_result(result):
     "normalize differences, such as timing between output"
-
     for normalizer, replacement in NORMALIZERS:
         result = re.sub(normalizer, replacement, result)
-
     return result
 
 def call_proc(cmd):
     assert not proc.wait()
     return proc.stdout.read()
 
-def str_2_file(f, s):
-    f = open(f, 'w')
-    try:
-        f.write(s)
-    finally:
-        f.close()
+################################################################################
 
-interactive = '-i' in sys.argv
-if interactive: 
-    print 'Running in interactive mode, will view diffs with %s' % DIFF_PROGRAM
+main_dir  = os.path.split(os.path.abspath(sys.argv[0]))[0]
+trunk_dir = os.path.normpath(os.path.join(main_dir, '../../'))
+
+test_suite_dirs = [x for x in os.listdir(main_dir) if os.path.isdir(x)
+                                                  and x not in IGNORE ]
+
+################################################################################
 
 single_cmd = "%s run_tests_sub.py -f %s"
 subprocess_cmd = single_cmd + ' -s'
     single = call_proc(single_cmd % (sys.executable, suite))
     subs = call_proc(subprocess_cmd % (sys.executable, suite))
 
-    normed_single = norm_result(single)
-    normed_subs = norm_result(subs)
+    normed_single, normed_subs = map(norm_result,(single, subs))
 
     if normed_single != normed_subs:
-        if interactive:
-            os.chdir(main_dir)
-            
-            single_file = "%s_single.txt" % suite
-            subs_file = "%s_subs.txt" % suite
-            
-            str_2_file(single_file, normed_single)
-            str_2_file(subs_file, normed_subs)
-            
-            subprocess.Popen([DIFF_PROGRAM, single_file, subs_file])
-            sys.exit()
-        else:
-            raise Exception("%s suite output not matching" % suite)
+        print '%s suite FAILED\n' % suite
+        print "difflib.Differ().compare(single, suprocessed):\n"
+        print ''.join ( list(
+            difflib.Differ().compare(
+                normed_single.splitlines(1),
+                normed_subs.splitlines(1)
+            ))
+        )
+    else:
+        print '%s suite OK' % suite
 
-print 'OK, output same'
+################################################################################
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.