def test_unsupported_versions_to_json(self, unsupported_version): counterfactual_explanations = CounterfactualExplanations( cf_examples_list=[], local_importance=None, summary_importance=None, version=unsupported_version) with pytest.raises(UserConfigValidationException) as ucve: counterfactual_explanations.to_json() assert "Unsupported serialization version {}".format(unsupported_version) in str(ucve)
def test_serialization_deserialization_counterfactual_explanations_class( self): counterfactual_explanations = CounterfactualExplanations( cf_examples_list=[], local_importance=None, summary_importance=None) assert counterfactual_explanations.cf_examples_list is not None assert len(counterfactual_explanations.cf_examples_list) == 0 assert counterfactual_explanations.summary_importance is None assert counterfactual_explanations.local_importance is None assert counterfactual_explanations.metadata is not None assert counterfactual_explanations.metadata['version'] is not None assert counterfactual_explanations.metadata['version'] == '1.0' counterfactual_explanations_as_json = counterfactual_explanations.to_json( ) recovered_counterfactual_explanations = CounterfactualExplanations.from_json( counterfactual_explanations_as_json) assert counterfactual_explanations == recovered_counterfactual_explanations
def test_empty_counterfactual_explanations_object(self, version): counterfactual_explanations = CounterfactualExplanations( cf_examples_list=[], local_importance=None, summary_importance=None, version=version) self.verify_counterfactual_explanations(counterfactual_explanations, None, 0, version) counterfactual_explanations_as_json = counterfactual_explanations.to_json() assert counterfactual_explanations_as_json is not None recovered_counterfactual_explanations = CounterfactualExplanations.from_json( counterfactual_explanations_as_json) self.verify_counterfactual_explanations(recovered_counterfactual_explanations, None, 0, version) assert counterfactual_explanations == recovered_counterfactual_explanations