[Mesa-dev] [PATCH 1/2] compiler/glsl/tests: Make tests python3 safe

Mathieu Bridon bochecha at daitauha.fr
Fri Aug 17 18:01:23 UTC 2018


On Fri, 2018-08-17 at 10:45 -0700, Dylan Baker wrote:
> Quoting Mathieu Bridon (2018-08-16 15:00:39)
> > On Thu, 2018-08-16 at 14:21 -0700, Dylan Baker wrote:
> > > ---
> > > 
> > > I didn't see any patches from anyone else, so I wrote some real
> > > quick. Please
> > > point to them if other patches already exist.
> > 
> > I was about to send mine, but you were faster. >_<
> > 
> > They ar every similar though, except that you missed glcpp_test.py,
> > which requires a few more changes. (I have them ready, and can send
> > them separately)
> > 
> > > diff --git a/src/compiler/glsl/tests/optimization_test.py
> > > b/src/compiler/glsl/tests/optimization_test.py
> > > index 577d2dfc20f..f40d0cee6bd 100755
> > > --- a/src/compiler/glsl/tests/optimization_test.py
> > > +++ b/src/compiler/glsl/tests/optimization_test.py
> > > @@ -1,4 +1,4 @@
> > > -#!/usr/bin/env python2
> > > +#!/usr/bin/env python
> > >  # encoding=utf-8
> > >  # Copyright © 2018 Intel Corporation
> > >  
> > > @@ -71,7 +71,9 @@ def main():
> > >                  stdout=subprocess.PIPE,
> > >                  stderr=subprocess.PIPE,
> > >                  stdin=subprocess.PIPE)
> > > -            out, err = proc.communicate(source)
> > > +            out, err = proc.communicate(source.encode())
> > > +            out = out.decode()
> > > +            err = err.decode()
> > 
> > I usually find it too unpredictable to use the default encoding,
> > and
> > prefer always specifying 'utf-8'. (even on Python 3, you can't be
> > sure
> > that will always be the default)
> 
> That's true I guess. I've never seen anyone build python with utf-8
> as not the default, but they can so we should do the right thing.

That's not a build-time thing though:

  $ python3 -c 'print("é".encode())'
  b'\xc3\xa9'
  $ LC_ALL=C python3 -c 'print("é".encode())'
  Unable to decode the command from the command line:
  UnicodeEncodeError: 'utf-8' codec can't encode characters in position 7-8: surrogates not allowed

This happens regularly in some containers-like environment or SSH-ing
to a server which doesn't have your client locale.


-- 
Mathieu



More information about the mesa-dev mailing list