From 36761c39e2fd64d3da94472e2a7d4f11f82b5aa7 Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 10:24:47 -0400 Subject: [PATCH 1/8] Fixed the input for test_bionetgen_input, removed a few comments --- bionetgen/core/main.py | 6 +- bionetgen/main.py | 2 +- tests/test_bionetgen.py | 173 +++++++++++++++++++--------------------- 3 files changed, 86 insertions(+), 95 deletions(-) diff --git a/bionetgen/core/main.py b/bionetgen/core/main.py index ff07386..4615d16 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()) @@ -216,4 +212,4 @@ def run(self): os.environ["BNGPATH"] = self.old_bngpath raise ValueError( "Failed to run your BNGL file, there might be an issue with your model!" - ) + ) \ No newline at end of file diff --git a/bionetgen/main.py b/bionetgen/main.py index b8aad47..81d9b0d 100644 --- a/bionetgen/main.py +++ b/bionetgen/main.py @@ -397,4 +397,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index b20abc9..dfc1bb2 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,24 +6,24 @@ 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_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_input(): + # test basic command help + 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(): @@ -33,79 +32,78 @@ # 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_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_model_running_lib(): # test running a few models using the library - # models = ["test_MM.bngl", "motor.bngl", "simple_system.bngl"] - models = ["test_MM.bngl"] + models = ["test_MM.bngl", "motor.bngl", "simple_system.bngl"] succ = [] fail = [] success = 0 @@ -114,9 +112,6 @@ def test_model_running_lib(): fpath = os.path.join(*[tfold, "models", model]) fpath = os.path.abspath(fpath) 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) success += 1 succ.append(model) From 93f25a570042a9b8e99cad92d8c58e89ddbe30cf Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 10:25:25 -0400 Subject: [PATCH 2/8] Once again forgot to run linter on previous changes --- bionetgen/core/main.py | 2 +- bionetgen/main.py | 2 +- tests/test_bionetgen.py | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bionetgen/core/main.py b/bionetgen/core/main.py index 4615d16..c576a11 100644 --- a/bionetgen/core/main.py +++ b/bionetgen/core/main.py @@ -212,4 +212,4 @@ def run(self): os.environ["BNGPATH"] = self.old_bngpath raise ValueError( "Failed to run your BNGL file, there might be an issue with your model!" - ) \ No newline at end of file + ) diff --git a/bionetgen/main.py b/bionetgen/main.py index 81d9b0d..b8aad47 100644 --- a/bionetgen/main.py +++ b/bionetgen/main.py @@ -397,4 +397,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index dfc1bb2..8a3c01f 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -17,7 +17,13 @@ def test_bionetgen_help(): def test_bionetgen_input(): # test basic command help - argv = ["run", "-i", os.path.join(tfold, "test.bngl"), "-o", os.path.join(tfold, "test")] + 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() From da40af61ba5dfc67a55194734823cfae56cae4ac Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 12:02:44 -0400 Subject: [PATCH 3/8] Trying to test run all models --- tests/test_bionetgen.py | 47 ++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index 8a3c01f..1283ee8 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -7,7 +7,7 @@ def test_bionetgen_help(): - # test basic command help + # tests basic command help with raises(SystemExit): argv = ["--help"] with BioNetGenTest(argv=argv) as app: @@ -16,7 +16,6 @@ def test_bionetgen_help(): def test_bionetgen_input(): - # test basic command help argv = [ "run", "-i", @@ -32,13 +31,14 @@ def test_bionetgen_input(): 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_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 = [] @@ -56,20 +56,21 @@ def test_bionetgen_all_model_loading(): fails += 1 fail.append(model) print("succ: {}".format(success)) - # print(sorted(succ)) + 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", "all_actions.bngl"]) m = bng.bngmodel(all_action_model) assert len(m.actions) == 27 def test_bionetgen_info(): - # test info subcommand + # tests info subcommand argv = ["info"] with BioNetGenTest(argv=argv) as app: app.run() @@ -77,29 +78,29 @@ def test_bionetgen_info(): def test_model_running_CLI(): - # test running a few models using the CLI - models = ["test_MM.bngl", "motor.bngl", "simple_system.bngl"] + # 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 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"] + argv = ["run", "-i", model, "-o", "cli_test_runs"] 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) - del model, fpath print("succ: {}".format(success)) print(sorted(succ)) print("fail: {}".format(fails)) @@ -108,24 +109,26 @@ def test_model_running_CLI(): def test_model_running_lib(): - # test running a few models using the library - models = ["test_MM.bngl", "motor.bngl", "simple_system.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) try: - 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)) From a116be05802fc12e7a687a25c010055df60e6db0 Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 12:04:13 -0400 Subject: [PATCH 4/8] Forgot to run linter again --- tests/test_bionetgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index 1283ee8..b346452 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -79,7 +79,7 @@ def test_bionetgen_info(): def test_model_running_CLI(): # tests running a list of models using the CLI - mpattern = os.path.join(tfold, "models") + os.sep +"*.bngl" + mpattern = os.path.join(tfold, "models") + os.sep + "*.bngl" models = glob.glob(mpattern) succ = [] fail = [] From 77fd68ac1953331a0670a5da9c8664f17b45c866 Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 12:08:03 -0400 Subject: [PATCH 5/8] Changed cli_tests.yaml to include testing branch --- .github/workflows/cli_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cli_tests.yml b/.github/workflows/cli_tests.yml index 5192622..29875fd 100644 --- a/.github/workflows/cli_tests.yml +++ b/.github/workflows/cli_tests.yml @@ -7,6 +7,7 @@ on: push: branches: - main + - testing jobs: deploy: From f5dd0611c7dbfea9dcceded1cdbdba6c0617693f Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 14:59:34 -0400 Subject: [PATCH 6/8] Fixed model running test functionality --- tests/models/DAT_validate/test.dat | 9 +++++++++ tests/models/{ => actions}/all_actions.bngl | 0 tests/models/actions/no_actions.bngl | 12 ++++++++++++ tests/models/test_tfun.bngl | 8 ++++---- tests/test_bionetgen.py | 18 ++++++++++++++---- 5 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 tests/models/DAT_validate/test.dat rename tests/models/{ => actions}/all_actions.bngl (100%) create mode 100644 tests/models/actions/no_actions.bngl 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 b346452..6304ba8 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -64,9 +64,13 @@ def test_bionetgen_all_model_loading(): def test_action_loading(): # tests a BNGL file containing all BNG actions - all_action_model = os.path.join(*[tfold, "models", "all_actions.bngl"]) - m = bng.bngmodel(all_action_model) - assert len(m.actions) == 27 + 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(): @@ -85,9 +89,13 @@ def test_model_running_CLI(): 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", "cli_test_runs"] + 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 @@ -117,6 +125,8 @@ def test_model_running_lib(): success = 0 fails = 0 for model in models: + if "test_tfun" in model: + continue try: bng.run(model) success += 1 From ad812fa38fa3a0e88775c6b6062a82e36ff94305 Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 15:00:41 -0400 Subject: [PATCH 7/8] Once again forgot to run linter on previous changes --- tests/test_bionetgen.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_bionetgen.py b/tests/test_bionetgen.py index 6304ba8..495074d 100644 --- a/tests/test_bionetgen.py +++ b/tests/test_bionetgen.py @@ -93,9 +93,15 @@ def test_model_running_CLI(): 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","") + model_name = os.path.basename(model).replace(".bngl", "") try: - argv = ["run", "-i", model, "-o", os.path.join(*[tfold, "models", "cli_test_runs", model_name])] + 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 From 321c6a0712f85596bbd2efab406e071357c01dd9 Mon Sep 17 00:00:00 2001 From: cjarmstrong97 Date: Fri, 3 Sep 2021 16:13:03 -0400 Subject: [PATCH 8/8] Removed testing branch from cli_tests --- .github/workflows/cli_tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cli_tests.yml b/.github/workflows/cli_tests.yml index 29875fd..5192622 100644 --- a/.github/workflows/cli_tests.yml +++ b/.github/workflows/cli_tests.yml @@ -7,7 +7,6 @@ on: push: branches: - main - - testing jobs: deploy: