def setUp(self): """ Make any objects that are used in multiple tests. """ self.ens_n = test_funcs.build_ensemble( qp.stats.norm_gen.test_data['norm']) self.ens_n_shift = test_funcs.build_ensemble( qp.stats.norm_gen.test_data['norm_shifted'])
def test_norm(self): key = 'norm' test_data = qp.stats.norm_gen.test_data[key] self.ens_norm = build_ensemble(test_data) assert hasattr(self.ens_norm, 'gen_func') assert isinstance(self.ens_norm.gen_obj, qp.stats.norm_gen) assert 'loc' in self.ens_norm.frozen.kwds self._run_ensemble_funcs(self.ens_norm, test_data['test_xvals'])
def test_hist(self): key = 'hist' test_data = qp.hist_gen.test_data[key] self.ens_h = build_ensemble(test_data) assert isinstance(self.ens_h.gen_obj, qp.hist_gen) self._run_ensemble_funcs(self.ens_h, test_data['test_xvals']) pdfs_mod = copy.copy(self.ens_h.dist.pdfs) pdfs_mod[:, 7] = 0.5 * pdfs_mod[:, 7] self.ens_h.update_objdata(dict(pdfs=pdfs_mod))
kw_test_convert = dict(atol_diff=val.pop('atol_diff', 1e-2), atol_diff2=val.pop('atol_diff2', 1e-2)) the_convert_func = partial(test_funcs.run_convert_tests, ens_orig=ens_orig, gen_class=test_class, test_data=val, **kw_test_convert) setattr(cls, 'test_convert_%s' % key, the_convert_func) test_plot = val.pop('test_plot', True) if test_plot: kw_test_plot = dict(do_samples=val.pop('do_samples', False)) the_plot_func = partial(test_funcs.run_plotting_func_tests, val, **kw_test_plot) setattr(cls, 'test_plotting_%s' % key, the_plot_func) @classmethod def auto_add(cls, class_list, ens_orig): """Add tests as member functions to a class""" for test_class in class_list: if hasattr(test_class, 'test_data'): cls.auto_add_class(test_class, ens_orig) ENS_ORIG = test_funcs.build_ensemble(qp.stats.norm_gen.test_data['norm']) TEST_CLASSES = qp.instance().values() PDFTestCase.auto_add(TEST_CLASSES, ENS_ORIG) if __name__ == '__main__': unittest.main()