|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
17 | | -from pathlib import Path |
| 17 | +from dataclasses import dataclass, field |
18 | 18 | from typing import Union |
19 | 19 |
|
20 | | -from .system import System |
21 | 20 | from .test_scenario import TestRun |
22 | 21 |
|
23 | 22 |
|
| 23 | +@dataclass |
24 | 24 | class BaseJob: |
25 | | - """ |
26 | | - Base class for representing a job created by executing a test. |
| 25 | + """Base class for representing a job created by executing a test.""" |
27 | 26 |
|
28 | | - Attributes |
29 | | - id (Union[str, int]): The unique identifier of the job. |
30 | | - mode (str): The mode of the job (e.g., 'run', 'dry-run'). |
31 | | - system (System): The system in which the job is running. |
32 | | - test_run (TestRun): The TestRun instance associated with this job. |
33 | | - output_path (Path): The path where the job's output is stored. |
34 | | - terminated_by_dependency (bool): Flag to indicate if the job was terminated due to a dependency. |
35 | | - """ |
36 | | - |
37 | | - def __init__(self, mode: str, system: System, test_run: TestRun): |
38 | | - """ |
39 | | - Initialize a BaseJob instance. |
40 | | -
|
41 | | - Args: |
42 | | - mode (str): The mode of the job (e.g., 'run', 'dry-run'). |
43 | | - system (System): The system in which the job is running. |
44 | | - test_run (TestRun): The TestRun instance associated with this job. |
45 | | - """ |
46 | | - self.id: Union[str, int] = 0 |
47 | | - self.mode: str = mode |
48 | | - self.system: System = system |
49 | | - self.test_run: TestRun = test_run |
50 | | - self.output_path: Path = test_run.output_path |
51 | | - self.terminated_by_dependency: bool = False |
52 | | - |
53 | | - def is_running(self) -> bool: |
54 | | - """ |
55 | | - Check if the specified job is currently running. |
56 | | -
|
57 | | - Returns |
58 | | - bool: True if the job is running, False otherwise. |
59 | | - """ |
60 | | - if self.mode == "dry-run": |
61 | | - return True |
62 | | - return self.system.is_job_running(self) |
63 | | - |
64 | | - def is_completed(self) -> bool: |
65 | | - """ |
66 | | - Check if a job is completed. |
67 | | -
|
68 | | - Returns |
69 | | - bool: True if the job is completed, False otherwise. |
70 | | - """ |
71 | | - if self.mode == "dry-run": |
72 | | - return True |
73 | | - return self.system.is_job_completed(self) |
74 | | - |
75 | | - def increment_iteration(self): |
76 | | - """Increment the iteration count of the associated test.""" |
77 | | - self.test_run.current_iteration += 1 |
78 | | - |
79 | | - def __repr__(self) -> str: |
80 | | - """ |
81 | | - Return a string representation of the BaseJob instance. |
82 | | -
|
83 | | - Returns |
84 | | - str: String representation of the job. |
85 | | - """ |
86 | | - return f"BaseJob(id={self.id}, mode={self.mode}, system={self.system.name}, test={self.test_run.test.name})" |
| 27 | + test_run: TestRun |
| 28 | + id: Union[str, int] |
| 29 | + terminated_by_dependency: bool = field(default=False, init=False) |
0 commit comments