1
"""A more complex example of do/undo capability with PyTables
3
Here, names has been assigned to the marks, and jumps are done between
11
fileh = tables.openFile('tutorial3-2.h5', 'w', title='Undo/Redo demo 2')
13
#'-**-**-**-**-**-**- enable undo/redo log -**-**-**-**-**-**-**-'
16
# Start undoable operations
17
fileh.createArray('/', 'otherarray1', [3,4], 'Another array 1')
18
fileh.createGroup('/', 'agroup', 'Group 1')
19
# Create a 'first' mark
21
fileh.createArray('/agroup', 'otherarray2', [4,5], 'Another array 2')
22
fileh.createGroup('/agroup', 'agroup2', 'Group 2')
23
# Create a 'second' mark
25
fileh.createArray('/agroup/agroup2', 'otherarray3', [5,6], 'Another array 3')
26
# Create a 'third' mark
28
fileh.createArray('/', 'otherarray4', [6,7], 'Another array 4')
29
fileh.createArray('/agroup', 'otherarray5', [7,8], 'Another array 5')
31
# Now go to mark 'first'
33
assert '/otherarray1' in fileh.objects
34
assert '/agroup' in fileh.objects
35
assert '/agroup/agroup2' not in fileh.objects
36
assert '/agroup/otherarray2' not in fileh.objects
37
assert '/agroup/agroup2/otherarray3' not in fileh.objects
38
assert '/otherarray4' not in fileh.objects
39
assert '/agroup/otherarray5' not in fileh.objects
42
assert '/otherarray1' in fileh.objects
43
assert '/agroup' in fileh.objects
44
assert '/agroup/agroup2' in fileh.objects
45
assert '/agroup/otherarray2' in fileh.objects
46
assert '/agroup/agroup2/otherarray3' in fileh.objects
47
assert '/otherarray4' not in fileh.objects
48
assert '/agroup/otherarray5' not in fileh.objects
49
# Now go to mark 'second'
51
assert '/otherarray1' in fileh.objects
52
assert '/agroup' in fileh.objects
53
assert '/agroup/agroup2' in fileh.objects
54
assert '/agroup/otherarray2' in fileh.objects
55
assert '/agroup/agroup2/otherarray3' not in fileh.objects
56
assert '/otherarray4' not in fileh.objects
57
assert '/agroup/otherarray5' not in fileh.objects
60
assert '/otherarray1' in fileh.objects
61
assert '/agroup' in fileh.objects
62
assert '/agroup/agroup2' in fileh.objects
63
assert '/agroup/otherarray2' in fileh.objects
64
assert '/agroup/agroup2/otherarray3' in fileh.objects
65
assert '/otherarray4' in fileh.objects
66
assert '/agroup/otherarray5' in fileh.objects
67
# Check that objects have come back to life in a sane state
68
assert fileh.root.otherarray1.read() == [3,4]
69
assert fileh.root.agroup.otherarray2.read() == [4,5]
70
assert fileh.root.agroup.agroup2.otherarray3.read() == [5,6]
71
assert fileh.root.otherarray4.read() == [6,7]
72
assert fileh.root.agroup.otherarray5.read() == [7,8]
75
#'-**-**-**-**-**-**- disable undo/redo log -**-**-**-**-**-**-**-'