[Piglit] [PATCH 12/12] core.py: rewrie loadTestProfile to remove execfile()
Daniel Vetter
daniel at ffwll.ch
Tue Jan 7 01:47:26 PST 2014
On Mon, Dec 23, 2013 at 04:51:49PM -0800, Dylan Baker wrote:
> This patch removes execfile, replaceing it with import instead.
>
> This isn't a prefect solution, but it provides feature parity with the
> execfile() aproach, while being python3 safe.
> ---
> framework/core.py | 22 ++++++++++++++++------
> 1 file changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/framework/core.py b/framework/core.py
> index cd5c11d..6dacc7c 100644
> --- a/framework/core.py
> +++ b/framework/core.py
> @@ -38,6 +38,7 @@ from textwrap import dedent
> from threads import synchronized_self
> import threading
> import multiprocessing
> +import importlib
> try:
> import simplejson as json
> except ImportError:
> @@ -632,13 +633,22 @@ class TestProfile:
>
>
> def loadTestProfile(filename):
> - ns = {'__file__': filename}
> + """ Load a python module and return it's profile attribute
> +
> + All of the python test files provide a profile attribute which is a
> + TestProfile instance. This loads that module and returns it or raises an
> + error.
> +
> + """
> + mod = importlib.import_module('tests.{0}'.format(
> + os.path.splitext(os.path.basename(filename))[0]))
My python-fu is mediocre, but this piece of magic seems to ensure that
scripts which call piglit with tests/foo.tests still work. And in the
future we can just use foo, which saves some typing ;-) Maybe mention this
somewhere in the docs/commit message?
Otherwise ack on the entire series but no r-b due to lack of python
skills.
-Daniel
> +
> try:
> - execfile(filename, ns)
> - except:
> - traceback.print_exc()
> - raise Exception('Could not read tests profile')
> - return ns['profile']
> + return mod.profile
> + except AttributeError:
> + print("Error: There is not profile attribute in module {0}."
> + "Did you specify the right file?".format(filename))
> + sys.exit(1)
>
>
> def merge_test_profiles(profiles):
> --
> 1.8.5.2
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
More information about the Piglit
mailing list