##// END OF EJS Templates
python3: update killdaemons and run-tests print and exception syntax...
Augie Fackler -
r25031:0adc22a0 default
parent child Browse files
Show More
@@ -64,7 +64,7 b' else:'
64 os.kill(pid, 0)
64 os.kill(pid, 0)
65 logfn('# Daemon process %d is stuck - really killing it' % pid)
65 logfn('# Daemon process %d is stuck - really killing it' % pid)
66 os.kill(pid, signal.SIGKILL)
66 os.kill(pid, signal.SIGKILL)
67 except OSError, err:
67 except OSError as err:
68 if err.errno != errno.ESRCH:
68 if err.errno != errno.ESRCH:
69 raise
69 raise
70
70
@@ -41,6 +41,8 b''
41 # completes fairly quickly, includes both shell and Python scripts, and
41 # completes fairly quickly, includes both shell and Python scripts, and
42 # includes some scripts that run daemon processes.)
42 # includes some scripts that run daemon processes.)
43
43
44 from __future__ import print_function
45
44 from distutils import version
46 from distutils import version
45 import difflib
47 import difflib
46 import errno
48 import errno
@@ -57,7 +59,10 b' import random'
57 import re
59 import re
58 import threading
60 import threading
59 import killdaemons as killmod
61 import killdaemons as killmod
60 import Queue as queue
62 try:
63 import Queue as queue
64 except ImportError:
65 import queue
61 from xml.dom import minidom
66 from xml.dom import minidom
62 import unittest
67 import unittest
63
68
@@ -86,7 +91,7 b' def checkportisavailable(port):'
86 s.bind(('localhost', port))
91 s.bind(('localhost', port))
87 s.close()
92 s.close()
88 return True
93 return True
89 except socket.error, exc:
94 except socket.error as exc:
90 if not exc.errno == errno.EADDRINUSE:
95 if not exc.errno == errno.EADDRINUSE:
91 raise
96 raise
92 return False
97 return False
@@ -135,11 +140,11 b' def parselistfiles(files, listtype, warn'
135 try:
140 try:
136 path = os.path.expanduser(os.path.expandvars(filename))
141 path = os.path.expanduser(os.path.expandvars(filename))
137 f = open(path, "rb")
142 f = open(path, "rb")
138 except IOError, err:
143 except IOError as err:
139 if err.errno != errno.ENOENT:
144 if err.errno != errno.ENOENT:
140 raise
145 raise
141 if warn:
146 if warn:
142 print "warning: no such %s file: %s" % (listtype, filename)
147 print("warning: no such %s file: %s" % (listtype, filename))
143 continue
148 continue
144
149
145 for line in f.readlines():
150 for line in f.readlines():
@@ -358,10 +363,10 b' def log(*msg):'
358 """
363 """
359 iolock.acquire()
364 iolock.acquire()
360 if verbose:
365 if verbose:
361 print verbose,
366 print(verbose, end=' ')
362 for m in msg:
367 for m in msg:
363 print m,
368 print(m, end=' ')
364 print
369 print()
365 sys.stdout.flush()
370 sys.stdout.flush()
366 iolock.release()
371 iolock.release()
367
372
@@ -475,7 +480,7 b' class Test(unittest.TestCase):'
475
480
476 try:
481 try:
477 os.mkdir(self._threadtmp)
482 os.mkdir(self._threadtmp)
478 except OSError, e:
483 except OSError as e:
479 if e.errno != errno.EEXIST:
484 if e.errno != errno.EEXIST:
480 raise
485 raise
481
486
@@ -487,7 +492,7 b' class Test(unittest.TestCase):'
487 if os.path.exists(self.errpath):
492 if os.path.exists(self.errpath):
488 try:
493 try:
489 os.remove(self.errpath)
494 os.remove(self.errpath)
490 except OSError, e:
495 except OSError as e:
491 # We might have raced another test to clean up a .err
496 # We might have raced another test to clean up a .err
492 # file, so ignore ENOENT when removing a previous .err
497 # file, so ignore ENOENT when removing a previous .err
493 # file.
498 # file.
@@ -517,20 +522,20 b' class Test(unittest.TestCase):'
517 except KeyboardInterrupt:
522 except KeyboardInterrupt:
518 self._aborted = True
523 self._aborted = True
519 raise
524 raise
520 except SkipTest, e:
525 except SkipTest as e:
521 result.addSkip(self, str(e))
526 result.addSkip(self, str(e))
522 # The base class will have already counted this as a
527 # The base class will have already counted this as a
523 # test we "ran", but we want to exclude skipped tests
528 # test we "ran", but we want to exclude skipped tests
524 # from those we count towards those run.
529 # from those we count towards those run.
525 result.testsRun -= 1
530 result.testsRun -= 1
526 except IgnoreTest, e:
531 except IgnoreTest as e:
527 result.addIgnore(self, str(e))
532 result.addIgnore(self, str(e))
528 # As with skips, ignores also should be excluded from
533 # As with skips, ignores also should be excluded from
529 # the number of tests executed.
534 # the number of tests executed.
530 result.testsRun -= 1
535 result.testsRun -= 1
531 except WarnTest, e:
536 except WarnTest as e:
532 result.addWarn(self, str(e))
537 result.addWarn(self, str(e))
533 except self.failureException, e:
538 except self.failureException as e:
534 # This differs from unittest in that we don't capture
539 # This differs from unittest in that we don't capture
535 # the stack trace. This is for historical reasons and
540 # the stack trace. This is for historical reasons and
536 # this decision could be revisited in the future,
541 # this decision could be revisited in the future,
@@ -873,7 +878,7 b' class TTest(Test):'
873 if wifexited(ret):
878 if wifexited(ret):
874 ret = os.WEXITSTATUS(ret)
879 ret = os.WEXITSTATUS(ret)
875 if ret == 2:
880 if ret == 2:
876 print stdout
881 print(stdout)
877 sys.exit(1)
882 sys.exit(1)
878
883
879 return ret == 0
884 return ret == 0
@@ -1621,7 +1626,7 b' class TestRunner(object):'
1621
1626
1622 def run(self, args, parser=None):
1627 def run(self, args, parser=None):
1623 """Run the test suite."""
1628 """Run the test suite."""
1624 oldmask = os.umask(022)
1629 oldmask = os.umask(0o22)
1625 try:
1630 try:
1626 parser = parser or getparser()
1631 parser = parser or getparser()
1627 options, args = parseargs(args, parser)
1632 options, args = parseargs(args, parser)
@@ -1643,7 +1648,7 b' class TestRunner(object):'
1643 # run largest tests first, as they tend to take the longest
1648 # run largest tests first, as they tend to take the longest
1644 try:
1649 try:
1645 val = -os.stat(f).st_size
1650 val = -os.stat(f).st_size
1646 except OSError, e:
1651 except OSError as e:
1647 if e.errno != errno.ENOENT:
1652 if e.errno != errno.ENOENT:
1648 raise
1653 raise
1649 return -1e9 # file does not exist, tell early
1654 return -1e9 # file does not exist, tell early
@@ -1667,7 +1672,7 b' class TestRunner(object):'
1667 # Meaning of tmpdir has changed since 1.3: we used to create
1672 # Meaning of tmpdir has changed since 1.3: we used to create
1668 # HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if
1673 # HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if
1669 # tmpdir already exists.
1674 # tmpdir already exists.
1670 print "error: temp dir %r already exists" % tmpdir
1675 print("error: temp dir %r already exists" % tmpdir)
1671 return 1
1676 return 1
1672
1677
1673 # Automatically removing tmpdir sounds convenient, but could
1678 # Automatically removing tmpdir sounds convenient, but could
@@ -1783,7 +1788,7 b' class TestRunner(object):'
1783 break
1788 break
1784 tests.pop(0)
1789 tests.pop(0)
1785 if not tests:
1790 if not tests:
1786 print "running all tests"
1791 print("running all tests")
1787 tests = orig
1792 tests = orig
1788
1793
1789 tests = [self._gettest(t, i) for i, t in enumerate(tests)]
1794 tests = [self._gettest(t, i) for i, t in enumerate(tests)]
@@ -1815,7 +1820,7 b' class TestRunner(object):'
1815 self._outputcoverage()
1820 self._outputcoverage()
1816 except KeyboardInterrupt:
1821 except KeyboardInterrupt:
1817 failed = True
1822 failed = True
1818 print "\ninterrupted!"
1823 print("\ninterrupted!")
1819
1824
1820 if failed:
1825 if failed:
1821 return 1
1826 return 1
@@ -1894,14 +1899,14 b' class TestRunner(object):'
1894 if os.readlink(mypython) == sys.executable:
1899 if os.readlink(mypython) == sys.executable:
1895 return
1900 return
1896 os.unlink(mypython)
1901 os.unlink(mypython)
1897 except OSError, err:
1902 except OSError as err:
1898 if err.errno != errno.ENOENT:
1903 if err.errno != errno.ENOENT:
1899 raise
1904 raise
1900 if self._findprogram(pyexename) != sys.executable:
1905 if self._findprogram(pyexename) != sys.executable:
1901 try:
1906 try:
1902 os.symlink(sys.executable, mypython)
1907 os.symlink(sys.executable, mypython)
1903 self._createdfiles.append(mypython)
1908 self._createdfiles.append(mypython)
1904 except OSError, err:
1909 except OSError as err:
1905 # child processes may race, which is harmless
1910 # child processes may race, which is harmless
1906 if err.errno != errno.EEXIST:
1911 if err.errno != errno.EEXIST:
1907 raise
1912 raise
@@ -1914,7 +1919,7 b' class TestRunner(object):'
1914 path.remove(exedir)
1919 path.remove(exedir)
1915 os.environ['PATH'] = os.pathsep.join([exedir] + path)
1920 os.environ['PATH'] = os.pathsep.join([exedir] + path)
1916 if not self._findprogram(pyexename):
1921 if not self._findprogram(pyexename):
1917 print "WARNING: Cannot find %s in search path" % pyexename
1922 print("WARNING: Cannot find %s in search path" % pyexename)
1918
1923
1919 def _installhg(self):
1924 def _installhg(self):
1920 """Install hg into the test environment.
1925 """Install hg into the test environment.
@@ -1962,7 +1967,7 b' class TestRunner(object):'
1962 def makedirs(p):
1967 def makedirs(p):
1963 try:
1968 try:
1964 os.makedirs(p)
1969 os.makedirs(p)
1965 except OSError, e:
1970 except OSError as e:
1966 if e.errno != errno.EEXIST:
1971 if e.errno != errno.EEXIST:
1967 raise
1972 raise
1968 makedirs(self._pythondir)
1973 makedirs(self._pythondir)
@@ -2007,7 +2012,7 b' class TestRunner(object):'
2007 f.write(data)
2012 f.write(data)
2008 f.close()
2013 f.close()
2009 else:
2014 else:
2010 print 'WARNING: cannot fix hg.bat reference to python.exe'
2015 print('WARNING: cannot fix hg.bat reference to python.exe')
2011
2016
2012 if self.options.anycoverage:
2017 if self.options.anycoverage:
2013 custom = os.path.join(self._testdir, 'sitecustomize.py')
2018 custom = os.path.join(self._testdir, 'sitecustomize.py')
@@ -2020,7 +2025,7 b' class TestRunner(object):'
2020 covdir = os.path.join(self._installdir, '..', 'coverage')
2025 covdir = os.path.join(self._installdir, '..', 'coverage')
2021 try:
2026 try:
2022 os.mkdir(covdir)
2027 os.mkdir(covdir)
2023 except OSError, e:
2028 except OSError as e:
2024 if e.errno != errno.EEXIST:
2029 if e.errno != errno.EEXIST:
2025 raise
2030 raise
2026
2031
@@ -2100,7 +2105,7 b' class TestRunner(object):'
2100 if found:
2105 if found:
2101 vlog("# Found prerequisite", p, "at", found)
2106 vlog("# Found prerequisite", p, "at", found)
2102 else:
2107 else:
2103 print "WARNING: Did not find prerequisite tool: %s " % p
2108 print("WARNING: Did not find prerequisite tool: %s " % p)
2104
2109
2105 if __name__ == '__main__':
2110 if __name__ == '__main__':
2106 runner = TestRunner()
2111 runner = TestRunner()
General Comments 0
You need to be logged in to leave comments. Login now