def _update_extensions(self) -> None: extension_types_enabled_in_configuration = { extension_configuration.extension_type for extension_configuration in self._configuration.extensions if extension_configuration.enabled } extension_types_sorter = TopologicalSorter( _build_extension_type_graph( extension_types_enabled_in_configuration)) extension_types_sorter.prepare() extensions = [] while extension_types_sorter.is_active(): extension_types_batch = extension_types_sorter.get_ready() extensions_batch = [] for extension_type in extension_types_batch: if issubclass(extension_type, ConfigurableExtension): if extension_type not in extension_types_enabled_in_configuration or self._configuration.extensions[ extension_type].extension_type_configuration is None: configuration = extension_type.default_configuration() else: configuration = self._configuration.extensions[ extension_type].extension_type_configuration extension = extension_type(self, configuration) else: extension = extension_type(self) extensions_batch.append(extension) extension_types_sorter.done(extension_type) extensions.append(extensions_batch) self._extensions._update(extensions)
def test_with_unknown_comes_after(self) -> None: class ComesBeforeExtension(Extension): pass class ComesAfterExtension(Extension): @classmethod def comes_after(cls) -> Set[Type[Extension]]: return {ComesBeforeExtension} extension_types = { ComesAfterExtension, } expected = { ComesAfterExtension: set(), } self.assertDictEqual(expected, dict(_build_extension_type_graph(extension_types)))
def test_with_isolated_extension_types(self) -> None: class IsolatedExtensionOne(Extension): pass class IsolatedExtensionTwo(Extension): pass extension_types = { IsolatedExtensionOne, IsolatedExtensionTwo, } expected = { IsolatedExtensionOne: set(), IsolatedExtensionTwo: set(), } self.assertEquals(expected, _build_extension_type_graph(extension_types))
def test_with_unknown_dependencies(self) -> None: class IsDependencyExtension(Extension): pass class HasDependencyExtension(Extension): @classmethod def depends_on(cls) -> Set[Type[Extension]]: return {IsDependencyExtension} extension_types = { HasDependencyExtension, } expected = { HasDependencyExtension: {IsDependencyExtension}, IsDependencyExtension: set(), } self.assertDictEqual(expected, dict(_build_extension_type_graph(extension_types)))
def test_without_extension_types(self) -> None: self.assertEquals({}, _build_extension_type_graph(set()))