Ejemplo n.º 1
0
    def test_register_class(self):
        factory = ObjectFactory(MockType)

        factory.register_class('subtype', MockSubType)

        assert 'subtype' in factory.factory_map
        assert factory.factory_map['subtype'] is MockSubType
Ejemplo n.º 2
0
    def test_unregister_with_invalid_name(self):
        factory = ObjectFactory(MockType)

        with pytest.raises(KeyError):
            factory.unregister('other')
Ejemplo n.º 3
0
    def test_unregister(self):
        factory = ObjectFactory(MockType)
        factory.factory_map['subtype'] = MockSubType

        factory.unregister('subtype')
        assert 'subtype' not in factory.factory_map
Ejemplo n.º 4
0
    def test_register_with_non_subclass(self):
        factory = ObjectFactory(MockType)

        func = factory.register('other')
        with pytest.raises(TypeError):
            func(OtherType)
Ejemplo n.º 5
0
 def test_register_class_with_non_subclass(self):
     factory = ObjectFactory(MockType)
     with pytest.raises(TypeError):
         factory.register_class('other', OtherType)
Ejemplo n.º 6
0
    def test_get(self):
        factory = ObjectFactory(MockType)

        factory.factory_map['subtype'] = MockSubType

        assert factory.get('subtype')
Ejemplo n.º 7
0
 def test_init(self):
     factory = ObjectFactory(MockType)
     assert factory._base_type == MockType
Ejemplo n.º 8
0
from frater.factory import ObjectFactory
from .data_type import DataType

data_types = ObjectFactory(DataType)