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

Mathieu Bridon bochecha at daitauha.fr
Fri Aug 17 17:58:38 UTC 2018


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?

> 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. :)
 

-- 
Mathieu



More information about the mesa-dev mailing list