D4546: tests: handle Python 3 not quoting non-empty-directory error

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Wed Sep 12 21:27:10 EDT 2018


mharbison72 added a comment.


  This motivated me to install py3, and give it a try.  But the test runner keeps crashing on str/bytes issues.  I fixed a couple, but it looks like treating everything as bytes can be a problem, since environment stuff internally wants to uppercase, which wants a str (apparently).
  
    $ /c/Program\ Files/Python37/python run-tests.py --local test-update-names.t
    Traceback (most recent call last):
      File "run-tests.py", line 3194, in <module>
        sys.exit(runner.run(sys.argv[1:]))
      File "run-tests.py", line 2475, in run
        self._checktools()
      File "run-tests.py", line 3123, in _checktools
        found = self._findprogram(p)
      File "run-tests.py", line 3112, in _findprogram
        for p in osenvironb.get(b'PATH', dpb).split(sepb):
      File "c:\Program Files\Python37\lib\_collections_abc.py", line 660, in get
        return self[key]
      File "c:\Program Files\Python37\lib\os.py", line 675, in __getitem__
        value = self._data[self.encodekey(key)]
      File "c:\Program Files\Python37\lib\os.py", line 744, in encodekey
        return encode(key).upper()
      File "c:\Program Files\Python37\lib\os.py", line 739, in check_str
        raise TypeError("str expected, not %s" % type(value).__name__)
    TypeError: str expected, not bytes
  
  I "fixed" that with the following...
  
    @@ -3107,10 +3107,12 @@ class TestRunner(object):
     
         def _findprogram(self, program):
             """Search PATH for a executable program"""
    -        dpb = _bytespath(os.defpath)
    -        sepb = _bytespath(os.pathsep)
    -        for p in osenvironb.get(b'PATH', dpb).split(sepb):
    -            name = os.path.join(p, program)
    +#        dpb = _bytespath(os.defpath)
    +#        sepb = _bytespath(os.pathsep)
    +        dpb = os.defpath
    +        sepb = os.pathsep
    +        for p in osenvironb.get('PATH', dpb).split(sepb):
    +            name = os.path.join(_bytespath(p), program)
                 if os.name == 'nt' or os.access(name, os.X_OK):
                     return name
             return None
  
  ... and then got a crash with a warning that the Windows bytes API is deprecated.
  
    $ /c/Program\ Files/Python37/python run-tests.py --local test-update-names.t
    run-tests.py:2491: DeprecationWarning: The Windows bytes API has been deprecated, use Unicode filenames instead
      os, 'getcwdb', os.getcwd)()
    Traceback (most recent call last):
      File "run-tests.py", line 3196, in <module>
        sys.exit(runner.run(sys.argv[1:]))
      File "run-tests.py", line 2480, in run
        result = self._run(testdescs)
      File "run-tests.py", line 2491, in _run
        os, 'getcwdb', os.getcwd)()
      File "c:\Program Files\Python37\lib\os.py", line 682, in __setitem__
        key = self.encodekey(key)
      File "c:\Program Files\Python37\lib\os.py", line 744, in encodekey
        return encode(key).upper()
      File "c:\Program Files\Python37\lib\os.py", line 739, in check_str
        raise TypeError("str expected, not %s" % type(value).__name__)
    TypeError: str expected, not bytes

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4546

To: durin42, #hg-reviewers, pulkit
Cc: mharbison72, mercurial-devel


More information about the Mercurial-devel mailing list