Example #1
0
 def test_change_newkey(self):
     a = {'key': 'value',
          'd': {'dkey': 'dval'}}
     b = {'key': 'value',
          'd': {'dkey': 'dval',
                'dkey2': 'dval2'}}
     changes = dict(util.get_variable_changes(a, b))
     self.assertIn('d', changes)
     self.assertEqual(b['d'], changes['d'])
Example #2
0
 def test_addition(self):
     a = {}
     b = {'new': 'value'}
     changes = dict(util.get_variable_changes(a, b))
     self.assertIn('new', changes)
Example #3
0
 def test_change(self):
     a = {'key': 'value'}
     b = {'key': 'newvalue'}
     changes = dict(util.get_variable_changes(a, b))
     self.assertIn('key', changes)
     self.assertEqual(b['key'], changes['key'])
Example #4
0
File: trace.py Project: xgid/smiley
def collapse_trace(trace_iter):
    """Combine closely related trace items.
    """
    # FIXME: Need to look at the thread id
    accumulate = None
    for t in trace_iter:
        vars_have_changed = False
        if accumulate:
            vars_that_changed = util.get_variable_changes(
                accumulate.local_vars,
                t.local_vars,
            )
            for var, val in vars_that_changed:
                if var in accumulate.local_vars:
                    # The value of an existing variable changed between events
                    vars_have_changed = True
                    break
        do_yield = (
            accumulate and  # we have something to yield
            (vars_have_changed or
             accumulate.event != 'line' or  # that something can't be collapsed
             t.event != 'line' or  # the next event can't be combined with it
             t.event != accumulate.event)
        )
        if do_yield:
            # The events do not match or can't be combined
            yield accumulate
            accumulate = None

        if not accumulate:
            accumulate = db.Trace(
                id=t.id,
                run_id=t.run_id,
                thread_id=t.thread_id,
                call_id=t.call_id,
                event=t.event,
                filename=t.filename,
                line_no=(t.line_no, t.line_no),
                func_name=t.func_name,
                trace_arg=t.trace_arg,
                local_vars=t.local_vars,
                timestamp=t.timestamp,
            )

        else:
            # Combine consecutive line events by updating the line_no
            # range
            accumulate = db.Trace(
                id=accumulate.id,
                run_id=accumulate.run_id,
                thread_id=t.thread_id,
                call_id=accumulate.call_id,
                event=accumulate.event,
                filename=accumulate.filename,
                line_no=(accumulate.line_no[0], t.line_no),
                func_name=accumulate.func_name,
                trace_arg=accumulate.trace_arg,
                # replace in case variables were added
                local_vars=t.local_vars,
                timestamp=accumulate.timestamp,
            )

    if accumulate:
        yield accumulate