diff --git a/bionetgen/core/main.py b/bionetgen/core/main.py index ff07386..c576a11 100644 --- a/bionetgen/core/main.py +++ b/bionetgen/core/main.py @@ -145,9 +145,6 @@ def _set_output(self, output): os.chdir(output) def run(self): - import ipdb - - ipdb.set_trace() try: stdout_loc = getattr(subprocess, self.stdout) except: @@ -201,7 +198,6 @@ def run(self): # print(rc.stdout.decode('utf-8')) # if rc.stderr is not None: # print(rc.stderr.decode('utf-8')) - # import ipdb;ipdb.set_trace() if rc == 0: # load in the result self.result = BNGResult(os.getcwd()) diff --git a/tests/models/DAT_validate/test.dat b/tests/models/DAT_validate/test.dat new file mode 100644 index 0000000..2496c81 --- /dev/null +++ b/tests/models/DAT_validate/test.dat @@ -0,0 +1,9 @@ +1.000000000000000000e+01 1.000000000000000000e+00 +2.000000000000000000e+01 2.000000000000000000e+00 +3.000000000000000000e+01 3.000000000000000000e+00 +4.000000000000000000e+01 4.000000000000000000e+00 +5.000000000000000000e+01 5.000000000000000000e+00 +6.000000000000000000e+01 6.000000000000000000e+00 +7.000000000000000000e+01 7.000000000000000000e+00 +8.000000000000000000e+01 8.000000000000000000e+00 +9.000000000000000000e+01 9.000000000000000000e+00 \ No newline at end of file diff --git a/tests/models/all_actions.bngl b/tests/models/actions/all_actions.bngl similarity index 100% rename from tests/models/all_actions.bngl rename to tests/models/actions/all_actions.bngl diff --git a/tests/models/actions/no_actions.bngl b/tests/models/actions/no_actions.bngl new file mode 100644 index 0000000..103cc7e --- /dev/null +++ b/tests/models/actions/no_actions.bngl @@ -0,0 +1,12 @@ +begin parameters + k 1 +end parameters +begin molecule types + A() +end molecule types +begin seed species + A() 100 +end seed species +begin reaction rules + A() -> 0 k +end reaction rules \ No newline at end of file diff --git a/tests/models/test_tfun.bngl b/tests/models/test_tfun.bngl index faf112c..56cc0ed 100644 --- a/tests/models/test_tfun.bngl +++ b/tests/models/test_tfun.bngl @@ -30,10 +30,10 @@ end observables begin functions mctr = dum/1e4 # various tests on TFUN - k1 = TFUN(mctr,'DAT_validate/test.dat') - k2 = (TFUN(mctr, "DAT_validate/test.dat")/1e1) - k3 = (TFUN(mctr, "DAT_validate/test.dat")/k_t) - k4 = (TFUN(mctr, "DAT_validate/test.dat")/mctr) + k1 = TFUN(mctr, "../../DAT_validate/test.dat") + k2 = (TFUN(mctr, "../../DAT_validate/test.dat")/1e1) + k3 = (TFUN(mctr, "../../DAT_validate/test.dat")/k_t) + k4 = (TFUN(mctr, "../../DAT_validate/test.dat")/mctr) end functions begin reaction rules diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index b20abc9..495074d 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -1,5 +1,4 @@ import os, glob -import shutil from pytest import raises import bionetgen as bng from bionetgen.main import BioNetGenTest @@ -7,124 +6,145 @@ tfold = os.path.dirname(__file__) -# def test_bionetgen_help(): -# # test basic command help -# with raises(SystemExit): -# argv = ["--help"] -# with BioNetGenTest(argv=argv) as app: -# app.run() -# assert app.exit_code == 0 - - -# def test_bionetgen_input(): -# # test basic command help -# argv = ["run", "-i", "test.bngl", "-o", os.path.join(tfold, "test")] -# to_match = ["test.xml", "test.cdat", "test.gdat", "test.net"] -# with BioNetGenTest(argv=argv) as app: -# app.run() -# assert app.exit_code == 0 -# file_list = os.listdir(os.path.join(tfold, "test")) -# assert file_list.sort() == to_match.sort() - - -# def test_bionetgen_model(): -# fpath = os.path.join(tfold, "test.bngl") -# fpath = os.path.abspath(fpath) -# m = bng.bngmodel(fpath) - - -# def test_bionetgen_all_model_loading(): -# mpattern = os.path.join(tfold, "models") + os.sep + "*.bngl" -# models = glob.glob(mpattern) -# succ = [] -# fail = [] -# success = 0 -# fails = 0 -# for model in models: -# try: -# m = bng.bngmodel(model) -# success += 1 -# mstr = str(m) -# succ.append(model) -# except: -# print("can't load model {}".format(model)) -# fails += 1 -# fail.append(model) -# print("succ: {}".format(success)) -# # print(sorted(succ)) -# print("fail: {}".format(fails)) -# print(sorted(fail)) -# assert fails == 0 - - -# def test_action_loading(): -# all_action_model = os.path.join(*[tfold, "models", "all_actions.bngl"]) -# m = bng.bngmodel(all_action_model) -# assert len(m.actions) == 27 - - -# def test_bionetgen_info(): -# # test info subcommand -# argv = ["info"] -# with BioNetGenTest(argv=argv) as app: -# app.run() -# assert app.exit_code == 0 - - -# def test_model_running_CLI(): -# # test running a few models using the CLI -# models = ["test_MM.bngl", "motor.bngl", "simple_system.bngl"] -# succ = [] -# fail = [] -# success = 0 -# fails = 0 -# for model in models: -# fpath = os.path.join(*[tfold, "models", model]) -# fpath = os.path.abspath(fpath) -# try: -# fpath = os.path.join(*[tfold, "models", model]) -# fpath = os.path.abspath(fpath) -# argv = ["run", "-i", fpath, "-o", "cli_test_runs"] -# with BioNetGenTest(argv=argv) as app: -# app.run() -# assert app.exit_code == 0 -# success += 1 -# succ.append(model) -# except: -# print("can't run model {}".format(model)) -# fails += 1 -# fail.append(model) -# del model, fpath -# print("succ: {}".format(success)) -# print(sorted(succ)) -# print("fail: {}".format(fails)) -# print(sorted(fail)) -# assert fails == 0 +def test_bionetgen_help(): + # tests basic command help + with raises(SystemExit): + argv = ["--help"] + with BioNetGenTest(argv=argv) as app: + app.run() + assert app.exit_code == 0 + + +def test_bionetgen_input(): + argv = [ + "run", + "-i", + os.path.join(tfold, "test.bngl"), + "-o", + os.path.join(tfold, "test"), + ] + to_match = ["test.xml", "test.cdat", "test.gdat", "test.net"] + with BioNetGenTest(argv=argv) as app: + app.run() + assert app.exit_code == 0 + file_list = os.listdir(os.path.join(tfold, "test")) + assert file_list.sort() == to_match.sort() + + +def test_bionetgen_model(): + fpath = os.path.join(tfold, "test.bngl") + fpath = os.path.abspath(fpath) + m = bng.bngmodel(fpath) + + +def test_bionetgen_all_model_loading(): + # tests library model loading using many models + mpattern = os.path.join(tfold, "models") + os.sep + "*.bngl" + models = glob.glob(mpattern) + succ = [] + fail = [] + success = 0 + fails = 0 + for model in models: + try: + m = bng.bngmodel(model) + success += 1 + mstr = str(m) + succ.append(model) + except: + print("can't load model {}".format(model)) + fails += 1 + fail.append(model) + print("succ: {}".format(success)) + print(sorted(succ)) + print("fail: {}".format(fails)) + print(sorted(fail)) + assert fails == 0 + + +def test_action_loading(): + # tests a BNGL file containing all BNG actions + all_action_model = os.path.join(*[tfold, "models", "actions", "all_actions.bngl"]) + m1 = bng.bngmodel(all_action_model) + assert len(m1.actions) == 27 + + no_action_model = os.path.join(*[tfold, "models", "actions", "no_actions.bngl"]) + m2 = bng.bngmodel(no_action_model) + assert len(m2.actions) == 0 + + +def test_bionetgen_info(): + # tests info subcommand + argv = ["info"] + with BioNetGenTest(argv=argv) as app: + app.run() + assert app.exit_code == 0 + + +def test_model_running_CLI(): + # tests running a list of models using the CLI + mpattern = os.path.join(tfold, "models") + os.sep + "*.bngl" + models = glob.glob(mpattern) + succ = [] + fail = [] + success = 0 + fails = 0 + test_run_folder = os.path.join(tfold, "models", "cli_test_runs") + if not os.path.isdir(test_run_folder): + os.mkdir(test_run_folder) + for model in models: + model_name = os.path.basename(model).replace(".bngl", "") + try: + argv = [ + "run", + "-i", + model, + "-o", + os.path.join(*[tfold, "models", "cli_test_runs", model_name]), + ] + with BioNetGenTest(argv=argv) as app: + app.run() + assert app.exit_code == 0 + success += 1 + model = os.path.split(model) + model = model[1] + succ.append(model) + except: + print("can't run model {}".format(model)) + fails += 1 + model = os.path.split(model) + model = model[1] + fail.append(model) + print("succ: {}".format(success)) + print(sorted(succ)) + print("fail: {}".format(fails)) + print(sorted(fail)) + assert fails == 0 def test_model_running_lib(): - # test running a few models using the library - # models = ["test_MM.bngl", "motor.bngl", "simple_system.bngl"] - models = ["test_MM.bngl"] + # test running a list of models using the library + mpattern = os.path.join(tfold, "models") + os.sep + "*.bngl" + models = glob.glob(mpattern) succ = [] fail = [] success = 0 fails = 0 for model in models: - fpath = os.path.join(*[tfold, "models", model]) - fpath = os.path.abspath(fpath) + if "test_tfun" in model: + continue try: - # result = bng.run(fpath, out="lib_test_runs") - # ONLY works if out folder is specified -- WHY? - # seems like an issue with try-except - works fine in separate .ipynb - bng.run(fpath) + bng.run(model) success += 1 + model = os.path.split(model) + model = model[1] succ.append(model) except: print("can't run model {}".format(model)) fails += 1 + model = os.path.split(model) + model = model[1] fail.append(model) - del model, fpath print("succ: {}".format(success)) print(sorted(succ)) print("fail: {}".format(fails))