def do_for_all_analyses(test_func): @pytest.mark.parametrize("analysis,single_hypothesis,many_hypotheses", zip(get_obj().values(), get_test_hypothesis().values(), get_hypothesis_lists().values()), ids=get_id_list()) def wrapper(analysis, single_hypothesis, many_hypotheses): test_func(analysis, single_hypothesis, many_hypotheses) return wrapper
"""Integration tests that apply to all Analysis classes, and check that they conform correctly to the required interface""" import pytest import numpy as np from tensorflow_probability import distributions as tfd from jmctf import JointDistribution from jmctf_tests.analysis_class_register import get_id_list, get_obj, get_test_hypothesis, get_hypothesis_lists # Fixture to create analysis objects and provide test parameters to use with them @pytest.fixture( scope="module", params=list(zip(get_obj().values(), get_test_hypothesis().values())) + list(zip(get_obj().values(), get_hypothesis_lists().values())), ids=[name + " (single hypothesis)" for name in get_id_list()] + [name + " (hypothesis list)" for name in get_id_list()]) def analysis_and_parameters(request): analysis, parameters = request.param return (analysis, parameters) @pytest.fixture(scope="module") def analysis(analysis_and_parameters): analy, pars = analysis_and_parameters return analy
has_curve = [ "NormalAnalysis", "NormalTEAnalysis", "BinnedAnalysis_single", "BinnedAnalysis" ] #has_curve = ["BinnedAnalysis_single"] # Number of samples to draw during tests N = 2 # Doing plotting, so don't want tonnes of curves confusing things @pytest.fixture(scope="module") def Nsamples(): return N pars_id = [(get_obj(name), ID, curve, "{0}_{1}".format(name, ID)) for name in has_curve for ID, curve in get_hypothesis_curves(name).items()] params = [x[0:3] for x in pars_id] # analysis and curve data ids = [x[3] for x in pars_id] # "Entry point" fixture providing the analysis objects and parameters for them. @pytest.fixture(scope="module", params=params, ids=ids) def analysis_ID_params(request): analysis, IDpar, params = request.param return analysis, IDpar, params @pytest.fixture(scope="module") def analysis_params(analysis_ID_params):
return hyp_gen # Special version for single hypothesis case def get_hyp_gen_1(hypothesis): def hyp_gen(): hyp_list = c.deep_expand_dims(hypothesis, 0) yield hyp_list, [0] return return hyp_gen @pytest.fixture(scope="module", params=[(get_obj(name), get_test_hypothesis(name), get_hypothesis_lists(name)) for name in analysis_tests.keys()], ids=[name for name in analysis_tests.keys()]) def analysis_params(request): analysis, params1, paramsN = request.param return analysis, params1, paramsN @pytest.fixture(scope="module", params=N_test_events) def Nevents(request): return request.param @pytest.fixture(scope="module") def analysis(analysis_params):
"NormalTEAnalysis": (N, 2, 2), "BinnedAnalysis": (N, 4, 4) } # @pytest.fixture(scope="module" # ,params=[(get_obj(name), get_test_hypothesis(name), H) for name,H in Hessians_shape.items()] # +[(get_obj(name), get_hypothesis_lists(name), H) for name,H in Hessians_shape.items()] # ,ids = [name + " (single hypothesis)" for name in Hessians_shape.keys()] # +[name + " (multiple hypotheses)" for name in Hessians_shape.keys()] # ) # "Entry point" fixture providing the analysis objects and parameters for them. @pytest.fixture( scope="module", params=[(get_obj(name), get_hypothesis_lists(name), H) for name, H in Hessians_shape.items()], ids=[name + " (multiple hypotheses)" for name in Hessians_shape.keys()]) def analysis_params_Hshape(request): analysis, params, H_shape = request.param return analysis, params, H_shape @pytest.fixture(scope="module") def analysis_params(analysis_params_Hshape): analysis, params, H_shape = analysis_params_Hshape return analysis, params @pytest.fixture(scope="module") def samples(joint0, Nsamples):