Support batch operation table
This commit is contained in:
@@ -157,15 +157,7 @@ class TestApi:
|
||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}) # fail
|
||||
|
||||
cs = execute_batch_command(p, cs)
|
||||
assert len(cs.operations) == 0
|
||||
|
||||
assert get_current_operation(p) == 0
|
||||
|
||||
cs = ChangeSet()
|
||||
cs.add({'type': JUNCTION, 'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||
cs.add({'type': JUNCTION, 'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0})
|
||||
|
||||
cs = execute_batch_command(p, cs)
|
||||
assert len(cs.operations) == 2
|
||||
|
||||
assert get_current_operation(p) == 1
|
||||
|
||||
@@ -399,6 +391,87 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_delete_nodes_then_restore_command(self):
|
||||
p = 'test_delete_nodes_then_restore_commands'
|
||||
read_inp(p, f'./inp/net3.inp', '2')
|
||||
|
||||
open_project(p)
|
||||
|
||||
nodes = get_nodes(p)
|
||||
links = get_links(p)
|
||||
|
||||
for _ in range(10):
|
||||
random.shuffle(nodes)
|
||||
|
||||
batch = ChangeSet()
|
||||
for node in nodes:
|
||||
if is_junction(p, node):
|
||||
batch.delete({'type' : 'junction', 'id': node })
|
||||
if is_reservoir(p, node):
|
||||
batch.delete({'type' : 'reservoir', 'id': node })
|
||||
if is_tank(p, node):
|
||||
batch.delete({'type' : 'tank', 'id': node })
|
||||
execute_batch_command(p, batch)
|
||||
|
||||
for node in nodes:
|
||||
assert is_node(p, node) == False
|
||||
for link in links:
|
||||
assert is_link(p, link) == False
|
||||
|
||||
assert get_nodes(p) == []
|
||||
assert get_links(p) == []
|
||||
|
||||
op = get_restore_operation(p)
|
||||
pick_operation(p, op)
|
||||
|
||||
for node in nodes:
|
||||
assert is_node(p, node)
|
||||
for link in links:
|
||||
assert is_link(p, link)
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_delete_links_then_restore_command(self):
|
||||
p = 'test_delete_links_then_restore_commands'
|
||||
read_inp(p, f'./inp/net3.inp', '2')
|
||||
|
||||
open_project(p)
|
||||
|
||||
nodes = get_nodes(p)
|
||||
links = get_links(p)
|
||||
|
||||
for _ in range(10):
|
||||
random.shuffle(links)
|
||||
|
||||
batch = ChangeSet()
|
||||
for link in links:
|
||||
if is_pipe(p, link):
|
||||
batch.delete({'type' : 'pipe', 'id': link })
|
||||
if is_pump(p, link):
|
||||
batch.delete({'type' : 'pump', 'id': link })
|
||||
if is_valve(p, link):
|
||||
batch.delete({'type' : 'valve', 'id': link })
|
||||
execute_batch_command(p, batch)
|
||||
|
||||
for node in nodes:
|
||||
assert is_node(p, node)
|
||||
for link in links:
|
||||
assert is_link(p, link) == False
|
||||
|
||||
assert get_links(p) == []
|
||||
|
||||
op = get_restore_operation(p)
|
||||
pick_operation(p, op)
|
||||
|
||||
for node in nodes:
|
||||
assert is_node(p, node)
|
||||
for link in links:
|
||||
assert is_link(p, link)
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_delete_nodes_links_then_restore_v2(self):
|
||||
p = 'test_delete_nodes_links_then_restore_v2'
|
||||
read_inp(p, f'./inp/net3.inp', '2')
|
||||
|
||||
Reference in New Issue
Block a user