[Piglit] [PATCH] python tests: Adds an object proxy to make generator names correct
Dylan Baker
baker.dylan.c at gmail.com
Thu May 29 14:03:32 PDT 2014
On Thursday, May 29, 2014 14:01:11 Dylan Baker wrote:
> My understanding is that they operate very similarly, but solve different
> problems. So functools.wraps solves the problem of "I wrote a decorator,
> but now a bunch of stuff doesn't work because the decorator hides the
> actual method"; this class solves the problem of "When we iterate a
single
> instance of a class yielding it multiple times"
wow, I know exactly where i was interrupted while writing this.
It shold go on to say: "when what we really want is to yield a new instance
each time"
> by wrapping the function and
> holding the metadata we want instead of presenting the metadata of
the
> underlying object.
>
> So, now that I think about it that way maybe a better description is an
> "object obscurer"
>
> On Thursday, May 29, 2014 16:48:46 Ilia Mirkin wrote:
> > Can you explain how your wrapper class is different from
> > functools.wraps? I'm sure I'm missing some detail...
> >
> > On Thu, May 29, 2014 at 4:37 PM, Dylan Baker
>
> <baker.dylan.c at gmail.com> wrote:
> > > This adds a class that wraps python functions to work around a bug
in
> > > nose. The bug has to do with the way nose test generators and
>
> python
>
> > > instances interact, but the short is that all generated tests that
raise
> > > an error will get the description of the last test run, rather than
> > > their own. This works around that bug by creating a class instance
per
> > > generated test, so they get the right description.
> > >
> > > ---
> > >
> > > The problem with this solution is it requires adding more boilerplate
to
> > > each generator, a better solution would be to use a decorator, of
>
> course,
>
> > > there is a problem with the way nose handles generators which
makes
> > > decorating generators difficult, and I don't have the time to dig into
> > > it.
> > >
> > > framework/tests/core_tests.py | 5 ++---
> > > framework/tests/dmesg_tests.py | 12 ++++++----
> > > framework/tests/log_tests.py | 3 ++-
> > > framework/tests/status_tests.py | 3 ++-
> > > framework/tests/summary_tests.py | 7 +++---
> > > framework/tests/test_lists.py | 5 +++--
> > > framework/tests/utils.py | 47
> > > ++++++++++++++++++++++++++++++++++++++++ 7
>
> files changed, 68
>
> > > insertions(+), 14 deletions(-)
> > >
> > > diff --git a/framework/tests/core_tests.py
>
> b/framework/tests/core_tests.py
>
> > > index 44462ce..de424ad 100644
> > > --- a/framework/tests/core_tests.py
> > > +++ b/framework/tests/core_tests.py
> > >
> > > @@ -47,10 +47,9 @@ def test_generate_initialize():
> > > even work?
> > >
> > > """
> > >
> > > - yieldable = check_initialize
> > >
> > > - for target in [core.Environment, core.TestrunResult,
>
> core.TestResult,
>
> > > - core.PiglitJSONEncoder]:
> > > + for target in [core.Environment, core.PiglitJSONEncoder,]:
> > > + yieldable = utils.GeneratedTestWrapper(check_initialize)
> > >
> > > yieldable.description = "Test that {} initializes".format(
> > >
> > > target.__name__)
> > >
> > > yield yieldable, target
> > >
> > > diff --git a/framework/tests/dmesg_tests.py
> > > b/framework/tests/dmesg_tests.py index ccc3144..13ea705 100644
> > > --- a/framework/tests/dmesg_tests.py
> > > +++ b/framework/tests/dmesg_tests.py
> > > @@ -32,6 +32,7 @@ from framework.exectest import PiglitTest
> > >
> > > from framework.gleantest import GleanTest
> > > from framework.shader_test import ShaderTest
> > > from framework.glsl_parser_test import GLSLParserTest
> > >
> > > +import framework.tests.utils as utils
> > >
> > > def _get_dmesg():
> > > @@ -180,10 +181,11 @@ def test_update_result_replace():
> > > new_result = dmesg.update_result(create_test_result(res))
> > >
> > > # Create a yieldable and set the description for useful
> > > per-test
> > > names
> > >
> > > - yieldable = check_update_result
> > > + yieldable = utils.GeneratedTestWrapper(check_update_result)
> > >
> > > yieldable.description = "Test update_result: {0}".format(res)
> > > yield yieldable, new_result['result'], res
> > >
> > > + yieldable = utils.GeneratedTestWrapper(check_update_result)
> > >
> > > yieldable.description = "Test update_result subtest:
> > > {0}".format(res)
> > > yield yieldable, new_result['subtest']['test'], res
> > >
> > > @@ -193,7 +195,7 @@ def test_update_result_replace():
> > > _write_dev_kmesg()
> > > new_result = dmesg.update_result(create_test_result(res))
> > >
> > > - yieldable = check_equal_result
> > > + yieldable = utils.GeneratedTestWrapper(check_equal_result)
> > >
> > > yieldable.description = ("Test update_result with non-matching
> > > regex: "
> > >
> > > "{0}".format(res))
> > >
> > > yield yieldable, new_result['result'], res
> > >
> > > @@ -204,11 +206,12 @@ def test_update_result_replace():
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140529/72eb375b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140529/72eb375b/attachment-0001.sig>
More information about the Piglit
mailing list