def test_bad_class(self): """This returns a class which doesn't inherient from fitter """ mock_entry_badclass = mock.create_autospec(EntryPoint) mock_entry_badclass.name = "BadClass" mock_entry_badclass.load = self.returnbadclass with pytest.warns(AstropyUserWarning, match=r".*BadClass.*"): populate_entry_points([mock_entry_badclass])
def test_bad_func(self): """This returns a function which fails the type check""" mock_entry_badfunc = mock.create_autospec(EntryPoint) mock_entry_badfunc.name = "BadFunc" mock_entry_badfunc.load = self.returnbadfunc with pytest.warns(AstropyUserWarning, match=r".*Class.*"): populate_entry_points([mock_entry_badfunc])
def test_import_error(self): """This raises an import error on load to test that it is handled correctly""" mock_entry_importerror = mock.create_autospec(EntryPoint) mock_entry_importerror.name = "IErr" mock_entry_importerror.load = self.raiseimporterror with pytest.warns(AstropyUserWarning, match=r".*ImportError.*"): populate_entry_points([mock_entry_importerror])
def test_bad_class(self): """This returns a class which doesn't inherient from fitter """ with warnings.catch_warnings(): warnings.filterwarnings('error') try: mock_entry_badclass = mock.create_autospec(EntryPoint) mock_entry_badclass.name = "BadClass" mock_entry_badclass.load = self.returnbadclass populate_entry_points([mock_entry_badclass]) except AstropyUserWarning as w: if 'modeling.Fitter' in w.args[0]: # any error for this case should have this in it. pass else: raise w else: raise self.exception_not_thrown
def test_bad_func(self): """This returns a function which fails the type check""" with warnings.catch_warnings(): warnings.filterwarnings('error') try: mock_entry_badfunc = mock.create_autospec(EntryPoint) mock_entry_badfunc.name = "BadFunc" mock_entry_badfunc.load = self.returnbadfunc populate_entry_points([mock_entry_badfunc]) except AstropyUserWarning as w: if "Class" in w.args[0]: # any error for this case should have this in it. pass else: raise w else: raise self.exception_not_thrown
def test_import_error(self): """This raises an import error on load to test that it is handled correctly""" with warnings.catch_warnings(): warnings.filterwarnings('error') try: mock_entry_importerror = mock.create_autospec(EntryPoint) mock_entry_importerror.name = "IErr" mock_entry_importerror.load = self.raiseimporterror populate_entry_points([mock_entry_importerror]) except AstropyUserWarning as w: if "ImportError" in w.args[0]: # any error for this case should have this in it. pass else: raise w else: raise self.exception_not_thrown
def test_working(self): """This should work fine""" mock_entry_working = mock.create_autospec(EntryPoint) mock_entry_working.name = "Working" mock_entry_working.load = self.successfulimport populate_entry_points([mock_entry_working])