[PATCH 028 of 179 tests-refactor] run-tests: move fail() into Test

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 13:37:45 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397965268 25200
#      Sat Apr 19 20:41:08 2014 -0700
# Branch stable
# Node ID 3029253df56a97f5622b6383285182133e592994
# Parent  19a7cd2c17eea63d5ab3b1946aecdd2691222506
run-tests: move fail() into Test

The code was changed slightly as part of the migration to make use of
appropriate variables and modern Python conventions.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -671,16 +671,37 @@ class Test(object):
             if k.startswith('HG_'):
                 del env[k]
 
         return env
 
     def success(self):
         return '.', self._test, ''
 
+    def fail(self, msg, ret):
+        warned = ret is False
+        if not self._options.nodiff:
+            log("\n%s: %s %s" % (warned and 'Warning' or 'ERROR', self._test,
+                                 msg))
+        if (not ret and self._options.interactive and
+            os.path.exists(self._errpath)):
+            iolock.acquire()
+            print 'Accept this change? [n] ',
+            answer = sys.stdin.readline().strip()
+            iolock.release()
+            if answer.lower() in ('y', 'yes').split():
+                if self._test.endswith('.t'):
+                    rename(self._errpath, self._testpath)
+                else:
+                    rename(self._errpath, '%s.out' % self._testpath)
+
+                return '.', self._test, ''
+
+        return warned and '~' or '!', self._test, msg
+
 class TestResult(object):
     """Holds the result of a test execution."""
 
     def __init__(self):
         self.ret = None
         self.out = None
         self.duration = None
         self.exception = None
@@ -1027,34 +1048,16 @@ def run(cmd, wd, options, replacements, 
 def runone(options, test, count):
     '''returns a result element: (code, test, msg)'''
 
     def skip(msg):
         if options.verbose:
             log("\nSkipping %s: %s" % (testpath, msg))
         return 's', test, msg
 
-    def fail(msg, ret):
-        warned = ret is False
-        if not options.nodiff:
-            log("\n%s: %s %s" % (warned and 'Warning' or 'ERROR', test, msg))
-        if (not ret and options.interactive
-            and os.path.exists(testpath + ".err")):
-            iolock.acquire()
-            print "Accept this change? [n] ",
-            answer = sys.stdin.readline().strip()
-            iolock.release()
-            if answer.lower() in "y yes".split():
-                if test.endswith(".t"):
-                    rename(testpath + ".err", testpath)
-                else:
-                    rename(testpath + ".err", testpath + ".out")
-                return '.', test, ''
-        return warned and '~' or '!', test, msg
-
     def ignore(msg):
         return 'i', test, msg
 
     def describe(ret):
         if ret < 0:
             return 'killed by signal %d' % -ret
         return 'returned error code %d' % ret
 
@@ -1094,17 +1097,17 @@ def runone(options, test, count):
 
     vlog("# Test", test)
 
     t = runner(test, testpath, options, count, ref, err)
     res = TestResult()
     t.run(res)
 
     if res.exception:
-        return fail('Exception during execution: %s' % res.exception, 255)
+        return t.fail('Exception during execution: %s' % res.exception, 255)
 
     ret = res.ret
     out = res.out
 
     times.append((test, res.duration))
     vlog("# Ret was:", ret)
 
     skipped = res.skipped
@@ -1121,40 +1124,40 @@ def runone(options, test, count):
         if out is None:                 # debug mode: nothing to parse
             missing = ['unknown']
             failed = None
         else:
             missing, failed = parsehghaveoutput(out)
         if not missing:
             missing = ['irrelevant']
         if failed:
-            result = fail("hghave failed checking for %s" % failed[-1], ret)
+            result = t.fail("hghave failed checking for %s" % failed[-1], ret)
             skipped = False
         else:
             result = skip(missing[-1])
     elif ret == 'timeout':
-        result = fail("timed out", ret)
+        result = t.fail("timed out", ret)
     elif out != refout:
         info = {}
         if not options.nodiff:
             iolock.acquire()
             if options.view:
                 os.system("%s %s %s" % (options.view, ref, err))
             else:
                 info = showdiff(refout, out, ref, err)
             iolock.release()
         msg = ""
         if info.get('servefail'): msg += "serve failed and "
         if ret:
             msg += "output changed and " + describe(ret)
         else:
             msg += "output changed"
-        result = fail(msg, ret)
+        result = t.fail(msg, ret)
     elif ret:
-        result = fail(describe(ret), ret)
+        result = t.fail(describe(ret), ret)
     else:
         result = t.success()
 
     if not options.verbose:
         iolock.acquire()
         sys.stdout.write(result[0])
         sys.stdout.flush()
         iolock.release()


More information about the Mercurial-devel mailing list