Add tag api and test
This commit is contained in:
@@ -1174,6 +1174,89 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_tag(self):
|
||||
p = 'test_tag'
|
||||
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')
|
||||
|
||||
t = get_tag(p, TAG_TYPE_NODE, 'j1')
|
||||
assert t['tag'] == None
|
||||
set_tag(p, ChangeSet({'t_type': TAG_TYPE_NODE, 'id': 'j1', 'tag': 'j1t' }))
|
||||
t = get_tag(p, TAG_TYPE_NODE, 'j1')
|
||||
assert t['tag'] == 'j1t'
|
||||
|
||||
t = get_tag(p, TAG_TYPE_NODE, 'j2')
|
||||
assert t['tag'] == None
|
||||
set_tag(p, ChangeSet({'t_type': TAG_TYPE_NODE, 'id': 'j2', 'tag': 'j2t' }))
|
||||
t = get_tag(p, TAG_TYPE_NODE, 'j2')
|
||||
assert t['tag'] == 'j2t'
|
||||
|
||||
t = get_tag(p, TAG_TYPE_LINK, 'p0')
|
||||
assert t['tag'] == None
|
||||
set_tag(p, ChangeSet({'t_type': TAG_TYPE_LINK, 'id': 'p0', 'tag': 'p0t' }))
|
||||
t = get_tag(p, TAG_TYPE_LINK, 'p0')
|
||||
assert t['tag'] == 'p0t'
|
||||
|
||||
self.leave(p)
|
||||
|
||||
def test_tag_op(self):
|
||||
p = 'test_tag_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')
|
||||
|
||||
cs = set_tag(p, ChangeSet({'t_type': TAG_TYPE_NODE, 'id': 'j1', 'tag': 'j1t' })).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_NODE
|
||||
assert cs['id'] == 'j1'
|
||||
assert cs['tag'] == 'j1t'
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_NODE
|
||||
assert cs['id'] == 'j1'
|
||||
assert cs['tag'] == None
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_NODE
|
||||
assert cs['id'] == 'j1'
|
||||
assert cs['tag'] == 'j1t'
|
||||
|
||||
cs = set_tag(p, ChangeSet({'t_type': TAG_TYPE_LINK, 'id': 'p0', 'tag': 'p0t' })).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_LINK
|
||||
assert cs['id'] == 'p0'
|
||||
assert cs['tag'] == 'p0t'
|
||||
|
||||
cs = execute_undo(p).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_LINK
|
||||
assert cs['id'] == 'p0'
|
||||
assert cs['tag'] == None
|
||||
|
||||
cs = execute_redo(p).operations[0]
|
||||
assert cs['type'] == 'tag'
|
||||
assert cs['t_type'] == TAG_TYPE_LINK
|
||||
assert cs['id'] == 'p0'
|
||||
assert cs['tag'] == 'p0t'
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_demand(self):
|
||||
p = 'test_demand'
|
||||
self.enter(p)
|
||||
|
||||
Reference in New Issue
Block a user