def test_custom_constraint_repeated_renaming(): c1 = CustomConstraint(lambda x1, y: True) assert c1.variables == {'x1', 'y'} c2 = c1.with_renamed_vars({'x1': 'x2'}) assert c2.variables == {'x2', 'y'} c3 = c2.with_renamed_vars({'x2': 'x3'}) assert c3.variables == {'x3', 'y'} c4 = c3.with_renamed_vars({'z1': 'z2'}) assert c4.variables == {'x3', 'y'}
def test_custom_constraint_with_renamed_vars(): actual_x = None actual_y = None def constraint(x, y): nonlocal actual_x nonlocal actual_y actual_x = x actual_y = y return x == y c1 = CustomConstraint(constraint) c2 = c1.with_renamed_vars({'x': 'z'}) assert c2({'x': 1, 'z': 2, 'y': 1}) is False assert actual_x == 2 assert actual_y == 1 assert c2({'x': 1, 'z': 3, 'y': 3}) is True assert actual_x == 3 assert actual_y == 3