Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwkruisselbrink committed Dec 11, 2024
1 parent cd531f8 commit dd5fdb2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/annotate_sbml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import argparse
import traceback
Expand All @@ -24,12 +25,18 @@ def main():
raise FileNotFoundError(f'Annotations file [{f_ann}] does not exist.')
try:
if not f_out.exists() or args.force:
sbml_file = f_in
annotations_file = f_ann
out_file = f_out

# Check if output folder exists, otherwise create it
out_dir = os.path.dirname(f_out)
if not os.path.exists(out_dir):
os.makedirs(out_dir)

# Annotate SBML file
annotator = PbkModelAnnotator()
document = annotator.annotate(sbml_file, annotations_file, logger)
ls.writeSBML(document, str(out_file))
document = annotator.annotate(f_in, f_ann, logger)

# Write SBML
ls.writeSBML(document, str(f_out))
else:
print(f'[{f_out}] already exists, use -f to force conversion')
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions src/ant2sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def main():
parser = argparse.ArgumentParser(description="Convert Antimony file to SBML")
parser.add_argument("ant_file", help="Full path to Antimony file")
parser.add_argument("out_file", help="Output file")
parser.add_argument("-o", "--output", type=str, help="Output file (optional)")
parser.add_argument("-f", "--force", action="store_true", help="Overwrite existing")
args = parser.parse_args()
f_in = Path(args.ant_file)
Expand All @@ -22,7 +22,7 @@ def main():
sys.exit(1)

# Get output file from command line args, otherwise derive from antimony file
f_out = Path(args.out_file) if args.out_file is not None else Path(args.ant_file).with_suffix('.sbml')
f_out = Path(args.output) if args.output is not None else Path(args.ant_file).with_suffix('.sbml')

# Check if output folder exists, otherwise create it
out_dir = os.path.dirname(f_out)
Expand Down
12 changes: 11 additions & 1 deletion src/validate_sbml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import logging
import os
import sys
from pathlib import Path
from sbmlpbkutils import PbkModelValidator
Expand All @@ -26,7 +27,16 @@ def main():
f_in = Path(args.f_in)
if not f_in.is_file():
raise FileNotFoundError(f'File {f_in} does not exist.')
logger = get_logger(__name__) if args.log_file is None else create_file_logger(Path(args.log_file))
if args.log_file is not None:
# Check if output folder exists, otherwise create it
out_dir = os.path.dirname(args.log_file)
if not os.path.exists(out_dir):
os.makedirs(out_dir)

# Create file logger
logger = create_file_logger(Path(args.log_file))
else:
logger = get_logger(__name__)

validator = PbkModelValidator()
validator.validate(f_in, logger)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_annotate_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestAnnotateSbml(TestBase):

@patch('sys.argv', ['ant2sbml.py', './tests/models/simple.sbml', './tests/models/simple.annotations.csv', './tests/output/simple.annotated.sbml'])
@patch('sys.argv', ['ant2sbml.py', './tests/models/simple.sbml', './tests/models/simple.annotations.csv', './tests/output/simple.annotated.sbml', '-f'])
def test_simple(self):
src.annotate_sbml.main()
path = pl.Path('./tests/output/simple.annotated.sbml')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ant2sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestAnt2Sbml(TestBase):

@patch('sys.argv', ['ant2sbml.py', './tests/models/simple.ant', './tests/output/simple.sbml'])
@patch('sys.argv', ['ant2sbml.py', './tests/models/simple.ant', '-o', './tests/output/simple.sbml', '-f'])
def test_simple(self):
src.ant2sbml.main()
path = pl.Path('./tests/output/simple.sbml')
Expand Down

0 comments on commit dd5fdb2

Please sign in to comment.