Repository navigation
Expand file tree
/
Copy pathtest_minimal_workflow.py
More file actions
212 lines (171 loc) · 5.33 KB
/
Copy pathtest_minimal_workflow.py
File metadata and controls
212 lines (171 loc) · 5.33 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"""
1. Create a test repository
2. Create files
3. Compute hashes for the new files
4. Upload the files
5. Delete the local copy of the repository
6. Clone the repository
8. Check that the annexed files are placeholders and have no content
9. Check that the git files have the correct hashes
9. Download the first file and check that only one file has content and
correct md5 hash
10. Download the second file and check that both files have content and
correct md5 hashes
11. Delete the local copy of the repository
"""
import os
import tempfile
import shutil
from glob import glob
from runner import Runner
import util
import pytest
def hashfiles():
hashes = dict()
for fname in glob("*"):
if os.path.exists(fname):
hashes[fname] = util.md5sum(fname)
else:
# For broken links: annexed files without content
hashes[fname] = None
return hashes
@pytest.fixture
def runner():
r = Runner()
r.login()
reponame = util.randrepo()
r.runcommand("gin", "create", reponame,
"Test a minimal workflow")
r.reponame = reponame
r.cdrel(reponame)
r.repositories[r.cmdloc] = reponame
yield r
r.cleanup()
r.logout()
@pytest.fixture
def drunner():
remoteloc = tempfile.TemporaryDirectory(prefix="gin-cli-test")
r = Runner(False)
reponame = util.randrepo()
r.reponame = reponame
os.mkdir(reponame)
r.cdrel(reponame)
# Create repo in A
r.runcommand("gin", "init")
r.runcommand("gin", "add-remote", "--create", "--default",
"origin", f"dir:{remoteloc.name}")
r.runcommand("gin", "upload")
r.repositories[r.cmdloc] = None
r.remotedir = remoteloc
yield r
util.set_rwx_recursive(remoteloc.name)
r.cleanup()
def test_workflow(runner):
r = runner
# create files in root
for idx in range(5):
util.mkrandfile(f"root-{idx}.git", 5)
for idx in range(7):
util.mkrandfile(f"root-{idx}.annex", 2000)
# compute hashes
orighashes = hashfiles()
# upload
r.runcommand("gin", "upload", ".")
# cleanup local repository
r.runcommand("gin", "annex", "uninit", exit=False)
r.cdrel("..")
shutil.rmtree(r.reponame, onerror=util.force_rm)
# redownload and check the hashes
repopath = f"{r.username}/{r.reponame}"
r.runcommand("gin", "get", repopath)
r.cdrel(r.reponame)
# should have 5 OK files and 7 NC files
status = util.zerostatus()
status["OK"] = 5
status["NC"] = 7
util.assert_status(r, status=status)
curhashes = hashfiles()
for k in curhashes:
orig = orighashes[k]
cur = curhashes[k]
if k.endswith("git"):
assert orig == cur
assert not util.isannexed(r, k)
elif k.endswith("annex"):
assert orig != cur
assert util.isannexed(r, k)
else:
assert False, f"Unexpected file {k}"
r.runcommand("gin", "get-content", "root-1.annex")
status["OK"] += 1
status["NC"] -= 1
util.assert_status(r, status=status)
curhashes = hashfiles()
assert orighashes["root-1.annex"] == curhashes["root-1.annex"]
assert util.isannexed(r, "root-1.annex")
# download everything
r.runcommand("gin", "getc", ".")
# everything should be OK
status["OK"] += status["NC"]
status["NC"] = 0
util.assert_status(r, status=status)
# all hashes should match original now
curhashes = hashfiles()
assert curhashes == orighashes
@pytest.mark.offline
def test_workflow_offline(drunner):
r = drunner
# create files in root
for idx in range(5):
util.mkrandfile(f"root-{idx}.git", 5)
for idx in range(7):
util.mkrandfile(f"root-{idx}.annex", 2000)
# compute hashes
orighashes = hashfiles()
print(orighashes)
# upload
r.runcommand("gin", "upload", ".")
# cleanup local repository
r.runcommand("gin", "annex", "uninit", exit=False)
r.cdrel("..")
shutil.rmtree(r.reponame, onerror=util.force_rm)
# redownload and check the hashes
os.mkdir(r.reponame)
r.cdrel(r.reponame)
r.runcommand("gin", "init")
r.runcommand("gin", "add-remote", "--default",
"origin", f"dir:{r.remotedir.name}")
r.runcommand("gin", "download")
# should have 5 OK files and 7 NC files
status = util.zerostatus()
status["OK"] = 5
status["NC"] = 7
util.assert_status(r, status=status)
curhashes = hashfiles()
for k in curhashes:
orig = orighashes[k]
cur = curhashes[k]
if k.endswith("git"):
assert orig == cur
assert not util.isannexed(r, k)
elif k.endswith("annex"):
assert orig != cur
assert util.isannexed(r, k)
else:
assert False, f"Unexpected file {k}"
r.runcommand("gin", "get-content", "root-1.annex")
status["OK"] += 1
status["NC"] -= 1
util.assert_status(r, status=status)
curhashes = hashfiles()
assert orighashes["root-1.annex"] == curhashes["root-1.annex"]
assert util.isannexed(r, k)
# download everything
r.runcommand("gin", "getc", ".")
# everything should be OK
status["OK"] += status["NC"]
status["NC"] = 0
util.assert_status(r, status=status)
# all hashes should match original now
curhashes = hashfiles()
assert curhashes == orighashes