-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_basic_operations.py
60 lines (46 loc) · 1.61 KB
/
test_basic_operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from datetime import datetime, timedelta
import pytest
from alfalfa_client.alfalfa_client import AlfalfaClient, SiteID
@pytest.mark.integration
def test_simple_internal_clock(alfalfa: AlfalfaClient, ref_id: SiteID):
alfalfa.wait(ref_id, "ready")
end_datetime = datetime(2019, 1, 2, 0, 2, 0)
alfalfa.start(
ref_id,
external_clock=False,
start_datetime=datetime(2019, 1, 2, 0, 0, 0),
end_datetime=end_datetime,
timescale=10
)
# Wait for model to complete
alfalfa.wait(ref_id, "complete")
model_time = alfalfa.get_sim_time(ref_id)
assert end_datetime == model_time
@pytest.mark.integration
def test_simple_external_clock(alfalfa: AlfalfaClient, ref_id: SiteID):
alfalfa.wait(ref_id, "ready")
start_dt = datetime(2019, 1, 2, 23, 55, 0)
alfalfa.start(
ref_id,
external_clock=True,
start_datetime=start_dt,
end_datetime=datetime(2019, 1, 3, 1, 0, 0)
)
alfalfa.wait(ref_id, "running")
# -- Assert model gets to expected start time
model_time = alfalfa.get_sim_time(ref_id)
assert start_dt == model_time
updated_dt = start_dt
for _ in range(2):
# -- Advance a single time step
alfalfa.advance(ref_id)
model_time = alfalfa.get_sim_time(ref_id)
updated_dt += timedelta(minutes=1)
assert updated_dt == model_time
# Shut down
alfalfa.stop(ref_id)
alfalfa.wait(ref_id, "complete")
@pytest.mark.integration
def test_alias(alfalfa: AlfalfaClient, ref_id: SiteID):
alfalfa.set_alias("test", ref_id)
assert alfalfa.get_alias("test") == ref_id