[Piglit] [Patch v2 2/2] results.py: Add recursive_update method to TestResult

Dylan Baker baker.dylan.c at gmail.com
Wed Jul 2 12:59:08 PDT 2014


On Wednesday, July 02, 2014 10:39:57 AM Dylan Baker wrote:
> On Wednesday, July 02, 2014 01:28:09 PM Ilia Mirkin wrote:
> > On Wed, Jul 2, 2014 at 1:17 PM, Dylan Baker <baker.dylan.c at gmail.com> 
wrote:
> > > This method is used during PiglitTest.interpret_result() to update
> > > subtest entries safely. I chose this approach since it is robust,
> > > reusable, and it felt more natural as a part of TestResult than putting
> > > it in PiglitTest.interpret_result()
> > > 
> > > v2: - Fix commit message
> > > 
> > > Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> > > ---
> > > 
> > >  framework/exectest.py |  2 +-
> > >  framework/results.py  | 32 ++++++++++++++++++++++++++++++++
> > >  2 files changed, 33 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/framework/exectest.py b/framework/exectest.py
> > > index e4a2344..fcc29af 100644
> > > --- a/framework/exectest.py
> > > +++ b/framework/exectest.py
> > > 
> > > @@ -279,6 +279,6 @@ class PiglitTest(Test):
> > >          outpiglit = (s[7:] for s in outlines if
> > >          s.startswith('PIGLIT:'))
> > > 
> > >          for piglit in outpiglit:
> > > -            self.result.update(json.loads(piglit))
> > > +            self.result.recursive_update(json.loads(piglit))
> > > 
> > >          self.result['out'] = '\n'.join(
> > >          
> > >              s for s in outlines if not s.startswith('PIGLIT:'))
> > > 
> > > diff --git a/framework/results.py b/framework/results.py
> > > index a715b29..88d962d 100644
> > > --- a/framework/results.py
> > > +++ b/framework/results.py
> > > 
> > > @@ -248,6 +248,38 @@ class TestResult(dict):
> > >              # normally
> > >              pass
> > > 
> > > +    def recursive_update(self, dictionary):
> > > +        """ Recursively update the TestResult
> > > +
> > > +        The problem with using self.update() is this:
> > > +        >>> t = TestResult()
> > > +        >>> t.update({'subtest': {'test1': 'pass'}})
> > > +        >>> t.update({'subtest': {'test2': 'pass'}})
> > > +        >>> t['subtest']
> > > +        {'test2': 'pass'}
> > > +
> > > +        This function is different, because it recursively updates
> > > self,
> > > it +        doesn't clobber existing entires in the same way
> > > +        >>> t = TestResult()
> > > +        >>> t.recursive_update({'subtest': {'test1': 'pass'}})
> > > +        >>> t.recursive_update({'subtest': {'test2': 'pass'}})
> > > +        >>> t['subtest']
> > > +        {'test1': 'pass', 'test2': 'pass'}
> > > +
> > > +        Arguments:
> > > +        dictionary -- a dictionary instance to update the TestResult
> > > with
> > > +
> > > +        """
> > > +        def update(d, u):
> > > +            for k, v in u.iteritems():
> > > +                if isinstance(v, dict):
> > > +                    d[k] = update(d.get(k, {}), v)
> > > +                else:
> > > +                    d[k] = u[k]
> > 
> > What about this? Why not d[k] = v? [Perhaps you missed that comment in
> > my response to the original?]
> 
> whoops, yes, yes I did. You're right, that should be v.
> 
> > > +            return d
> > > +
> > > +        update(self, dictionary)
> > > +
> > > 
> > >  class TestrunResult(object):
> > >      def __init__(self, resultfile=None):
> > > --
> > > 2.0.0
> > > 
> > > _______________________________________________
> > > Piglit mailing list
> > > Piglit at lists.freedesktop.org
> > > http://lists.freedesktop.org/mailman/listinfo/piglit

I made corrections and pushed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140702/a0d4df16/attachment.sig>


More information about the Piglit mailing list