[Piglit] [PATCH] results.py: Do not allow path separators in test names

Ilia Mirkin imirkin at alum.mit.edu
Sat Aug 30 16:26:08 PDT 2014


On Sat, Aug 30, 2014 at 7:20 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> This causes problems in the html summary generator, since os.mkdir
> doesn't understand that it's a string not a full path (and the
> underlying file system probably can't understand that either). Instead
> of raising an error we silently replace any illegal characters with an
> underscore.
>
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
>  framework/results.py             | 21 ++++++++++++++++++++-
>  framework/tests/results_tests.py | 16 ++++++++++++++++
>  2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/framework/results.py b/framework/results.py
> index efc7029..c89b39c 100644
> --- a/framework/results.py
> +++ b/framework/results.py
> @@ -305,7 +305,7 @@ class TestrunResult(object):
>                                  'lspci',
>                                  'results_version',
>                                  'time_elapsed']
> -        self.name = None
> +        self.__name = None
>          self.uname = None
>          self.options = None
>          self.glxinfo = None
> @@ -406,6 +406,25 @@ class TestrunResult(object):
>                             if k in self.serialized_keys),
>                        f, default=_piglit_encoder, indent=JSONWriter.INDENT)
>
> +    @property
> +    def name(self):
> +        return self.__name
> +
> +    @name.setter
> +    def name(self, name):
> +        """ Set the name of the test run
> +
> +        We don't allow path seperators in the name, they are silently replaced
> +        with underscores.
> +
> +        """
> +        replace = ['/', '\\']
> +
> +        for r in replace:
> +            name = name.replace(r, '_')

self.__name = re.sub(r'[\\/]', '_', name)

Or you can precompile the re if you want to be fancier... although
hopefully these things are cached.

> +
> +        self.__name = name
> +
>
>  def load_results(filename):
>      """ Loader function for TestrunResult class
> diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py
> index 54661cc..02438cf 100644
> --- a/framework/tests/results_tests.py
> +++ b/framework/tests/results_tests.py
> @@ -159,3 +159,19 @@ def test_update_results_old():
>          res = results.update_results(base, f.name)
>
>      nt.assert_equal(res.results_version, results.CURRENT_JSON_VERSION)
> +
> +
> + at utils.nose_generator
> +def test_testrunresult_set_name():
> +    """ Generate tests for the name setter """
> +    emsg = '"{}" should have been replaced but was not'
> +
> +    def test(value, expected, message):
> +        """ The actual test """
> +        t = results.TestrunResult()
> +        t.name = value
> +        nt.assert_equal(t.name, expected, msg=message)
> +
> +    for x in ['/', '\\']:
> +        test.description = 'TestrunResult.name replaces "{}" with "_"'.format(x)
> +        yield test, 'a{}name'.format(x), 'a_name', emsg.format(x)

Perhaps throw in multiple / in a single string?

> --
> 2.1.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list