[Piglit] [PATCH] results.py: Do not allow path separators in test names
Jason Ekstrand
jason at jlekstrand.net
Mon Sep 1 01:26:35 PDT 2014
On Sat, Aug 30, 2014 at 4: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 = name
> +
>
Personally, I'd rather we mangle things when we turn them into file names
rather than mangling the original. This way the original string still
shows up in table headers etc. That said, this also accomplishes the
objective of not crashing in stupid places.
--Jason
>
> 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)
> --
> 2.1.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140901/28a84b60/attachment.html>
More information about the Piglit
mailing list