|
1 | 1 | import unittest |
2 | 2 | import subprocess |
3 | | -import os |
| 3 | +import time |
4 | 4 |
|
5 | 5 | submit_script = "/home/uverma/Documents/code/My_Ganga/my_code/submit_jobs.py" |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class TestSubmitJobs(unittest.TestCase): |
9 | 9 |
|
10 | | - def test_submit_jobs(self): |
| 10 | + def setUp(self): |
| 11 | + """Ensure a clean Ganga job list before running tests.""" |
| 12 | + subprocess.run(["ganga", "-e", "jobs.clear()"], capture_output=True, text=True) |
11 | 13 |
|
| 14 | + def test_submit_jobs(self): |
| 15 | + |
12 | 16 | """Test if submit_jobs.py successfully creates and runs Ganga jobs.""" |
13 | 17 |
|
14 | | - |
15 | 18 | # Run the job submission script |
16 | | - result = subprocess.run(["ganga", submit_script], capture_output=True, text=True) |
| 19 | + result = subprocess.run( |
| 20 | + ["ganga", submit_script], |
| 21 | + capture_output=True, text=True |
| 22 | + ) |
17 | 23 |
|
18 | | - # Print output or error of jobs |
19 | 24 | print("Ganga Output:", result.stdout) |
20 | 25 | print("Ganga Error:", result.stderr) |
21 | 26 |
|
22 | | - # Test will pass if "total occurrences of 'it'" occurs in the output |
| 27 | + # Ensure the job was submitted |
| 28 | + self.assertIn("submitted", result.stdout.lower(), "Job was not submitted.") |
| 29 | + |
| 30 | + # Wait for jobs to complete |
| 31 | + time.sleep(30) |
| 32 | + |
| 33 | + # Check job list |
| 34 | + ganga_jobs = subprocess.run( |
| 35 | + ["ganga", "-e", "jobs"], |
| 36 | + capture_output=True, text=True |
| 37 | + ) |
| 38 | + |
| 39 | + print("🔹 Jobs Output:", ganga_jobs.stdout) |
| 40 | + print("🔹 Jobs Error:", ganga_jobs.stderr) |
| 41 | + |
| 42 | + # Verify if expected output exists |
23 | 43 | self.assertIn("total occurrences of 'it'", result.stdout.lower(), "Expected output not found.") |
24 | 44 |
|
25 | 45 | if __name__ == "__main__": |
|
0 commit comments