1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/usr/bin/env python3
# Copyright (C) 2018 Lars Wirzenius
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import uuid
import muck
def create_id():
return str(uuid.uuid4())
def changes(n):
res = {
'foo': 'bar',
}
for i in range(n):
meta = {
'id': create_id(),
'rev': create_id(),
}
chg = muck.CreateChange(meta=meta, res=res)
yield chg
def compare_dicts(d1, d2):
for key in d1:
if key not in d2:
return 'Missing key: {}'.format(key)
for key in d2:
if key not in d1:
return 'Extra key: {}'.format(key)
for key in d1:
v1 = d1[key]
v2 = d2[key]
if v1 != v2:
return 'Different values: {}: {} vs {}'.format(key, v1, v2)
return None
store_dir = sys.argv[1]
n = int(sys.argv[2])
if not os.path.exists(store_dir):
os.mkdir(store_dir)
st = muck.Store(store_dir)
for i, chg in enumerate(changes(n)):
st.change(chg)
st2 = muck.Store(store_dir)
ms = st.get_memory_store()
ms2 = st2.get_memory_store()
err = compare_dicts(ms.as_dict(), ms2.as_dict())
if err:
sys.stderr.write('ERROR: {}: {}\n'.format(i+1, err))
sys.exit(1)
sys.stdout.write('OK\n')
|