Beispiel #1
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())
Beispiel #2
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']
Beispiel #3
0
    def test_given_length_and_prefix(self):
        val = value_of(string_val(length=15, prefix='so good '))
        assert len(val) == 15
        assert val.startswith('so good ')

        val = value_of(string_val(length=5, prefix='hello'))
        # len('hello') == 5
        assert val == 'hello'
Beispiel #4
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())
Beispiel #5
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())
Beispiel #6
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()
Beispiel #7
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()
Beispiel #8
0
 def test_incorrect_length_and_prefix(self):
     with pytest.raises(AssertionError):
         string_val(length=1, prefix='oh wait!')
Beispiel #9
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']


# 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')
Beispiel #10
0
 def test_default_lengh_is_10(self):
     '''Because why not'''
     assert len(value_of(string_val())) == 10
Beispiel #11
0
 def test_implement_custom_generator_function(self):
     '''I do want easy Faker compatibility, but do NOT want have it in
     dependency'''
     val = value_of(string_val(fn=lambda: 'take this'))
     assert val == 'take this'
Beispiel #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())
Beispiel #13
0
 def test_single_prefix_without_length_is_forbidden(self):
     with pytest.raises(AssertionError):
         string_val(prefix='alone')
Beispiel #14
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']
Beispiel #15
0
 def test_given_length(self):
     assert len(value_of(string_val(length=10))) == 10
     assert len(value_of(string_val(length=42))) == 42
Beispiel #16
0
 def test_list_of_fixed_values(self):
     chars = ['Harry', 'Ron', 'Hermiona']
     assert value_of(string_val(chars)) in chars
Beispiel #17
0
 def test_fixed_value(self):
     assert value_of(string_val('hello')) == 'hello'
Beispiel #18
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()
Beispiel #19
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()
Beispiel #20
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()