From 50726d6f4332d5077006500ee5b51ff4eac9d4d7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 17:47:38 +0000 Subject: [PATCH 1/3] Add tests for runner.run() function using mocks Adds a comprehensive test suite to cover the core scenarios of the `runner.run()` function in `bionetgen/modelapi/runner.py`. The tests verify proper argument delegation to `BNGCLI` and correctly test output folder creation using temp directories and exception handling while isolating external effects using `unittest.mock`. Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_runner.py | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/test_runner.py diff --git a/tests/test_runner.py b/tests/test_runner.py new file mode 100644 index 00000000..83881198 --- /dev/null +++ b/tests/test_runner.py @@ -0,0 +1,65 @@ +import os +import pytest +from unittest.mock import patch, MagicMock + +import bionetgen.modelapi.runner as runner + +def test_runner_run_with_out(): + with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: + with patch("os.chdir") as mock_chdir: + mock_cli_inst = MagicMock() + mock_cli_class.return_value = mock_cli_inst + mock_cli_inst.result = "mock_result" + + cur_dir = os.getcwd() + res = runner.run("test.bngl", out="out_dir") + + mock_cli_class.assert_called_once_with("test.bngl", "out_dir", runner.conf["bngpath"], suppress=False, timeout=None) + mock_cli_inst.run.assert_called_once() + mock_chdir.assert_called_once_with(cur_dir) + assert res == "mock_result" + +def test_runner_run_without_out(): + with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: + with patch("bionetgen.modelapi.runner.TemporaryDirectory") as mock_tempdir: + with patch("os.chdir") as mock_chdir: + mock_tempdir.return_value.__enter__.return_value = "temp_dir" + mock_cli_inst = MagicMock() + mock_cli_class.return_value = mock_cli_inst + mock_cli_inst.result = "mock_result" + + cur_dir = os.getcwd() + res = runner.run("test.bngl") + + mock_cli_class.assert_called_once_with("test.bngl", "temp_dir", runner.conf["bngpath"], suppress=False, timeout=None) + mock_cli_inst.run.assert_called_once() + mock_chdir.assert_called_once_with(cur_dir) + assert res == "mock_result" + +def test_runner_run_exception_with_out(): + with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: + with patch("os.chdir") as mock_chdir: + mock_cli_inst = MagicMock() + mock_cli_class.return_value = mock_cli_inst + mock_cli_inst.run.side_effect = RuntimeError("Run failed") + + cur_dir = os.getcwd() + with pytest.raises(RuntimeError): + runner.run("test.bngl", out="out_dir") + + mock_chdir.assert_called_once_with(cur_dir) + +def test_runner_run_exception_without_out(): + with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: + with patch("bionetgen.modelapi.runner.TemporaryDirectory") as mock_tempdir: + with patch("os.chdir") as mock_chdir: + mock_tempdir.return_value.__enter__.return_value = "temp_dir" + mock_cli_inst = MagicMock() + mock_cli_class.return_value = mock_cli_inst + mock_cli_inst.run.side_effect = RuntimeError("Run failed") + + cur_dir = os.getcwd() + with pytest.raises(RuntimeError): + runner.run("test.bngl") + + mock_chdir.assert_called_once_with(cur_dir) From ccb1b1ac4e91afe5968a46e2c49916f23a91d64b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 20:02:23 +0000 Subject: [PATCH 2/3] Add tests for runner.run() function using mocks Adds a comprehensive test suite to cover the core scenarios of the `runner.run()` function in `bionetgen/modelapi/runner.py`. The tests verify proper argument delegation to `BNGCLI` and correctly test output folder creation using temp directories and exception handling while isolating external effects using `unittest.mock`. Fixes Black formatting issues as per CI requirements. Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_runner.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/test_runner.py b/tests/test_runner.py index 83881198..3f0ed105 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -4,6 +4,7 @@ import bionetgen.modelapi.runner as runner + def test_runner_run_with_out(): with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: with patch("os.chdir") as mock_chdir: @@ -14,11 +15,18 @@ def test_runner_run_with_out(): cur_dir = os.getcwd() res = runner.run("test.bngl", out="out_dir") - mock_cli_class.assert_called_once_with("test.bngl", "out_dir", runner.conf["bngpath"], suppress=False, timeout=None) + mock_cli_class.assert_called_once_with( + "test.bngl", + "out_dir", + runner.conf["bngpath"], + suppress=False, + timeout=None, + ) mock_cli_inst.run.assert_called_once() mock_chdir.assert_called_once_with(cur_dir) assert res == "mock_result" + def test_runner_run_without_out(): with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: with patch("bionetgen.modelapi.runner.TemporaryDirectory") as mock_tempdir: @@ -31,11 +39,18 @@ def test_runner_run_without_out(): cur_dir = os.getcwd() res = runner.run("test.bngl") - mock_cli_class.assert_called_once_with("test.bngl", "temp_dir", runner.conf["bngpath"], suppress=False, timeout=None) + mock_cli_class.assert_called_once_with( + "test.bngl", + "temp_dir", + runner.conf["bngpath"], + suppress=False, + timeout=None, + ) mock_cli_inst.run.assert_called_once() mock_chdir.assert_called_once_with(cur_dir) assert res == "mock_result" + def test_runner_run_exception_with_out(): with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: with patch("os.chdir") as mock_chdir: @@ -49,6 +64,7 @@ def test_runner_run_exception_with_out(): mock_chdir.assert_called_once_with(cur_dir) + def test_runner_run_exception_without_out(): with patch("bionetgen.modelapi.runner.BNGCLI") as mock_cli_class: with patch("bionetgen.modelapi.runner.TemporaryDirectory") as mock_tempdir: From dd50482249988e744275fd81b13c3f6b0b805b10 Mon Sep 17 00:00:00 2001 From: akutuva21 Date: Mon, 13 Apr 2026 10:17:50 -0400 Subject: [PATCH 3/3] chore: PR #43 remove forbidden artifacts and run black --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 39aa9026..f9bf9c80 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ temp_testing/* build dist Issues/rule_keywords/test_DeleteMolecules_changed.bngl +.jules/ +__pycache__/