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
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
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)
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)