From patchwork Thu Sep 20 12:10:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3] run-tests: avoid os.getcwdb() on Windows From: Matt Harbison X-Patchwork-Id: 34841 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Thu, 20 Sep 2018 08:10:00 -0400 # HG changeset patch # User Matt Harbison # 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'])