class TestNestedBase(with_metaclass(ABCMeta, TestBase)): def setUp(self): super(TestNestedBase, self).setUp() self.foo_bucket = FooBucket('test_foo_bucket', [ Foo('my_foo1', list(range(10)), 'value1', 10), Foo('my_foo2', list(range(10, 20)), 'value2', 20) ]) self.foo_builders = { 'my_foo1': GroupBuilder('my_foo1', datasets={ 'my_data': DatasetBuilder('my_data', list(range(10)), attributes={'attr2': 10}) }, attributes={ 'attr1': 'value1', 'namespace': CORE_NAMESPACE, 'data_type': 'Foo' }), 'my_foo2': GroupBuilder('my_foo2', datasets={ 'my_data': DatasetBuilder('my_data', list(range(10, 20)), attributes={'attr2': 20}) }, attributes={ 'attr1': 'value2', 'namespace': CORE_NAMESPACE, 'data_type': 'Foo' }) } self.setUpBucketBuilder() self.setUpBucketSpec() self.spec_catalog.register_spec(self.bucket_spec, 'test.yaml') self.type_map.register_container_type(CORE_NAMESPACE, 'FooBucket', FooBucket) self.type_map.register_map(FooBucket, ObjectMapper) self.manager = BuildManager(self.type_map) def setUpBucketBuilder(self): raise unittest.SkipTest('Abstract Base Class') def setUpBucketSpec(self): raise unittest.SkipTest('Abstract Base Class') def test_build(self): ''' Test default mapping for an Container that has an Container as an attribute value ''' builder = self.manager.build(self.foo_bucket) self.assertDictEqual(builder, self.bucket_builder) def test_construct(self): container = self.manager.construct(self.bucket_builder) self.assertEqual(container, self.foo_bucket)
class NestedBaseMixin(metaclass=ABCMeta): def setUp(self): super().setUp() self.foo_bucket = FooBucket('test_foo_bucket', [ Foo('my_foo1', list(range(10)), 'value1', 10), Foo('my_foo2', list(range(10, 20)), 'value2', 20)]) self.foo_builders = { 'my_foo1': GroupBuilder('my_foo1', datasets={'my_data': DatasetBuilder( 'my_data', list(range(10)), attributes={'attr2': 10})}, attributes={'attr1': 'value1', 'namespace': CORE_NAMESPACE, 'data_type': 'Foo', 'object_id': self.foo_bucket.foos['my_foo1'].object_id}), 'my_foo2': GroupBuilder('my_foo2', datasets={'my_data': DatasetBuilder( 'my_data', list(range(10, 20)), attributes={'attr2': 20})}, attributes={'attr1': 'value2', 'namespace': CORE_NAMESPACE, 'data_type': 'Foo', 'object_id': self.foo_bucket.foos['my_foo2'].object_id}) } self.setUpBucketBuilder() self.setUpBucketSpec() self.spec_catalog.register_spec(self.bucket_spec, 'test.yaml') self.type_map.register_container_type(CORE_NAMESPACE, 'FooBucket', FooBucket) self.type_map.register_map(FooBucket, self.setUpBucketMapper()) self.manager = BuildManager(self.type_map) @abstractmethod def setUpBucketBuilder(self): raise NotImplementedError('Cannot run test unless setUpBucketBuilder is implemented') @abstractmethod def setUpBucketSpec(self): raise NotImplementedError('Cannot run test unless setUpBucketSpec is implemented') @abstractmethod def setUpBucketMapper(self): raise NotImplementedError('Cannot run test unless setUpBucketMapper is implemented') def test_build(self): ''' Test default mapping for an Container that has an Container as an attribute value ''' builder = self.manager.build(self.foo_bucket) self.assertDictEqual(builder, self.bucket_builder) def test_construct(self): container = self.manager.construct(self.bucket_builder) self.assertEqual(container, self.foo_bucket)