Пример #1
0
 def test_inconsistent_position_error(self):
     with pytest.raises(IndexError):
         replace_many(f(a), [((), b), ((0, ), b)])
     with pytest.raises(IndexError):
         replace_many(a, [((), b), ((0, ), b)])
     with pytest.raises(IndexError):
         replace_many(a, [((0, ), b), ((1, ), b)])
Пример #2
0
def many_replace_wrapper(expression, position, replacement):
    return replace_many(expression, [(position, replacement)])
Пример #3
0
 def test_empty_replace(self):
     expression = f(a, b)
     result = replace_many(expression, [])
     assert expression is result, "Empty replacements should not change the expression."
Пример #4
0
 def test_substitution_match(self, expression, replacements, expected_result):
     result = replace_many(expression, replacements)
     assert result == expected_result, "Replacement did not yield expected result ({!r} -> {!r})".format(
         expression, replacements
     )
     assert result is not expression, "Replacement modified the original expression"