How to use test_single_run method in Molotov

Best Python code snippet using molotov_python

workflow_test.py

Source:workflow_test.py Github

copy

Full Screen

...14class Base(object):15 """Base class to test the full workflow16 """17 @pytest.mark.workflowtest18 def test_single_run(self, extension, bilby=False):19 """Test the full workflow for a single result file case20 Parameters21 ----------22 result_file: str23 path to result file you wish to run with24 """25 opts, inputs = make_argparse(outdir=self.tmpdir, 26 gw=False, extension=extension, bilby=bilby)27 func = functions(opts)28 PlotGeneration(inputs)29 WebpageGeneration(inputs)30 func["MetaFile"](inputs)31 func["FinishingTouches"](inputs)32 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))33 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))34 assert all(i == j for i, j in zip(plots, get_list_of_plots(outdir=self.tmpdir, gw=False)))35 assert all(i in plots for i in get_list_of_plots(outdir=self.tmpdir, gw=False))36 assert all(i in get_list_of_plots(outdir=self.tmpdir, gw=False) for i in plots)37 assert all(i == j for i, j in zip(files, get_list_of_files(outdir=self.tmpdir, gw=False)))38 assert all(i in files for i in get_list_of_files(outdir=self.tmpdir, gw=False))39 assert all(i in get_list_of_files(outdir=self.tmpdir, gw=False) for i in files)40 self.check_samples(extension, bilby=bilby)41 def check_samples(self, extension, bilby=False):42 """Check that the samples in the result file are consistent with the43 inputs44 """45 from pesummary.core.file.read import read46 initial_samples = read_result_file(extension=extension, bilby=bilby, outdir=self.tmpdir)47 data = read("{}/samples/posterior_samples.h5".format(self.tmpdir))48 samples = data.samples_dict49 label = data.labels[0]50 for param in initial_samples.keys():51 for i, j in zip(initial_samples[param], samples[label][param]):52 assert np.round(i, 8) == np.round(j, 8)53 54class GWBase(Base):55 """Base class to test the full workflow including gw specific options56 """57 @pytest.mark.workflowtest58 def test_single_run(self, extension, bilby=False, lalinference=False):59 """Test the full workflow for a single result file case60 Parameters61 ----------62 result_file: str63 path to result file you wish to run with64 """65 opts, inputs = make_argparse(outdir=self.tmpdir, 66 gw=True, extension=extension, bilby=bilby, lalinference=lalinference)67 print(opts)68 func = functions(opts)69 PlotGeneration(inputs, gw=True)70 WebpageGeneration(inputs, gw=True)71 func["MetaFile"](inputs)72 func["FinishingTouches"](inputs)73 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))74 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))75 assert all(i == j for i, j in zip(plots, get_list_of_plots(outdir=self.tmpdir, gw=True)))76 assert all(i in plots for i in get_list_of_plots(outdir=self.tmpdir, gw=True))77 assert all(i in get_list_of_plots(outdir=self.tmpdir, gw=True) for i in plots)78 for i, j in zip(files, get_list_of_files(outdir=self.tmpdir, gw=True)):79 print(i, j)80 assert all(i == j for i, j in zip(files, get_list_of_files(outdir=self.tmpdir, gw=True)))81 assert all(i in files for i in get_list_of_files(outdir=self.tmpdir, gw=True))82 assert all(i in get_list_of_files(outdir=self.tmpdir, gw=True) for i in files)83 self.check_samples(extension, bilby=bilby, lalinference=lalinference)84 def check_samples(self, extension, bilby=False, lalinference=False):85 """Check that the samples in the result file are consistent with the86 inputs87 """88 from pesummary.core.file.read import read89 initial_samples = read_result_file(90 extension=extension, bilby=bilby, lalinference=lalinference,91 outdir=self.tmpdir92 )93 data = read("{}/samples/posterior_samples.h5".format(self.tmpdir))94 samples = data.samples_dict95 label = data.labels[0]96 for param in initial_samples.keys():97 for i, j in zip(initial_samples[param], samples[label][param]):98 assert np.round(i, 8) == np.round(j, 8)99class TestCoreDat(Base):100 """Test the full workflow with a core dat file101 """102 def setup(self):103 """Setup the TestCoreDat class104 """105 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name106 if not os.path.isdir(self.tmpdir):107 os.mkdir(self.tmpdir)108 def teardown(self):109 """Remove the files and directories created from this class110 """111 if os.path.isdir(self.tmpdir):112 shutil.rmtree(self.tmpdir)113 @pytest.mark.workflowtest114 def test_single_run(self):115 """Test the full workflow with a core dat result file116 """117 extension = "dat"118 super(TestCoreDat, self).test_single_run(extension)119class TestCoreJson(Base):120 """Test the full workflow with a core json file121 """122 def setup(self):123 """Setup the TestCoreJson class124 """125 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name126 if not os.path.isdir(self.tmpdir):127 os.mkdir(self.tmpdir)128 def teardown(self):129 """Remove the files and directories created from this class130 """131 if os.path.isdir(self.tmpdir):132 shutil.rmtree(self.tmpdir)133 @pytest.mark.workflowtest134 def test_single_run(self):135 """Test the full workflow with a core json result file136 """137 extension = "json"138 super(TestCoreJson, self).test_single_run(extension)139class TestCoreHDF5(Base):140 """Test the full workflow with a core hdf5 file141 """142 def setup(self):143 """Setup the TestCoreHDF5 class144 """145 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name146 if not os.path.isdir(self.tmpdir):147 os.mkdir(self.tmpdir)148 def teardown(self):149 """Remove the files and directories created from this class150 """151 if os.path.isdir(self.tmpdir):152 shutil.rmtree(self.tmpdir)153 @pytest.mark.workflowtest154 def test_single_run(self):155 """Test the full workflow with a core hdf5 result file156 """157 extension = "h5"158 super(TestCoreHDF5, self).test_single_run(extension)159class TestCoreBilbyJson(Base):160 """Test the full workflow with a core json bilby file161 """162 def setup(self):163 """Setup the TestCoreBilby class164 """165 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name166 if not os.path.isdir(self.tmpdir):167 os.mkdir(self.tmpdir)168 def teardown(self):169 """Remove the files and directories created from this class170 """171 if os.path.isdir(self.tmpdir):172 shutil.rmtree(self.tmpdir)173 if os.path.isdir("{}_pesummary".format(self.tmpdir)):174 shutil.rmtree("{}_pesummary".format(self.tmpdir))175 @pytest.mark.workflowtest176 def test_single_run(self):177 """Test the full workflow with a core bilby result file178 """179 extension = "json"180 super(TestCoreBilbyJson, self).test_single_run(extension, bilby=True)181 @pytest.mark.workflowtest182 def test_double_run(self):183 """Test the full workflow for 2 lalinference result files184 """185 opts, inputs = make_argparse(outdir=self.tmpdir, 186 gw=False, extension="json", bilby=True, number=2)187 func = functions(opts)188 PlotGeneration(inputs)189 WebpageGeneration(inputs)190 func["MetaFile"](inputs)191 func["FinishingTouches"](inputs)192 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))193 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))194 assert all(i == j for i, j in zip(plots, get_list_of_plots(outdir=self.tmpdir, 195 gw=False, number=2)))196 assert all(i in plots for i in get_list_of_plots(outdir=self.tmpdir, gw=False, number=2))197 assert all(i in get_list_of_plots(outdir=self.tmpdir, gw=False, number=2) for i in plots)198 assert all(i == j for i, j in zip(files, get_list_of_files(outdir=self.tmpdir, 199 gw=False, number=2)))200 assert all(i in files for i in get_list_of_files(outdir=self.tmpdir, gw=False, number=2))201 assert all(i in get_list_of_files(outdir=self.tmpdir, gw=False, number=2) for i in files)202 @pytest.mark.workflowtest203 def test_existing_run(self):204 """Test the fill workflow for when you add to an existing webpage205 """206 opts, inputs = make_argparse(outdir=self.tmpdir, 207 gw=False, extension="json", bilby=True)208 func = functions(opts)209 PlotGeneration(inputs)210 WebpageGeneration(inputs)211 func["MetaFile"](inputs)212 func["FinishingTouches"](inputs)213 opts, inputs = make_argparse(outdir=self.tmpdir, 214 gw=False, extension="json", bilby=True, existing=True)215 func = functions(opts)216 PlotGeneration(inputs)217 WebpageGeneration(inputs)218 func["MetaFile"](inputs)219 func["FinishingTouches"](inputs)220 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))221 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))222 assert all(i == j for i, j in zip(plots, get_list_of_plots(outdir=self.tmpdir, 223 gw=False, number=2)))224 assert all(i in plots for i in get_list_of_plots(outdir=self.tmpdir, gw=False, number=2))225 assert all(i in get_list_of_plots(outdir=self.tmpdir, gw=False, number=2) for i in plots)226 assert all(i == j for i, j in zip(files, get_list_of_files(outdir=self.tmpdir, 227 gw=False, number=2)))228 assert all(i in files for i in get_list_of_files(outdir=self.tmpdir, gw=False, number=2))229 assert all(i in get_list_of_files(outdir=self.tmpdir, gw=False, number=2) for i in files)230 @pytest.mark.workflowtest231 def test_pesummary_input(self):232 """Test the full workflow for a pesummary input file233 """234 opts, inputs = make_argparse(outdir=self.tmpdir, 235 gw=False, extension="json", bilby=True, number=2)236 func = functions(opts)237 PlotGeneration(inputs)238 WebpageGeneration(inputs)239 func["MetaFile"](inputs)240 func["FinishingTouches"](inputs)241 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))242 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))243 from pesummary.core.cli.command_line import command_line244 parser = command_line()245 default_args = ["--webdir", "{}_pesummary".format(self.tmpdir),246 "--samples", "{}/samples/posterior_samples.h5".format(self.tmpdir),247 "--disable_expert"]248 opts = parser.parse_args(default_args)249 func = functions(opts)250 inputs = func["input"](opts)251 PlotGeneration(inputs)252 WebpageGeneration(inputs)253 func["MetaFile"](inputs)254 func["FinishingTouches"](inputs)255 plots_pesummary = sorted(glob.glob("{}_pesummary/plots/*.png".format(self.tmpdir)))256 files_pesummary = sorted(glob.glob("{}_pesummary/html/*.html".format(self.tmpdir)))257 assert all(i.split("/")[-1] == j.split("/")[-1] for i, j in zip(258 plots, plots_pesummary))259 assert all(i.split("/")[-1] == j.split("/")[-1] for i, j in zip(260 files, files_pesummary))261class TestCoreBilbyHDF5(Base):262 """Test the full workflow with a core hdf5 bilby file263 """264 def setup(self):265 """Setup the TestCoreBilby class266 """267 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name268 if not os.path.isdir(self.tmpdir):269 os.mkdir(self.tmpdir)270 def teardown(self):271 """Remove the files and directories created from this class272 """273 if os.path.isdir(self.tmpdir):274 shutil.rmtree(self.tmpdir)275 @pytest.mark.workflowtest276 def test_single_run(self):277 """Test the full workflow with a core bilby result file278 """279 extension = "h5"280 super(TestCoreBilbyHDF5, self).test_single_run(extension, bilby=True)281class TestGWDat(GWBase):282 """Test the full workflow with a gw dat file283 """284 def setup(self):285 """Setup the TestCoreDat class286 """287 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name288 if not os.path.isdir(self.tmpdir):289 os.mkdir(self.tmpdir)290 def teardown(self):291 """Remove the files and directories created from this class292 """293 if os.path.isdir(self.tmpdir):294 shutil.rmtree(self.tmpdir)295 @pytest.mark.workflowtest296 def test_single_run(self):297 """Test the full workflow with a gw dat result file298 """299 extension = "dat"300 super(TestGWDat, self).test_single_run(extension)301class TestGWJson(GWBase):302 """Test the full workflow with a json dat file303 """304 def setup(self):305 """Setup the TestGWJson class306 """307 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name308 if not os.path.isdir(self.tmpdir):309 os.mkdir(self.tmpdir)310 def teardown(self):311 """Remove the files and directories created from this class312 """313 if os.path.isdir(self.tmpdir):314 shutil.rmtree(self.tmpdir)315 @pytest.mark.workflowtest316 def test_single_run(self):317 """Test the full workflow with a gw json result file318 """319 extension = "json"320 super(TestGWJson, self).test_single_run(extension)321class TestGWBilbyJson(GWBase):322 """Test the full workflow with a gw bilby json file323 """324 def setup(self):325 """Setup the TestGWJson class326 """327 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name328 if not os.path.isdir(self.tmpdir):329 os.mkdir(self.tmpdir)330 def teardown(self):331 """Remove the files and directories created from this class332 """333 if os.path.isdir(self.tmpdir):334 shutil.rmtree(self.tmpdir)335 @pytest.mark.workflowtest336 def test_single_run(self):337 """Test the full workflow with a gw bilby json result file338 """339 extension = "json"340 super(TestGWBilbyJson, self).test_single_run(extension, bilby=True)341class TestGWBilbyHDF5(GWBase):342 """Test the full workflow with a gw bilby HDF5 file343 """344 def setup(self):345 """Setup the TestGWJson class346 """347 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name348 if not os.path.isdir(self.tmpdir):349 os.mkdir(self.tmpdir)350 def teardown(self):351 """Remove the files and directories created from this class352 """353 if os.path.isdir(self.tmpdir):354 shutil.rmtree(self.tmpdir)355 @pytest.mark.workflowtest356 def test_single_run(self):357 """Test the full workflow with a gw bilby HDF5 result file358 """359 extension = "h5"360 super(TestGWBilbyHDF5, self).test_single_run(extension, bilby=True)361class TestGWLALInference(GWBase):362 """Test the full workflow with a lalinference file363 """364 def setup(self):365 """Setup the TestGWJson class366 """367 self.tmpdir = tempfile.TemporaryDirectory(prefix=".", dir=".").name368 if not os.path.isdir(self.tmpdir):369 os.mkdir(self.tmpdir)370 def teardown(self):371 """Remove the files and directories created from this class372 """373 if os.path.isdir(self.tmpdir):374 shutil.rmtree(self.tmpdir)375 if os.path.isdir("{}_pesummary".format(self.tmpdir)):376 shutil.rmtree("{}_pesummary".format(self.tmpdir))377 @pytest.mark.workflowtest378 def test_single_run(self):379 """Test the full workflow with a lalinference result file380 """381 extension = "hdf5"382 super(TestGWLALInference, self).test_single_run(extension, lalinference=True)383 @pytest.mark.workflowtest384 def test_double_run(self):385 """Test the full workflow for 2 lalinference result files386 """387 opts, inputs = make_argparse(outdir=self.tmpdir, 388 gw=True, extension="hdf5", lalinference=True, number=2)389 func = functions(opts)390 PlotGeneration(inputs, gw=True)391 WebpageGeneration(inputs, gw=True)392 func["MetaFile"](inputs)393 func["FinishingTouches"](inputs)394 plots = sorted(glob.glob("{}/plots/*.png".format(self.tmpdir)))395 files = sorted(glob.glob("{}/html/*.html".format(self.tmpdir)))396 assert all(i == j for i, j in zip(plots, get_list_of_plots(outdir=self.tmpdir, ...

Full Screen

Full Screen

simulator_test.py

Source:simulator_test.py Github

copy

Full Screen

...37 plt.legend(loc="upper right")38 plt.xlabel('staff num')39 plt.ylabel('y axis')4041def test_single_run(simulator, round):42 (average_staff_used, average_time_waited) = simulator.run(round)43 print(average_staff_used)44 print(average_time_waited)4546def test_staff_num(simulator, round):47 total_staff_used_list = []48 total_time_waited_list = []49 staff_num_list = [i for i in range(1, GROUP_SIZE + 1)]5051 for staff_num in range(1, GROUP_SIZE + 1):52 print("this is time %d" % staff_num)53 simulator.set_staff_num(staff_num)54 (average_staff_used, average_time_waited) = simulator.run(round)55 total_staff_used_list.append(average_staff_used)56 total_time_waited_list.append(average_time_waited)5758 return total_staff_used_list, total_time_waited_list5960def test_influence_of_distance(simulator, round, range_start, range_end):61 rec_total_staff_used_list = []62 rec_total_time_waited_list = []63 rec_staff_num_list = []64 for distance in range(range_start, range_end):65 simulator.set_distance(distance)66 print("\n\n\n\n\nthis is distance %d\n\n\n\n\n" % distance)67 (total_staff_used_list, total_time_waited_list) = test_staff_num(simulator, round)68 rec_total_staff_used_list.append(total_staff_used_list)69 rec_total_time_waited_list.append(total_time_waited_list)70 rec_staff_num_list.append([i for i in range(1, GROUP_SIZE + 1)])7172 draw_graph_staff_num(rec_staff_num_list, rec_total_staff_used_list)73 draw_graph_time_waited(rec_staff_num_list, rec_total_time_waited_list)74 plt.show()757677if __name__ == '__main__':78 test_round = 1000079 simulator = Simulator(FAILURE_RATE, GROUP_SIZE, GROUP_NUM, STAFF_NUM, GROUP_INTERVAL, MACHINE_INTERVAL, SPEED, FIX_TIME, X_DIVIDE)80 # test_influence_of_distance(simulator, test_round, 0, 1)81 time_start = time.time()82 test_single_run(simulator, test_round)83 time_end = time.time()84 print("time for this run is:")85 print(time_end - time_start)8687 # (total_staff_used_list, total_time_waited_list) = test_staff_num(simulator, test_round)88 # draw_graph_time_waited([[i for i in range(1, GROUP_SIZE + 1)]], [total_time_waited_list])89 # plt.show()909192 # result_staff = []93 # result_waited_time = []94 # staff_num_list = []95 # for i in range(1, GROUP_SIZE + 1):96 # simulator.set_staff_num(i) ...

Full Screen

Full Screen

test_enrichr.py

Source:test_enrichr.py Github

copy

Full Screen

...4from magine.enrichment.enrichr import Enrichr, clean_drug_dbs, clean_tf_names, \5 get_background_list, get_libraries, run_enrichment_for_project6from magine.tests.sample_experimental_data import exp_data7e = Enrichr()8def test_single_run():9 e.print_valid_libs()10 list_2 = ['CASP3', 'CASP6', 'FAS', 'FADD', 'CASP8', 'CFLAR', 'BFAR', 'BAD',11 'BID', 'PMAIP1', 'MCL1', 'BCL2', 'BCL2L1', 'BAX', 'BAK1',12 'DIABLO', 'CYCS', 'PARP1', 'APAF1', 'XIAP']13 df = e.run(list_2, 'GO_Biological_Process_2017')14 terms = df['term_name']15 ok_(len(terms) == 185)16def test_libaries():17 get_libraries()18def test_project():19 slimmed = exp_data.species.copy()20 slimmed = slimmed.loc[slimmed.source.isin(['label_free', 'silac'])]21 slimmed = slimmed.loc[slimmed.sample_id.isin(['Time_1', 'Time_2', ])]22 slimmed = ExperimentalData(slimmed)23 run_enrichment_for_project(slimmed, 'test',24 databases=['KEGG_2016'])25 slimmed = exp_data.species.copy()26 slimmed = slimmed.loc[slimmed.source.isin(['label_free'])]27 slimmed = slimmed.loc[slimmed.sample_id.isin(['Time_1', 'Time_2', ])]28 slimmed = ExperimentalData(slimmed)29 run_enrichment_for_project(slimmed, 'test',30 databases=['KEGG_2016'])31def test_get_gene_set_lib():32 get_background_list('Phosphatase_Substrates_from_DEPOD')33def test_clean_drug_dbs():34 list_2 = ['CASP3', 'CASP6', 'FAS', 'FADD', 'CASP8', 'CFLAR', 'BFAR', 'BAD',35 'BID', 'PMAIP1', 'MCL1', 'BCL2', 'BCL2L1', 'BAX', 'BAK1',36 'DIABLO', 'CYCS', 'PARP1', 'APAF1', 'XIAP']37 df = e.run(list_2, ['Drug_Perturbations_from_GEO_2014',38 'LINCS_L1000_Chem_Pert_up'39 ])40 df = clean_drug_dbs(df)41 ok_(len(df['term_name']) == 6243)42 ok_(len(df.sig['term_name']) == 249)43def test_multi_sample():44 lists = [['BAX', 'BCL2', 'CASP3'],45 ['CASP10', 'CASP8', 'BAK'],46 ['BIM', 'CASP3']]47 df2 = e.run_samples(lists, ['1', '2', '3'], save_name='enrichr_test')48 ok_(df2.shape == (111, 11))49def test_multi_sample_plotting():50 up = exp_data.genes.sig.up_by_sample51 out_dir = tempfile.mkdtemp()52 e.run_samples(up, ['1', '2', '3'],53 gene_set_lib=['Human_Phenotype_Ontology',54 'MGI_Mammalian_Phenotype_2017'],55 save_name='enrichr_test',56 exp_data=exp_data,57 create_html=True,58 pivot=True,59 out_dir=out_dir)60def test_set_of_dbs():61 lists = [['BAX', 'BCL2', 'CASP3'],62 ['CASP10', 'CASP8', 'BAK'],63 ['BIM', 'CASP3']]64 df2 = e.run_samples(lists, ['1', '2', '3'],65 gene_set_lib=['KEGG_2016', 'NCI-Nature_2016']66 )67 ok_(df2.shape == (128, 11))68def test_tf_names():69 df = e.run(['BAX', 'BCL2', 'MCL1'], ['ARCHS4_TFs_Coexp', 'ChEA_2016'])70 tfs = clean_tf_names(df)71 for i in tfs['term_name']:72 ok_('_' not in i)73if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful