Support compress batch commands as one command

This commit is contained in:
WQY\qiong
2022-10-26 20:42:53 +08:00
parent 65e2ce2541
commit 89cc1acc66
5 changed files with 223 additions and 9 deletions

View File

@@ -1834,5 +1834,44 @@ class TestApi:
self.leave(p)
def test_batch_command(self):
p = 'test_batch_command'
self.enter(p)
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.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 get_current_operation(p) == 1
cs = ChangeSet()
cs.delete({'type': JUNCTION, 'id': 'j1'})
cs.delete({'type': JUNCTION, 'id': 'j2'})
cs = execute_batch_command(p, cs)
assert get_current_operation(p) == 2
cs = execute_undo(p)
assert get_current_operation(p) == 1
cs = execute_undo(p)
assert get_current_operation(p) == 0
self.leave(p)
if __name__ == '__main__':
pytest.main()