def test_copy(self): substitution = Substitution({'x': a}) copy = substitution.__copy__() assert copy == substitution assert copy is not substitution
def test_extract_substitution(self, substitution, subject, pattern, expected_result): substitution = Substitution(substitution) if expected_result is False: assert substitution.extract_substitution(subject, pattern) is False else: assert substitution.extract_substitution(subject, pattern) is True assert substitution == expected_result
def test_union_with_var(self, substitution, variable, value, expected_result): substitution = Substitution(substitution) if expected_result is ValueError: with pytest.raises(ValueError): _ = substitution.union_with_variable(variable, value) else: result = substitution.union_with_variable(variable, value) assert result == expected_result
def test_union(self, substitution1, substitution2, expected_result): substitution1 = Substitution(substitution1) substitution2 = Substitution(substitution2) if expected_result is ValueError: with pytest.raises(ValueError): _ = substitution1.union(substitution2) with pytest.raises(ValueError): _ = substitution2.union(substitution1) else: result = substitution1.union(substitution2) assert result == expected_result assert result is not substitution1 assert result is not substitution2 result = substitution2.union(substitution1) assert result == expected_result assert result is not substitution1 assert result is not substitution2
def __call__(self, match): self.called_with.append(Substitution(match)) return self.return_value
def test_rename(self, substitution, renaming, expected_result): assert Substitution(substitution).rename(renaming) == expected_result