Example #1
0
def test_two_strings_of_same_length_could_be_eq():
    m = Model(x={
        'a': string_val(length=4),
        'b': string_val(length=4)
    }).restricted_by(eq('x.a', 'x.b')).build()
    row = m.create()[0][1]
    assert row['a'] == row['b']
Example #2
0
def test_restriction_must_override_parameter_definition():
    m = Model(leader={'direction': string_val('north')},
              follower={'direction': string_val()},
        ).restricted_by(eq('leader.direction', 'follower.direction')).build()
    assert sorted([('leader', {'direction': 'north'}),
                   ('follower', {'direction': 'north'})]) == \
           sorted(m.create())
Example #3
0
def test_restriction_must_override_parameter_definition():
    m = Model(
        leader={
            'direction': string_val('north')
        },
        follower={
            'direction': string_val()
        },
    ).restricted_by(eq('leader.direction', 'follower.direction')).build()
    assert sorted([('leader', {'direction': 'north'}),
                   ('follower', {'direction': 'north'})]) == \
           sorted(m.create())
Example #4
0
        'b': string_val(length=4)
    }).restricted_by(eq('x.a', 'x.b')).build()
    row = m.create()[0][1]
    assert row['a'] == row['b']


# error handling
@pytest.mark.parametrize('model,restrictions', [
    ({
        'leader': {
            'direction': string_val('north')
        },
        'follower': {
            'direction': int_val(13)
        }
    }, [eq('leader.direction', 'follower.direction')]),
    ({
        'x': {
            'a': string_val(length=5),
            'b': string_val(length=4)
        }
    }, [eq('x.a', 'x.b')]),
    ({
        'u': {
            'o': string_val('one'),
            't': string_val('two')
        }
    }, [eq('u.o', 'u.t')]),
    ({
        'fns': {
            'a': string_val(fn=lambda: 'hello'),
Example #5
0
def test_two_strings_of_same_length_could_be_eq():
    m = Model(x={'a': string_val(length=4),
                 'b': string_val(length=4)}
        ).restricted_by(eq('x.a', 'x.b')).build()
    row = m.create()[0][1]
    assert row['a'] == row['b']
Example #6
0
def test_restriction_must_override_parameter_definition():
    m = Model(leader={'direction': string_val('north')},
              follower={'direction': string_val()},
        ).restricted_by(eq('leader.direction', 'follower.direction')).build()
    assert sorted([('leader', {'direction': 'north'}),
                   ('follower', {'direction': 'north'})]) == \
           sorted(m.create())

def test_two_strings_of_same_length_could_be_eq():
    m = Model(x={'a': string_val(length=4),
                 'b': string_val(length=4)}
        ).restricted_by(eq('x.a', 'x.b')).build()
    row = m.create()[0][1]
    assert row['a'] == row['b']

# error handling
@pytest.mark.parametrize('model,restrictions', [
    ({'leader': {'direction': string_val('north')}, 'follower': {'direction': int_val(13)}},
     [eq('leader.direction', 'follower.direction')]),
    ({'x': {'a': string_val(length=5), 'b': string_val(length=4)}},
     [eq('x.a', 'x.b')]),
    ({'u': {'o': string_val('one'), 't': string_val('two')}},
     [eq('u.o', 'u.t')]),
    ({'fns': {'a': string_val(fn=lambda: 'hello'), 'b': string_val(fn=lambda: 'hello')}},
     [eq('fns.a', 'fns.b')]),
])
def test_failure_on_bad_combinations(model, restrictions):
    m = Model(**model).restricted_by(*restrictions)
    with pytest.raises(ModelException):
        m.build()