Skip to content

Commit

Permalink
Merge branch 'testing' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cjarmstrong97 authored Sep 2, 2021
2 parents f403c55 + e8b0d46 commit 10213ab
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 41 deletions.
4 changes: 4 additions & 0 deletions bionetgen/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ 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 @@ -198,6 +201,7 @@ 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
143 changes: 102 additions & 41 deletions tests/test_bionetgen.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,132 @@
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_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
os.chdir(tfold)
argv = ["run", "-i", "test.bngl", "-o", os.path.join(tfold, "test")]
to_match = ["test.xml", "test.cdat", "test.gdat", "test.net", "test.log"]
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", "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_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.path.sep + "*.bngl"
models = glob.glob(mpattern)
# 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"]
succ = []
fail = []
success = 0
fails = 0
for model in models:
fpath = os.path.join(*[tfold, "models", model])
fpath = os.path.abspath(fpath)
try:
m = bng.bngmodel(model)
mstr = str(m)
# 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)
except:
print("can't load model {}".format(model))
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_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

0 comments on commit 10213ab

Please sign in to comment.