|
1 | | -from datetime import datetime, timedelta, timezone |
2 | | -from pathlib import Path |
| 1 | +from modacor.dataclasses.process_step import ProcessStep |
| 2 | +from modacor.io import IoSources |
3 | 3 |
|
4 | | -import pytest |
5 | | - |
6 | | -from ..dataclasses.process_step import ProcessStep |
7 | | - |
8 | | - |
9 | | -# Dummy BaseData for testing execute() since ProcessStep.execute() requires it. |
10 | | -class DummyBaseData: |
11 | | - pass |
| 4 | +TEST_IO_SOURCES = IoSources() |
12 | 5 |
|
13 | 6 |
|
14 | 7 | def test_minimal_instantiation(): |
15 | 8 | """ |
16 | 9 | Test that a ProcessStep can be instantiated with only the minimal arguments. |
17 | 10 | """ |
18 | | - ps = ProcessStep( |
19 | | - calling_name="Test Process", |
20 | | - calling_id="proc_001", |
21 | | - calling_module_path=Path("src/modacor/modules/some_module.py"), |
22 | | - calling_version="1.0", |
23 | | - ) |
24 | | - assert ps is not None |
25 | | - |
26 | | - |
27 | | -def test_full_instantiation(): |
28 | | - """ |
29 | | - Test that a ProcessStep can be instantiated with all arguments. |
30 | | - """ |
31 | | - ps = ProcessStep( |
32 | | - calling_name="Test Process", |
33 | | - calling_id="proc_002", |
34 | | - calling_module_path=Path("src/modacor/modules/some_module.py"), |
35 | | - calling_version="1.0", |
36 | | - required_data_keys=["fish", "cake"], |
37 | | - calling_arguments={"fish": "salmon", "cake": "chocolate"}, |
38 | | - step_keywords=["test", "full"], |
39 | | - step_doc="Test full instantiation", |
40 | | - step_reference="doi: 10.1234/5678", |
41 | | - step_note="I am a note.", |
42 | | - # produced_values={}, # this is internally generated |
43 | | - use_frames_cache=["fish"], |
44 | | - use_overall_cache=["cake"], |
45 | | - saved={"cake": "/path/to/cake"}, |
46 | | - ) |
47 | | - ps.start() |
48 | | - ps.stop() |
49 | | - assert ps is not None |
50 | | - |
51 | | - |
52 | | -def test_missing_required_input(): |
53 | | - """ |
54 | | - Test that a ProcessStep can be instantiated with all arguments. |
55 | | - """ |
56 | | - with pytest.raises( |
57 | | - ValueError, match=r"Missing required data keys in calling_arguments: ['bread']" |
58 | | - ): |
59 | | - ProcessStep( |
60 | | - calling_name="Test Process", |
61 | | - calling_id="proc_002", |
62 | | - calling_module_path=Path("src/modacor/modules/some_module.py"), |
63 | | - calling_version="1.0", |
64 | | - required_data_keys=["fish", "cake", "bread"], |
65 | | - calling_arguments={"fish": "salmon", "cake": "chocolate"}, |
66 | | - step_keywords=["test", "full"], |
67 | | - step_doc="Test full instantiation", |
68 | | - step_reference="doi: 10.1234/5678", |
69 | | - step_note="I am a note.", |
70 | | - # produced_values={}, # this is internally generated |
71 | | - use_frames_cache=["fish"], |
72 | | - use_overall_cache=["cake"], |
73 | | - saved={"cake": "/path/to/cake"}, |
74 | | - ) |
75 | | - |
76 | | - |
77 | | -def test_duration_calculation(): |
78 | | - """ |
79 | | - Test that the duration property correctly computes elapsed time. |
80 | | - """ |
81 | | - ps = ProcessStep( |
82 | | - calling_name="Test Process", |
83 | | - calling_id="proc_003", |
84 | | - calling_module_path=Path("src/modacor/modules/some_module.py"), |
85 | | - calling_version="1.0", |
86 | | - required_data_keys=[], |
87 | | - calling_arguments={}, |
88 | | - step_keywords=["test", "duration"], |
89 | | - step_doc="Test duration calculation", |
90 | | - step_reference="", |
91 | | - step_note=None, |
92 | | - produced_values={}, |
93 | | - use_frames_cache=[], |
94 | | - ) |
95 | | - # Manually set start_time 5 seconds before now. |
96 | | - ps.start_time = datetime.now(timezone.utc) - timedelta(seconds=5) |
97 | | - ps.stop() # Sets stop_time to now. |
98 | | - duration = ps.duration |
99 | | - assert duration is not None and duration >= 5 |
| 11 | + ps = ProcessStep(TEST_IO_SOURCES) |
| 12 | + assert isinstance(ps, ProcessStep) |
0 commit comments