def test_module_consistency_check_internals(): check = ModuleElementConsistencyCheck() elements = [Element(injector=..., strategy=...) for _ in range(4)] check.check([Module(elements={*elements}, exports={*elements[:2]})]) with pytest.raises(ModuleElementConsistencyError): check.check( [Module(elements={*elements[:2]}, exports={*elements[1:]})]) a = Module(elements={*elements[:2]}, exports={*elements[:2]}) b = Module(elements={*elements[2:]}, exports={*elements}, imports={a}) check.check([a, b]) a = Module(elements={*elements[:2]}, exports={*elements[:1]}) b = Module(elements={*elements[2:]}, exports={*elements}, imports={a}) with pytest.raises(ModuleElementConsistencyError): check.check([a, b]) a = Module(elements={*elements}, bootstrap={*elements}) check.check([a]) a = Module(elements={*elements[:2]}, bootstrap={*elements}) with pytest.raises(ModuleElementConsistencyError): check.check([a]) a = Module(elements={*elements[:2]}, exports={*elements[:1]}) b = Module(elements={*elements[2:]}, bootstrap={*elements}) with pytest.raises(ModuleElementConsistencyError): check.check([a, b])
def test_module_consistency_check_duplicates(): check = ModuleElementConsistencyCheck() elements = [Element(injector=..., strategy=...) for _ in range(8)] check.check([ Module(elements={*elements[:4]}, exports={*elements[:2]}), Module(elements={*elements[4:]}, exports={*elements[6:]}), ]) with pytest.raises(ModuleElementConsistencyError): check.check([ Module(elements={*elements}, exports={*elements[:2]}), Module(elements={*elements[4:]}, exports={*elements[6:]}), ])
def a_b_ci_modules(self): a_ci = Module( name="Aci", elements={*self.a_module.elements}, exports={*self.a_module.exports}, ) b_ci = Module( name="Bci", imports={a_ci}, elements={*self.b_module.elements}, exports={*self.b_module.exports}, ) a_ci.imports.add(b_ci) return a_ci, b_ci
def b_cd_module(self): return Module( name="Bcd", imports={self.a_module}, elements={*self.b_cd_elements}, exports={*self.b_cd_elements}, )
def b_ma_module(self): return Module( name="Bma", imports={self.a_ma_module}, elements={*self.b_module.elements}, exports={*self.b_module.exports}, )
def c_module(self): return Module( name="C", imports={self.a_module, self.b_module}, elements={*self.c_elements}, exports={*self.c_elements}, )
def c_bs_module(self): return Module( name="Cbs", imports={self.a_module, self.b_bs_module}, elements={*reversed(self.c_elements)}, bootstrap={*reversed(self.c_elements)}, exports={*self.c_module.exports}, )
def b_bs_module(self): return Module( name="Bbs", imports={self.a_module}, elements={*self.b_elements}, bootstrap={*self.b_elements}, exports={*self.b_elements}, )
def test_module_cycle(): modules = [Module(name=f"{index}") for index in range(3)] modules[0].imports = {modules[1]} modules[1].imports = {modules[2]} modules[2].imports = {modules[0]} solver = ModuleImportSolver() with pytest.raises(ModuleImportSolverError): solver.solve(modules)
def test_module_simple(): modules = [Module(name=f"{index}") for index in range(4)] modules[1].imports = {modules[0]} modules[2].imports = {modules[0]} modules[3].imports = {modules[1], modules[2]} solver = ModuleImportSolver() plan = solver.solve(modules) order = plan.steps assert len(order[0]) == 1 and modules[0] in order[0] assert len( order[1]) == 2 and modules[1] in order[1] and modules[2] in order[1] assert len(order[2]) == 1 and modules[3] in order[2]
def __init__( self, *iterables: Iterable[ModuleElement], imports: Collection[ModuleImportType] = (), name: Optional[str] = None, global_: bool = False, agg_checks: Iterable[IsAggregationType] = (), ): super().__init__( module=Module(name=name), properties=MutableModuleProperties(global_=global_, module_agg=[*agg_checks]), ) self._imports(*imports) self._include(*iterables)
def _restricted_from(cls, global_module: Module): yield global_module yield from global_module.recursive_imports()
def inconsistent_module(self): return Module( name="Ic", elements={*self.a_module.elements}, exports={*self.b_module.elements}, )
def a_ma_module(self): return Module( name="Ama", elements={*self.a_ma_elements}, exports={*self.a_ma_elements}, )