Add status api and test

This commit is contained in:
WQY\qiong
2022-10-22 11:51:48 +08:00
parent 6fa2f77a60
commit c1b99bc7eb
7 changed files with 171 additions and 5 deletions

View File

@@ -1198,7 +1198,7 @@ class TestApi:
def test_demand_op(self):
p = 'test_demand'
p = 'test_demand_op'
self.enter(p)
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
@@ -1240,6 +1240,78 @@ class TestApi:
self.leave(p)
def test_status(self):
p = 'test_status'
self.enter(p)
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
assert is_junction(p, 'j1')
assert is_junction(p, 'j2')
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
assert is_pipe(p, 'p0')
s = get_status(p, 'p0')
assert s['link'] == 'p0'
assert s['status'] == None
assert s['setting'] == None
set_status(p, ChangeSet({'link': 'p0', 'status': LINK_STATUS_OPEN, 'setting': 10.0}))
s = get_status(p, 'p0')
assert s['link'] == 'p0'
assert s['status'] == LINK_STATUS_OPEN
assert s['setting'] == 10.0
self.leave(p)
def test_status_op(self):
p = 'test_status_op'
self.enter(p)
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
assert is_junction(p, 'j1')
assert is_junction(p, 'j2')
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
assert is_pipe(p, 'p0')
s = get_status(p, 'p0')
assert s['link'] == 'p0'
assert s['status'] == None
assert s['setting'] == None
cs = set_status(p, ChangeSet({'link': 'p0', 'status': LINK_STATUS_OPEN, 'setting': 10.0})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'status'
assert cs['link'] == 'p0'
assert cs['status'] == LINK_STATUS_OPEN
assert cs['setting'] == 10.0
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'status'
assert cs['link'] == 'p0'
assert cs['status'] == None
assert cs['setting'] == None
s = get_status(p, 'p0')
assert s['link'] == 'p0'
assert s['status'] == None
assert s['setting'] == None
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'status'
assert cs['link'] == 'p0'
assert cs['status'] == LINK_STATUS_OPEN
assert cs['setting'] == 10.0
self.leave(p)
def test_snapshot(self):
p = "test_snapshot"
self.enter(p)
@@ -1286,7 +1358,7 @@ class TestApi:
def test_batch_commands(self):
p = 'test_valve_op'
p = 'test_batch_commands'
self.enter(p)
cs = ChangeSet()