Exemplo n.º 1
0
def test_existent_path_selects_relevant_ops():
    result = reduce(DIFF, ['key2'])
    assert result == (
        ('change', (), 'old2', 'new2'),
        ('add', ('suba', ), 'olda', 'newa'),
        ('remove', ('subb', ), 'oldb', 'newb'),
    )
Exemplo n.º 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
Exemplo n.º 3
0
def test_overly_specific_path_dives_into_dicts_for_change():
    result = reduce(DIFF, ['key4', 'subc'])
    assert result == (('change', (), 'oldc', 'newc'), )
Exemplo n.º 4
0
def test_overly_specific_path_dives_into_dicts_for_removal():
    result = reduce(DIFF, ['key4', 'suba'])
    assert result == (('remove', (), 'olda', None), )
Exemplo n.º 5
0
def test_overly_specific_path_dives_into_dicts_for_addition():
    result = reduce(DIFF, ['key4', 'subb'])
    assert result == (('add', (), None, 'newb'), )
Exemplo n.º 6
0
def test_nonexistent_path_selects_nothing(path):
    result = reduce(DIFF, path)
    assert result == ()
Exemplo n.º 7
0
def test_empty_path_selects_all_ops():
    result = reduce(DIFF, [])
    assert result == DIFF
Exemplo n.º 8
0
def test_type_ignored_for_inputs_but_is_tuple_for_output(diff, path):
    result = reduce(diff, path)
    assert result == (('op', (), 'old', 'new'), )