From 45bb0483cea9e59d026bf36fae0663d2ca128d5e Mon Sep 17 00:00:00 2001 From: wqy Date: Sat, 3 Sep 2022 11:12:54 +0800 Subject: [PATCH] Refine demo --- api/operation.py | 2 +- new_demo.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/api/operation.py b/api/operation.py index 50fca6a..ac457f3 100644 --- a/api/operation.py +++ b/api/operation.py @@ -118,7 +118,7 @@ def execute_redo(name: str) -> None: _execute(name, redo) _update_current_operation(name, curr, child) -# snapshot support to check out between different version of database +# snapshot support to checkout between different version of database # snapshot is persistent # since redo always remember the recently undo path diff --git a/new_demo.py b/new_demo.py index d14cc57..02f25d8 100644 --- a/new_demo.py +++ b/new_demo.py @@ -4,6 +4,8 @@ from tjnetwork_new import * def demo_snapshot(): p = "demo_snapshot" + print(p) + if is_project_open(p): close_project(p) @@ -30,8 +32,14 @@ def demo_snapshot(): add_junction(p, 'j-8', 10.0, 20.0, 30.0) take_snapshot(p, "5-6-7-8") + print("before checkout, it should be 5, 6, 7, 8") + print(get_nodes(p)) + pick_snapshot(p, "1-2-3-4") + print("after checkout, it should be 1, 2, 3, 4") + print(get_nodes(p)) + close_project(p) # delete_project(p) @@ -39,6 +47,8 @@ def demo_snapshot(): def demo_transaction(): p = "demo_transaction" + print(p) + if is_project_open(p): close_project(p) @@ -60,12 +70,18 @@ def demo_transaction(): add_junction(p, 'j-4', 10.0, 20.0, 30.0) take_snapshot(p, "4") + print("before rollback, it should be 1, 2, 3, 4") + print(get_nodes(p)) + + print("after rollback, it should be 1, 2") abort_transaction(p) - print(have_snapshot(p, "1")) - print(have_snapshot(p, "2")) - print(have_snapshot(p, "3")) - print(have_snapshot(p, "4")) + print(get_nodes(p)) + + print(f"have snapshot 1: {have_snapshot(p, '1')}") + print(f"have snapshot 2: {have_snapshot(p, '2')}") + print(f"have snapshot 3: {have_snapshot(p, '3')}") + print(f"have snapshot 4: {have_snapshot(p, '4')}") close_project(p) # delete_project(p) @@ -74,6 +90,8 @@ def demo_transaction(): def demo_1_title(): p = "demo_1_title" + print(p) + if is_project_open(p): close_project(p) @@ -104,6 +122,8 @@ def demo_1_title(): def demo_2_junctions(): p = "demo_2_junctions" + print(p) + if is_project_open(p): close_project(p) @@ -157,8 +177,8 @@ def demo_2_junctions(): if __name__ == "__main__": - # demo_snapshot() + demo_snapshot() demo_transaction() - # demo_1_title() - # demo_2_junctions() + demo_1_title() + demo_2_junctions() pass