def test_existent_path_selects_relevant_ops():
    result = reduce(DIFF, ['key2'])
    assert result == (
        ('change', (), 'old2', 'new2'),
        ('add', ('suba', ), 'olda', 'newa'),
        ('remove', ('subb', ), 'oldb', 'newb'),
    )
Beispiel #2
0
 def adjust_cause(self, cause: execution.CauseT) -> execution.CauseT:
     if self.field is not None and isinstance(cause, causes.ChangingCause):
         old = dicts.resolve(cause.old, self.field, None)
         new = dicts.resolve(cause.new, self.field, None)
         diff = diffs.reduce(cause.diff, self.field)
         new_cause = dataclasses.replace(cause, old=old, new=new, diff=diff)
         return cast(execution.CauseT, new_cause)  # TODO: mypy bug?
     else:
         return cause
def test_overly_specific_path_dives_into_dicts_for_change():
    result = reduce(DIFF, ['key4', 'subc'])
    assert result == (('change', (), 'oldc', 'newc'), )
def test_overly_specific_path_dives_into_dicts_for_removal():
    result = reduce(DIFF, ['key4', 'suba'])
    assert result == (('remove', (), 'olda', None), )
def test_overly_specific_path_dives_into_dicts_for_addition():
    result = reduce(DIFF, ['key4', 'subb'])
    assert result == (('add', (), None, 'newb'), )
def test_nonexistent_path_selects_nothing(path):
    result = reduce(DIFF, path)
    assert result == ()
def test_empty_path_selects_all_ops():
    result = reduce(DIFF, [])
    assert result == DIFF
def test_type_ignored_for_inputs_but_is_tuple_for_output(diff, path):
    result = reduce(diff, path)
    assert result == (('op', (), 'old', 'new'), )