8
8
from arctic .exceptions import ConcurrentModificationException , NoDataFoundException
9
9
10
10
11
- def test_ConcurrentWriteBlock_simple ():
11
+ def test_ArcticTransaction_simple ():
12
12
vs = create_autospec (VersionStore , _collection = Mock ())
13
13
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
14
14
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
@@ -20,11 +20,27 @@ def test_ConcurrentWriteBlock_simple():
20
20
cwb .write (sentinel .symbol , pd .DataFrame (index = [3 , 4 ], data = {'a' : [1.0 , 2.0 ]}), metadata = sentinel .meta )
21
21
22
22
assert not vs ._delete_version .called
23
- vs .write .assert_called_once_with (sentinel .symbol , ANY , prune_previous_version = True , metadata = sentinel .meta )
24
- vs .list_versions .assert_called_once_with (sentinel .symbol )
23
+ assert vs .write .call_args_list == [call (sentinel .symbol , ANY , prune_previous_version = True , metadata = sentinel .meta )]
24
+ assert vs .list_versions .call_args_list == [call (sentinel .symbol )]
25
+ assert vs ._write_audit .call_args_list == [call (sentinel .user , sentinel .log , ANY )]
26
+
27
+
28
+ def test_ArticTransaction_no_audit ():
29
+ vs = create_autospec (VersionStore , _collection = Mock ())
30
+ ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
31
+ vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
32
+ vs .write .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 2 ,
33
+ metadata = None , data = None )
34
+ vs .list_versions .return_value = [{'version' : 2 }, {'version' : 1 }]
35
+
36
+ with ArcticTransaction (vs , sentinel .symbol , sentinel .user , sentinel .log , audit = False ) as cwb :
37
+ cwb .write (sentinel .symbol , pd .DataFrame (index = [3 , 4 ], data = {'a' : [1.0 , 2.0 ]}), metadata = sentinel .meta )
38
+
39
+ assert vs .write .call_count == 1
40
+ assert vs ._write_audit .call_count == 0
25
41
26
42
27
- def test_ConcurrentWriteBlock_writes_if_metadata_changed ():
43
+ def test_ArcticTransaction_writes_if_metadata_changed ():
28
44
vs = create_autospec (VersionStore , _collection = Mock ())
29
45
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
30
46
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
@@ -49,7 +65,7 @@ def test_ConcurrentWriteBlock_writes_if_metadata_changed():
49
65
assert cwb ._do_write is False
50
66
51
67
52
- def test_ConcurrentWriteBlock_writes_if_base_data_corrupted ():
68
+ def test_ArcticTransaction_writes_if_base_data_corrupted ():
53
69
54
70
vs = create_autospec (VersionStore , _collection = Mock ())
55
71
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
@@ -67,7 +83,7 @@ def test_ConcurrentWriteBlock_writes_if_base_data_corrupted():
67
83
assert vs .list_versions .call_args_list == [call (sentinel .symbol )]
68
84
69
85
70
- def test_ConcurrentWriteBlock_writes_no_data_found ():
86
+ def test_ArcticTransaction_writes_no_data_found ():
71
87
vs = create_autospec (VersionStore , _collection = Mock ())
72
88
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
73
89
vs .read .side_effect = NoDataFoundException ('no data' )
@@ -85,7 +101,7 @@ def test_ConcurrentWriteBlock_writes_no_data_found():
85
101
call (sentinel .symbol )]
86
102
87
103
88
- def test_ConcurrentWriteBlock_writes_no_data_found_deleted ():
104
+ def test_ArcticTransaction_writes_no_data_found_deleted ():
89
105
vs = create_autospec (VersionStore , _collection = Mock ())
90
106
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
91
107
vs .read .side_effect = NoDataFoundException ('no data' )
@@ -103,7 +119,7 @@ def test_ConcurrentWriteBlock_writes_no_data_found_deleted():
103
119
call (sentinel .symbol )]
104
120
105
121
106
- def test_ConcurrentWriteBlock_does_nothing_when_data_not_modified ():
122
+ def test_ArcticTransaction_does_nothing_when_data_not_modified ():
107
123
vs = create_autospec (VersionStore , _collection = Mock ())
108
124
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
109
125
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
@@ -117,7 +133,7 @@ def test_ConcurrentWriteBlock_does_nothing_when_data_not_modified():
117
133
assert not vs .write .called
118
134
119
135
120
- def test_ConcurrentWriteBlock_does_nothing_when_data_is_None ():
136
+ def test_ArcticTransaction_does_nothing_when_data_is_None ():
121
137
vs = create_autospec (VersionStore , _collection = Mock ())
122
138
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
123
139
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
@@ -131,7 +147,7 @@ def test_ConcurrentWriteBlock_does_nothing_when_data_is_None():
131
147
assert not vs .write .called
132
148
133
149
134
- def test_ConcurrentWriteBlock_guards_against_inconsistent_ts ():
150
+ def test_ArcticTransaction_guards_against_inconsistent_ts ():
135
151
vs = create_autospec (VersionStore , _collection = Mock ())
136
152
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
137
153
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
@@ -144,7 +160,7 @@ def test_ConcurrentWriteBlock_guards_against_inconsistent_ts():
144
160
pass
145
161
146
162
147
- def test_ConcurrentWriteBlock_detects_concurrent_writes ():
163
+ def test_ArcticTransaction_detects_concurrent_writes ():
148
164
vs = create_autospec (VersionStore , _collection = Mock ())
149
165
ts1 = pd .DataFrame (index = [1 , 2 ], data = {'a' :[1.0 , 2.0 ]})
150
166
vs .read .return_value = VersionedItem (symbol = sentinel .symbol , library = sentinel .library , version = 1 , metadata = None , data = ts1 )
0 commit comments