Esempio n. 1
0
def test_build_multi_register(factory):

    @pix.register('A')
    class A1(object):
        @classmethod
        def foo(cls):
            return 1

    @pix.register('A')
    class A2(object):
        @classmethod
        def foo(cls):
            return 2

    cls = factory.build('A')  # type: A2
    assert issubclass(cls, A2)
    assert issubclass(cls, A1)
    assert issubclass(cls, pix.PIXObject)

    mro = inspect.getmro(cls)
    assert mro[1] is A2
    assert mro[2] is A1
    assert mro[3] is pix.PIXObject

    assert hasattr(cls, 'foo')

    # test order that they're registered is the mro order
    assert cls.foo() == 2
Esempio n. 2
0
def test_build_inherit_pixobject(factory):

    @pix.register('A')
    class A(pix.PIXObject):
        pass

    cls = factory.build('A')
    assert issubclass(cls, A)
    assert issubclass(cls, pix.PIXObject)
Esempio n. 3
0
def test_build_no_inherit(factory):

    @pix.register('A')
    class A:
        def foo(self):
            pass

    cls = factory.build('A')
    assert issubclass(cls, A)
    assert issubclass(cls, pix.PIXObject)
    assert hasattr(cls, 'foo')
Esempio n. 4
0
def test_build(factory):
    cls = factory.build('PIXTestObj')
    assert issubclass(cls, PIXTestObj)
    cls = factory.build('PIXTestChildObj')
    assert issubclass(cls, PIXTestChildObj)