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)])
def many_replace_wrapper(expression, position, replacement): return replace_many(expression, [(position, replacement)])
def test_empty_replace(self): expression = f(a, b) result = replace_many(expression, []) assert expression is result, "Empty replacements should not change the expression."
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"