|
1 | 1 | import os |
2 | 2 | import shutil |
| 3 | +import subprocess |
| 4 | +import sys |
3 | 5 | import tempfile |
4 | 6 | import unittest |
5 | 7 | from unittest.mock import MagicMock, patch |
@@ -87,6 +89,51 @@ def test_main_exception_triggers_exit( |
87 | 89 | "Fatal error during entropy calculation: Test exception", exc_info=True |
88 | 90 | ) |
89 | 91 |
|
| 92 | + def test_main_entry_point_runs(self): |
| 93 | + """ |
| 94 | + Test that the CLI entry point (main.py) runs successfully with minimal required |
| 95 | + arguments. |
| 96 | + """ |
| 97 | + # Prepare input files |
| 98 | + data_dir = os.path.abspath( |
| 99 | + os.path.join(os.path.dirname(__file__), "..", "data") |
| 100 | + ) |
| 101 | + tpr_path = shutil.copy(os.path.join(data_dir, "md_A4_dna.tpr"), self.test_dir) |
| 102 | + trr_path = shutil.copy( |
| 103 | + os.path.join(data_dir, "md_A4_dna_xf.trr"), self.test_dir |
| 104 | + ) |
| 105 | + |
| 106 | + config_path = os.path.join(self.test_dir, "config.yaml") |
| 107 | + with open(config_path, "w") as f: |
| 108 | + f.write("run1:\n" " selection_string: resid 1\n") |
| 109 | + |
| 110 | + result = subprocess.run( |
| 111 | + [ |
| 112 | + sys.executable, |
| 113 | + "-m", |
| 114 | + "CodeEntropy.main", |
| 115 | + "--top_traj_file", |
| 116 | + tpr_path, |
| 117 | + trr_path, |
| 118 | + ], |
| 119 | + cwd=self.test_dir, |
| 120 | + capture_output=True, |
| 121 | + text=True, |
| 122 | + ) |
| 123 | + |
| 124 | + self.assertEqual(result.returncode, 0) |
| 125 | + |
| 126 | + # Check for job folder and output file |
| 127 | + job_dir = os.path.join(self.test_dir, "job001") |
| 128 | + output_file = os.path.join(job_dir, "output_file.json") |
| 129 | + |
| 130 | + self.assertTrue(os.path.exists(job_dir)) |
| 131 | + self.assertTrue(os.path.exists(output_file)) |
| 132 | + |
| 133 | + with open(output_file) as f: |
| 134 | + content = f.read() |
| 135 | + self.assertIn("DA", content) |
| 136 | + |
90 | 137 |
|
91 | 138 | if __name__ == "__main__": |
92 | 139 | unittest.main() |
0 commit comments