def test_form_itemFactory_selection(qtbot): """Checks that the TaurusForm itemFactory selection API works""" lines = ["test_Form_ItemFactorySel={}:_DummyItemFactory".format(__name__)] group = "taurus.form.item_factories" mapping = mock_entry_point(lines, group=group) ep1 = mapping[group]["test_Form_ItemFactorySel"] w = TaurusForm() qtbot.addWidget(w) # the test_Form_ItemFactory should be in the default factories default_factories = w.getItemFactories() assert ep1 in default_factories # no factories should be excluded by default inc, exc = w.getItemFactories(return_disabled=True) assert exc == [] # Check that we can deselect all factories no_factories = w.setItemFactories(include=[]) assert no_factories == [] # Check that we can exclude everything except test_Form_ItemFactory select1 = w.setItemFactories(exclude=[r"(?!.*test_Form_ItemFactorySel).*"]) assert select1 == [ep1] # Check that we can include only test_Form_ItemFactory select2 = w.setItemFactories(include=["test_Form_ItemFactorySel"]) assert select2 == [ep1] # Check that the selected test_Form_ItemFactory is an entry point from pkg_resources import EntryPoint assert type(select2[0]) == EntryPoint # Check that the selected entry point loads _DummyItemFactory assert select2[0].load() is _DummyItemFactory # Check that we can include a factory instance select3 = w.setItemFactories(include=[_DummyItemFactory]) # Check that the selected test_Form_ItemFactory is an entry point-alike from taurus.core.util.plugin import EntryPointAlike assert type(select3[0]) == EntryPointAlike # Check that the selected entry point loads _DummyItemFactory assert select3[0].load() is _DummyItemFactory # Check that the selected entry point has the given name assert select3[0].name == repr(_DummyItemFactory)