コード例 #1
0
ファイル: itools.py プロジェクト: nzralc/Django-Emlak-Sitesi
def test_product():
    tests = [((('ABCD', 'xy'), {}),
              ['Ax', 'Ay', 'Bx', 'By', 'Cx', 'Cy', 'Dx', 'Dy']),
             ((('01', ), {
                 'repeat': 3
             }), ['000', '001', '010', '011', '100', '101', '110', '111'])]
    for test, result in tests:
        args, kwargs = test
        result = map(tuple, result)
        Assert(list(product(*args, **kwargs))) == result
コード例 #2
0
ファイル: itools.py プロジェクト: DocHoncho/brownie
def test_product():
    tests = [
        ((('ABCD', 'xy'), {}), ['Ax', 'Ay', 'Bx', 'By', 'Cx', 'Cy', 'Dx', 'Dy']),
        ((('01', ), {'repeat': 3}), [
            '000', '001', '010', '011', '100', '101', '110', '111'
        ])
    ]
    for test, result in tests:
        args, kwargs = test
        result = map(tuple, result)
        Assert(list(product(*args, **kwargs))) == result
コード例 #3
0
ファイル: abstract.py プロジェクト: MiguelMoll/vFense
def test_virtual_subclass_meta():
    from abc import ABCMeta

    class Foo(object):
        __metaclass__ = ABCMeta


    class Bar(object):
        __metaclass__ = ABCMeta


    class Simple(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Foo, Bar]

    class InheritingSimple(Simple):
        pass

    for a, b in product([Simple, InheritingSimple], [Foo, Bar]):
        assert issubclass(a, b)
        assert isinstance(a(), b)

    assert issubclass(InheritingSimple, Simple)
    assert isinstance(InheritingSimple(), Simple)

    class Spam(object):
        __metaclass__ = ABCMeta

    class Eggs(object):
        __metaclass__ = ABCMeta

    class SimpleMonty(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Spam, Eggs]

    class MultiInheritance(Simple, SimpleMonty):
        pass

    class MultiVirtualInheritance(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Simple, SimpleMonty]

    for virtual_super_cls in [Foo, Bar, Simple, Spam, Eggs, SimpleMonty]:
        assert issubclass(MultiInheritance, virtual_super_cls)
        assert isinstance(MultiInheritance(), virtual_super_cls)
コード例 #4
0
def test_virtual_subclass_meta():
    from abc import ABCMeta

    class Foo(object):
        __metaclass__ = ABCMeta

    class Bar(object):
        __metaclass__ = ABCMeta

    class Simple(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Foo, Bar]

    class InheritingSimple(Simple):
        pass

    for a, b in product([Simple, InheritingSimple], [Foo, Bar]):
        Assert.issubclass(a, b)
        Assert.isinstance(a(), b)

    Assert.issubclass(InheritingSimple, Simple)
    Assert.isinstance(InheritingSimple(), Simple)

    class Spam(object):
        __metaclass__ = ABCMeta

    class Eggs(object):
        __metaclass__ = ABCMeta

    class SimpleMonty(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Spam, Eggs]

    class MultiInheritance(Simple, SimpleMonty):
        pass

    class MultiVirtualInheritance(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Simple, SimpleMonty]

    for virtual_super_cls in [Foo, Bar, Simple, Spam, Eggs, SimpleMonty]:
        Assert.issubclass(MultiInheritance, virtual_super_cls)
        Assert.isinstance(MultiInheritance(), virtual_super_cls)