Skip to content

Commit

Permalink
Merge pull request #5 from cjarmstrong97/testing
Browse files Browse the repository at this point in the history
Final Testing Pull
  • Loading branch information
cjarmstrong97 authored Sep 3, 2021
2 parents 10213ab + 321c6a0 commit 3d251dc
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 112 deletions.
4 changes: 0 additions & 4 deletions bionetgen/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions tests/models/DAT_validate/test.dat
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/models/actions/no_actions.bngl
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions tests/models/test_tfun.bngl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
228 changes: 124 additions & 104 deletions tests/test_bionetgen.py
Original file line number Diff line number Diff line change
@@ -1,130 +1,150 @@
import os, glob
import shutil
from pytest import raises
import bionetgen as bng
from bionetgen.main import BioNetGenTest

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))
Expand Down

0 comments on commit 3d251dc

Please sign in to comment.