[PATCH 2 of 3] run-tests: avoid os.getcwdb() on Windows

Matt Harbison mharbison72 at gmail.com
Thu Sep 20 08:10:00 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1537407718 14400
#      Wed Sep 19 21:41:58 2018 -0400
# Node ID de033c83ce6ef41b81cef5c27d33b4d518005085
# Parent  4d2a7291137d1fc1ac8ac32862a1d3593f3eb10e
run-tests: avoid os.getcwdb() on Windows

Any call to this issues a DeprecationWarning about the Windows bytes API being
deprecated.  There are a handful of these calls in core, but test-run-tests.t
was littered with these, as it's printed everytime run-tests.py is launched.
I'm not sure what the long term strategy for Unicode on Windows in the test
runner is, but this seems no worse than the current conversion strategy.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -184,6 +184,10 @@ if sys.version_info > (3, 5, 0):
 
         osenvironb = environbytes(os.environ)
 
+    getcwdb = getattr(os, 'getcwdb')
+    if not getcwdb or os.name == 'nt':
+        getcwdb = lambda : _bytespath(os.getcwd())
+
 elif sys.version_info >= (3, 0, 0):
     print('%s is only supported on Python 3.5+ and 2.7, not %s' %
           (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
@@ -200,6 +204,7 @@ else:
 
     _strpath = _bytespath
     osenvironb = os.environ
+    getcwdb = os.getcwd
 
 # For Windows support
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
@@ -2520,8 +2525,7 @@ class TestRunner(object):
             os.umask(oldmask)
 
     def _run(self, testdescs):
-        self._testdir = osenvironb[b'TESTDIR'] = getattr(
-            os, 'getcwdb', os.getcwd)()
+        self._testdir = osenvironb[b'TESTDIR'] = getcwdb()
         # assume all tests in same folder for now
         if testdescs:
             pathname = os.path.dirname(testdescs[0]['path'])


More information about the Mercurial-devel mailing list