示例#1
0
def test_copy():
    sc1 = SimpleConstraint(name='sc1')
    sc1_copy = sc1.copy()
    assert id(sc1) != id(sc1_copy)
    sc1.check_and_set('value1')
    assert sc1.value == 'value1'
    assert sc1_copy.value is None
    sc1_copy.check_and_set('value2')
    assert sc1_copy.value == 'value2'
    assert sc1.value == 'value1'
示例#2
0
def test_simpleconstraint_reprocess_nomatch():
    """Test options for reprocessing"""
    sc = SimpleConstraint(
        value='my_value',
        reprocess_on_fail=True
    )
    match, reprocess = sc.check_and_set('bad_value')
    assert not match
    assert len(reprocess)
示例#3
0
def test_simpleconstraint_checkset():
    """Test check_and_set"""

    # Check and set.
    c = SimpleConstraint()
    match, reprocess = c.check_and_set('my_value')
    assert match
    assert c.value == 'my_value'
    assert len(reprocess) == 0

    # Non-match
    c = SimpleConstraint(value='my_value')
    match, reprocess = c.check_and_set('bad_value')
    assert not match
    assert c.value == 'my_value'
    assert len(reprocess) == 0

    # Don't force unique
    c = SimpleConstraint(force_unique=False)
    match, reprocess = c.check_and_set('my_value')
    assert match
    assert c.value is None
    assert len(reprocess) == 0