##// END OF EJS Templates
run-tests: replace open-coded .decode()s on paths with a helper (issue4667)...
Augie Fackler -
r25162:153b9c52 default
parent child Browse files
Show More
@@ -83,15 +83,26 b' if sys.version_info > (3, 5, 0):'
83 83 xrange = range # we use xrange in one place, and we'd rather not use range
84 84 def _bytespath(p):
85 85 return p.encode('utf-8')
86
87 def _strpath(p):
88 return p.decode('utf-8')
89
86 90 elif sys.version_info >= (3, 0, 0):
87 91 print('%s is only supported on Python 3.5+ and 2.6-2.7, not %s' %
88 92 (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
89 93 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
90 94 else:
91 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 101 def _bytespath(p):
93 102 return p
94 103
104 _strpath = _bytespath
105
95 106 def checkportisavailable(port):
96 107 """return true if a port seems free to bind on localhost"""
97 108 try:
@@ -443,7 +454,7 b' class Test(unittest.TestCase):'
443 454 """
444 455 self.path = path
445 456 self.bname = os.path.basename(path)
446 self.name = self.bname.decode('utf-8')
457 self.name = _strpath(self.bname)
447 458 self._testdir = os.path.dirname(path)
448 459 self.errpath = os.path.join(self._testdir, b'%s.err' % self.bname)
449 460
@@ -1734,8 +1745,8 b' class TestRunner(object):'
1734 1745 # in all lowercase, which causes troubles with paths (issue3490)
1735 1746 d = osenvironb.get(b'TMP', None)
1736 1747 # FILE BUG: mkdtemp works only on unicode in Python 3
1737 tmpdir = tempfile.mkdtemp('', 'hgtests.',
1738 d and d.decode('utf-8')).encode('utf-8')
1748 tmpdir = tempfile.mkdtemp('', 'hgtests.', d and _strpath(d))
1749 tmpdir = _bytespath(tmpdir)
1739 1750
1740 1751 self._hgtmp = osenvironb[b'HGTMP'] = (
1741 1752 os.path.realpath(tmpdir))
@@ -2126,7 +2137,7 b' class TestRunner(object):'
2126 2137 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
2127 2138 cmd = cmd % PYTHON
2128 2139 if PYTHON3:
2129 cmd = cmd.decode('utf-8')
2140 cmd = _strpath(cmd)
2130 2141 pipe = os.popen(cmd)
2131 2142 try:
2132 2143 self._hgpath = _bytespath(pipe.read().strip())
General Comments 0
You need to be logged in to leave comments. Login now