def test_reraise_str(self, gamr_model: GAMR): fm = FailedModel(gamr_model, exc="foobar") with pytest.raises(RuntimeError): fm.reraise() assert isinstance(fm._exc, RuntimeError)
def test_reraise(self, gamr_model: GAMR): fm = FailedModel(gamr_model, exc=ValueError("foobar")) with pytest.raises(ValueError): fm.reraise() assert isinstance(fm._exc, ValueError)
def test_correct_gene_and_lineage(self, gamr_model): fm = FailedModel(gamr_model) assert fm.adata is gamr_model.adata assert fm.model is gamr_model assert fm._gene == gamr_model._gene assert fm._lineage == gamr_model._lineage
def test_do_nothing_no_bulk_fit(self, gamr_model: GAMR): fm = FailedModel(gamr_model) for fn in [ "prepare", "fit", "predict", "confidence_interval", "default_confidence_interval", "plot", ]: with pytest.raises(UnknownModelError): getattr(fm, fn)()
def test_do_nothing_bulk_fit(self, gamr_model: GAMR): gamr_model._is_bulk = True fm = FailedModel(gamr_model) expected_dict = fm.__dict__.copy() for fn in [ "prepare", "fit", "predict", "confidence_interval", "default_confidence_interval", "plot", ]: getattr(fm, fn)() assert expected_dict == fm.__dict__
def test_str_repr(self, gamr_model: GAMR): expected = f"<FailedModel[origin={str(gamr_model).strip('<>')}]>" fm = FailedModel(gamr_model) assert str(fm) == expected assert repr(fm) == expected
def test_exception_not_base_exception(self, gamr_model: GAMR): with pytest.raises(TypeError): _ = FailedModel(gamr_model, exc=0)
def test_copy(self, gamr_model): fm1 = FailedModel(gamr_model) fm2 = fm1.copy() assert fm1.model is not fm2.model assert fm1.adata is fm2.adata
def test_wrong_model_type(self): with pytest.raises(TypeError): _ = FailedModel(SVR())