Ejemplo n.º 1
0
def test_model_many_builder_custom_cls():
    class Foo(Model):
        bar: str

        def baz(self):
            return True

    data = [{'bar': 1}] * 3
    models = list(model_many_builder(data, cls=Foo))

    assert len(models) == 3
    assert all(foo.baz() for foo in models)
Ejemplo n.º 2
0
def test_model_many_builder():
    element = {
        'foo*bar': 'foobar',
        'baz/qux': 'bazqux',
    }
    model_count = 3
    data = [element] * model_count

    models = model_many_builder(data)

    assert len(models) == model_count
    first = models[0]
    for model in models[1:]:
        assert isinstance(model, type(first))
Ejemplo n.º 3
0
def test_model_many_builder_ignore_private_attrs():
    element = {
        'foo': 'foo',
        '_bar': 'bar',
        '__nope': 'nope',
    }
    model_count = 3
    data = [element] * model_count

    models = list(model_many_builder(data))

    assert len(models) == model_count
    for model in models:
        assert model.foo == 'foo'
        assert model._bar == 'bar'
        assert hasattr(model, '__nope') is False
Ejemplo n.º 4
0
def test_model_many_builder_empty_iterable(iterable):
    models = model_many_builder(iterable)

    assert isinstance(models, typing.Generator)
    assert len(list(models)) == 0