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

Dylan Baker dylan at pnwbakers.com
Fri Aug 17 18:03:39 UTC 2018


Quoting Mathieu Bridon (2018-08-17 10:58:38)
> On Fri, 2018-08-17 at 10:51 -0700, Dylan Baker wrote:
> > diff --git a/src/compiler/glsl/tests/optimization_test.py
> > b/src/compiler/glsl/tests/optimization_test.py
> > index 577d2dfc20f..65bac676963 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('utf-8')
> > +            err = err.decode('utf-8')
> 
> Shouldn't you also specify the encoding for the source.encode() bit?

....Yes

> 
> > diff --git a/src/compiler/glsl/tests/sexps.py
> > b/src/compiler/glsl/tests/sexps.py
> > index a714af8d236..09ca96e3be5 100644
> > --- a/src/compiler/glsl/tests/sexps.py
> > +++ b/src/compiler/glsl/tests/sexps.py
> > @@ -28,6 +28,13 @@
> >  # as ['constant', 'float', ['1.000000']].
> >  
> >  import re
> > +import sys
> > +if sys.version_info >= (3, 0, 0):
> > +    STRING_TYPE = str
> > +    BYTES_TYPE = bytes
> > +else:
> > +    STRING_TYPE = unicode
> > +    BYTES_TYPE = str
> 
> Note that "bytes" exists on Python 2 and is an alias to "str":
> 
>   >>> bytes
>   <type 'str'>
> 
> So you don't actually need BYTES_TYPE at all. :)

Despite all of the projects I've ported I did not know that. :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180817/09c430b0/attachment.sig>


More information about the mesa-dev mailing list