From c9a15e348f3c9a98448408793185d5e72f283852 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 13:38:51 +0000 Subject: [PATCH 1/4] Add unit tests for run function in runner.py Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_runner.py | 93 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 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..8a09beb3 --- /dev/null +++ b/tests/test_runner.py @@ -0,0 +1,93 @@ +import os +import unittest +from unittest.mock import patch, MagicMock + +# Assuming the runner can be imported like this +from bionetgen.modelapi.runner import run + + +class TestRunner(unittest.TestCase): + @patch("bionetgen.modelapi.runner.BNGCLI") + @patch("bionetgen.modelapi.runner.TemporaryDirectory") + @patch("bionetgen.modelapi.runner.os.chdir") + def test_run_with_no_out(self, mock_chdir, mock_temp_dir, mock_bngcli): + # Setup mocks + mock_temp_dir.return_value.__enter__.return_value = "/tmp/mocked" + mock_cli_instance = MagicMock() + mock_cli_instance.result = "mocked_result" + mock_bngcli.return_value = mock_cli_instance + + # Execute + result = run("mock_input.bngl") + + # Verify + mock_temp_dir.assert_called_once() + mock_bngcli.assert_called_once_with( + "mock_input.bngl", "/tmp/mocked", unittest.mock.ANY, suppress=False, timeout=None + ) + mock_cli_instance.run.assert_called_once() + self.assertEqual(mock_chdir.call_count, 1) # should return to original directory + self.assertEqual(result, "mocked_result") + + @patch("bionetgen.modelapi.runner.BNGCLI") + @patch("bionetgen.modelapi.runner.os.chdir") + def test_run_with_out(self, mock_chdir, mock_bngcli): + # Setup mocks + mock_cli_instance = MagicMock() + mock_cli_instance.result = "mocked_result" + mock_bngcli.return_value = mock_cli_instance + + # Execute + result = run("mock_input.bngl", out="/custom/out") + + # Verify + mock_bngcli.assert_called_once_with( + "mock_input.bngl", "/custom/out", unittest.mock.ANY, suppress=False, timeout=None + ) + mock_cli_instance.run.assert_called_once() + self.assertEqual(mock_chdir.call_count, 1) + self.assertEqual(result, "mocked_result") + + @patch("bionetgen.modelapi.runner.BNGCLI") + @patch("bionetgen.modelapi.runner.TemporaryDirectory") + @patch("bionetgen.modelapi.runner.os.chdir") + def test_run_with_no_out_exception(self, mock_chdir, mock_temp_dir, mock_bngcli): + # Setup mocks + mock_temp_dir.return_value.__enter__.return_value = "/tmp/mocked" + mock_cli_instance = MagicMock() + mock_cli_instance.run.side_effect = Exception("Test exception") + mock_bngcli.return_value = mock_cli_instance + + # Execute and Verify + with self.assertRaises(Exception) as context: + run("mock_input.bngl") + + self.assertTrue("Test exception" in str(context.exception)) + mock_temp_dir.assert_called_once() + mock_bngcli.assert_called_once_with( + "mock_input.bngl", "/tmp/mocked", unittest.mock.ANY, suppress=False, timeout=None + ) + mock_cli_instance.run.assert_called_once() + self.assertEqual(mock_chdir.call_count, 1) # Exception handling restores directory + + @patch("bionetgen.modelapi.runner.BNGCLI") + @patch("bionetgen.modelapi.runner.os.chdir") + def test_run_with_out_exception(self, mock_chdir, mock_bngcli): + # Setup mocks + mock_cli_instance = MagicMock() + mock_cli_instance.run.side_effect = Exception("Test exception") + mock_bngcli.return_value = mock_cli_instance + + # Execute and Verify + with self.assertRaises(Exception) as context: + run("mock_input.bngl", out="/custom/out") + + self.assertTrue("Test exception" in str(context.exception)) + mock_bngcli.assert_called_once_with( + "mock_input.bngl", "/custom/out", unittest.mock.ANY, suppress=False, timeout=None + ) + mock_cli_instance.run.assert_called_once() + self.assertEqual(mock_chdir.call_count, 1) # Exception handling restores directory + +if __name__ == "__main__": + unittest.main() From ae8c0a0e62f526aaf57dff83866eb19178e950b4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 14:07:51 +0000 Subject: [PATCH 2/4] Fix black formatting in tests/test_runner.py Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> --- tests/test_runner.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/test_runner.py b/tests/test_runner.py index 8a09beb3..fa052b84 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -23,10 +23,16 @@ def test_run_with_no_out(self, mock_chdir, mock_temp_dir, mock_bngcli): # Verify mock_temp_dir.assert_called_once() mock_bngcli.assert_called_once_with( - "mock_input.bngl", "/tmp/mocked", unittest.mock.ANY, suppress=False, timeout=None + "mock_input.bngl", + "/tmp/mocked", + unittest.mock.ANY, + suppress=False, + timeout=None, ) mock_cli_instance.run.assert_called_once() - self.assertEqual(mock_chdir.call_count, 1) # should return to original directory + self.assertEqual( + mock_chdir.call_count, 1 + ) # should return to original directory self.assertEqual(result, "mocked_result") @patch("bionetgen.modelapi.runner.BNGCLI") @@ -42,7 +48,11 @@ def test_run_with_out(self, mock_chdir, mock_bngcli): # Verify mock_bngcli.assert_called_once_with( - "mock_input.bngl", "/custom/out", unittest.mock.ANY, suppress=False, timeout=None + "mock_input.bngl", + "/custom/out", + unittest.mock.ANY, + suppress=False, + timeout=None, ) mock_cli_instance.run.assert_called_once() self.assertEqual(mock_chdir.call_count, 1) @@ -65,10 +75,16 @@ def test_run_with_no_out_exception(self, mock_chdir, mock_temp_dir, mock_bngcli) self.assertTrue("Test exception" in str(context.exception)) mock_temp_dir.assert_called_once() mock_bngcli.assert_called_once_with( - "mock_input.bngl", "/tmp/mocked", unittest.mock.ANY, suppress=False, timeout=None + "mock_input.bngl", + "/tmp/mocked", + unittest.mock.ANY, + suppress=False, + timeout=None, ) mock_cli_instance.run.assert_called_once() - self.assertEqual(mock_chdir.call_count, 1) # Exception handling restores directory + self.assertEqual( + mock_chdir.call_count, 1 + ) # Exception handling restores directory @patch("bionetgen.modelapi.runner.BNGCLI") @patch("bionetgen.modelapi.runner.os.chdir") @@ -84,10 +100,17 @@ def test_run_with_out_exception(self, mock_chdir, mock_bngcli): self.assertTrue("Test exception" in str(context.exception)) mock_bngcli.assert_called_once_with( - "mock_input.bngl", "/custom/out", unittest.mock.ANY, suppress=False, timeout=None + "mock_input.bngl", + "/custom/out", + unittest.mock.ANY, + suppress=False, + timeout=None, ) mock_cli_instance.run.assert_called_once() - self.assertEqual(mock_chdir.call_count, 1) # Exception handling restores directory + self.assertEqual( + mock_chdir.call_count, 1 + ) # Exception handling restores directory + if __name__ == "__main__": unittest.main() From cb5ba546668b0a038abddbc1962b4542292c81b1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 14:13:40 +0000 Subject: [PATCH 3/4] Commit formatting change for black Co-authored-by: akutuva21 <44119804+akutuva21@users.noreply.github.com> From 9b1d427a15fd3e6281c821e690c4c97c82f5102f Mon Sep 17 00:00:00 2001 From: akutuva21 Date: Mon, 13 Apr 2026 10:15:09 -0400 Subject: [PATCH 4/4] chore: PR #75 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__/