Пример #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']
Пример #2
0
def test_model_with_multiple_params():
    m = Model(human={
        'head': int_val(1),
        'hands': int_val(2),
        'name': string_val('Hurin'),
    }).build()
    assert [('human', {'head': 1, 'hands': 2, 'name': 'Hurin'})] == m.create()
Пример #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())
Пример #4
0
def test_model_with_multiple_params():
    m = Model(human={
        'head': int_val(1),
        'hands': int_val(2),
        'name': string_val('Hurin'),
        }).build()
    assert [('human', {'head': 1, 'hands': 2, 'name': 'Hurin'})] == m.create()
Пример #5
0
def test_model_with_multiple_entities():
    m = Model(first={
        'name': string_val('elves')
    },
              second={
                  'name': string_val('humans')
              }).build()
    assert sorted([('first', {'name': 'elves'}),
                   ('second', {'name': 'humans'})]) ==\
           sorted(m.create())
Пример #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())
Пример #7
0
def test_failure_on_bad_combinations(model, restrictions):
    m = Model(**model).restricted_by(*restrictions)
    with pytest.raises(ModelException):
        m.build()
Пример #8
0
def test_minimal_model():
    m = Model(const={'int': int_val(42)}).build()
    assert [('const', {'int': 42})] == m.create()
    m = Model(const2={'str': string_val('hello')}).build()
    assert [('const2', {'str': 'hello'})] == m.create()
Пример #9
0
def test_minimal_model():
    m = Model(const={'int': int_val(42)}).build()
    assert [('const', {'int': 42})] == m.create()
    m = Model(const2={'str': string_val('hello')}).build()
    assert [('const2', {'str': 'hello'})] == m.create()
Пример #10
0
def test_failure_on_bad_combinations(model, restrictions):
    m = Model(**model).restricted_by(*restrictions)
    with pytest.raises(ModelException):
        m.build()
Пример #11
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']
Пример #12
0
def test_model_with_multiple_entities():
    m = Model(first={'name': string_val('elves')},
              second={'name': string_val('humans')}).build()
    assert sorted([('first', {'name': 'elves'}),
                   ('second', {'name': 'humans'})]) ==\
           sorted(m.create())