comparison tests/run-tests.py @ 25162:153b9c5235c2

run-tests: replace open-coded .decode()s on paths with a helper (issue4667) This also cleans up the mkdtemp code mentioned in the previous patch. At this point, the remaining callsites of .{en,de)code() are in the following categories: Handling escaped lines in .t files ----------------------------------- It seems eminently reasonable to me for us to declare that .t files are valid utf-8, and that any escape sequences we see in .t files should be valid unicode_escape sequences. Making error text safe for cdata blocks for xml error reports ------------------------------------------------------------- This is a point where we're already basically screwed, and we're simply trying to do something "good enough" that the xml output will be vaguely useful to the user. Punting here seems fine, and we should probably stick to the same encoding here that we used in the previous section.
author Augie Fackler <augie@google.com>
date Sun, 17 May 2015 21:47:18 -0400
parents 4d30467d944e
children c3459555318e
comparison
equal deleted inserted replaced
25161:4d30467d944e 25162:153b9c5235c2
81 if sys.version_info > (3, 5, 0): 81 if sys.version_info > (3, 5, 0):
82 PYTHON3 = True 82 PYTHON3 = True
83 xrange = range # we use xrange in one place, and we'd rather not use range 83 xrange = range # we use xrange in one place, and we'd rather not use range
84 def _bytespath(p): 84 def _bytespath(p):
85 return p.encode('utf-8') 85 return p.encode('utf-8')
86
87 def _strpath(p):
88 return p.decode('utf-8')
89
86 elif sys.version_info >= (3, 0, 0): 90 elif sys.version_info >= (3, 0, 0):
87 print('%s is only supported on Python 3.5+ and 2.6-2.7, not %s' % 91 print('%s is only supported on Python 3.5+ and 2.6-2.7, not %s' %
88 (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))) 92 (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
89 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit` 93 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
90 else: 94 else:
91 PYTHON3 = False 95 PYTHON3 = False
96
97 # In python 2.x, path operations are generally done using
98 # bytestrings by default, so we don't have to do any extra
99 # fiddling there. We define the wrapper functions anyway just to
100 # help keep code consistent between platforms.
92 def _bytespath(p): 101 def _bytespath(p):
93 return p 102 return p
103
104 _strpath = _bytespath
94 105
95 def checkportisavailable(port): 106 def checkportisavailable(port):
96 """return true if a port seems free to bind on localhost""" 107 """return true if a port seems free to bind on localhost"""
97 try: 108 try:
98 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 109 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
441 452
442 shell is the shell to execute tests in. 453 shell is the shell to execute tests in.
443 """ 454 """
444 self.path = path 455 self.path = path
445 self.bname = os.path.basename(path) 456 self.bname = os.path.basename(path)
446 self.name = self.bname.decode('utf-8') 457 self.name = _strpath(self.bname)
447 self._testdir = os.path.dirname(path) 458 self._testdir = os.path.dirname(path)
448 self.errpath = os.path.join(self._testdir, b'%s.err' % self.bname) 459 self.errpath = os.path.join(self._testdir, b'%s.err' % self.bname)
449 460
450 self._threadtmp = tmpdir 461 self._threadtmp = tmpdir
451 self._keeptmpdir = keeptmpdir 462 self._keeptmpdir = keeptmpdir
1732 if os.name == 'nt': 1743 if os.name == 'nt':
1733 # without this, we get the default temp dir location, but 1744 # without this, we get the default temp dir location, but
1734 # in all lowercase, which causes troubles with paths (issue3490) 1745 # in all lowercase, which causes troubles with paths (issue3490)
1735 d = osenvironb.get(b'TMP', None) 1746 d = osenvironb.get(b'TMP', None)
1736 # FILE BUG: mkdtemp works only on unicode in Python 3 1747 # FILE BUG: mkdtemp works only on unicode in Python 3
1737 tmpdir = tempfile.mkdtemp('', 'hgtests.', 1748 tmpdir = tempfile.mkdtemp('', 'hgtests.', d and _strpath(d))
1738 d and d.decode('utf-8')).encode('utf-8') 1749 tmpdir = _bytespath(tmpdir)
1739 1750
1740 self._hgtmp = osenvironb[b'HGTMP'] = ( 1751 self._hgtmp = osenvironb[b'HGTMP'] = (
1741 os.path.realpath(tmpdir)) 1752 os.path.realpath(tmpdir))
1742 1753
1743 if self.options.with_hg: 1754 if self.options.with_hg:
2124 return self._hgpath 2135 return self._hgpath
2125 2136
2126 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"' 2137 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
2127 cmd = cmd % PYTHON 2138 cmd = cmd % PYTHON
2128 if PYTHON3: 2139 if PYTHON3:
2129 cmd = cmd.decode('utf-8') 2140 cmd = _strpath(cmd)
2130 pipe = os.popen(cmd) 2141 pipe = os.popen(cmd)
2131 try: 2142 try:
2132 self._hgpath = _bytespath(pipe.read().strip()) 2143 self._hgpath = _bytespath(pipe.read().strip())
2133 finally: 2144 finally:
2134 pipe.close() 2145 pipe.close()