Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ temp_testing/*
build
dist
Issues/rule_keywords/test_DeleteMolecules_changed.bngl
.jules/
__pycache__/
6 changes: 3 additions & 3 deletions bionetgen/core/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, subprocess
from bionetgen.core.exc import BNGPerlError
from distutils import spawn
import shutil as spawn

from bionetgen.core.utils.logging import BNGLogger

Expand Down Expand Up @@ -589,7 +589,7 @@ def _try_path(candidate_path):
return hit

# 3) On PATH
bng_on_path = spawn.find_executable("BNG2.pl")
bng_on_path = spawn.which("BNG2.pl")
if bng_on_path:
tried.append(bng_on_path)
hit = _try_path(bng_on_path)
Expand All @@ -616,7 +616,7 @@ def test_perl(app=None, perl_path=None):
logger.debug("Checking if perl is installed.", loc=f"{__file__} : test_perl()")
# find path to perl binary
if perl_path is None:
perl_path = spawn.find_executable("perl")
perl_path = spawn.which("perl")
if perl_path is None:
raise BNGPerlError
# check if perl is actually working
Expand Down
5 changes: 4 additions & 1 deletion bionetgen/simulator/csimulator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import ctypes, os, tempfile, bionetgen
import numpy as np

from distutils import ccompiler
try:
from distutils import ccompiler
except ImportError:
pass
from .bngsimulator import BNGSimulator
from bionetgen.main import BioNetGen
from bionetgen.core.exc import BNGCompileError
Expand Down
59 changes: 59 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import pytest
from unittest.mock import patch, MagicMock, ANY
from bionetgen.modelapi.runner import run


@patch("bionetgen.modelapi.runner.BNGCLI")
def test_runner_with_out(mock_bngcli):
mock_cli_instance = MagicMock()
mock_bngcli.return_value = mock_cli_instance
mock_cli_instance.result = "mock_result"

inp = "test.bngl"
out = "test_out"

result = run(inp, out=out, suppress=True, timeout=10)

mock_bngcli.assert_called_once_with(inp, out, ANY, suppress=True, timeout=10)
mock_cli_instance.run.assert_called_once()
assert result == "mock_result"


@patch("bionetgen.modelapi.runner.BNGCLI")
@patch("bionetgen.modelapi.runner.TemporaryDirectory")
def test_runner_without_out(mock_tempdir, mock_bngcli):
mock_cli_instance = MagicMock()
mock_bngcli.return_value = mock_cli_instance
mock_cli_instance.result = "mock_result"

mock_tempdir_instance = MagicMock()
mock_tempdir.return_value.__enter__.return_value = "temp_out"

inp = "test.bngl"

result = run(inp, suppress=False, timeout=None)

mock_tempdir.assert_called_once()
mock_bngcli.assert_called_once_with(
inp, "temp_out", ANY, suppress=False, timeout=None
)
mock_cli_instance.run.assert_called_once()
assert result == "mock_result"


@patch("bionetgen.modelapi.runner.BNGCLI")
def test_runner_exception(mock_bngcli):
mock_cli_instance = MagicMock()
mock_bngcli.return_value = mock_cli_instance
mock_cli_instance.run.side_effect = Exception("Test Exception")

inp = "test.bngl"
out = "test_out"

cur_dir = os.getcwd()

with pytest.raises(Exception, match="Test Exception"):
run(inp, out=out)

assert os.getcwd() == cur_dir
Loading