Reduce duplication in test

This commit is contained in:
Adriane Boyd 2022-11-07 16:48:35 +01:00
parent ee9f7ce232
commit 45cdf47877

View File

@ -861,20 +861,22 @@ def test_span_length_freq_dist_output_must_be_correct():
def test_local_remote_storage():
with make_tempdir() as d:
filename = "a.txt"
content = "older context"
for content_hash in ("aaaa", "bbbb", "cccc"):
content = f"{content_hash} content"
loc_file = d / "root" / filename
if not loc_file.parent.exists():
loc_file.parent.mkdir(parents=True)
with loc_file.open(mode="w") as file_:
file_.write(content)
# push first version to remote storage
remote = RemoteStorage(d / "root", str(d / "remote"))
remote.push(filename, "aaaa", "aaaa")
remote.push(filename, "aaaa", content_hash)
# retrieve with full hashes
loc_file.unlink()
remote.pull(filename, command_hash="aaaa", content_hash="aaaa")
remote.pull(filename, command_hash="aaaa", content_hash=content_hash)
with loc_file.open(mode="r") as file_:
assert file_.read() == content
@ -886,40 +888,7 @@ def test_local_remote_storage():
# retrieve with content hash
loc_file.unlink()
remote.pull(filename, content_hash="aaaa")
with loc_file.open(mode="r") as file_:
assert file_.read() == content
# retrieve with no hashes
loc_file.unlink()
remote.pull(filename)
with loc_file.open(mode="r") as file_:
assert file_.read() == content
# push second version to remote storage
content = "newer content"
with loc_file.open(mode="w") as file_:
file_.write(content)
remote.push(filename, "aaaa", "bbbb")
assert (d / "remote" / filename / "aaaa" / "bbbb").stat().st_mtime > (
d / "remote" / filename / "aaaa" / "aaaa"
).stat().st_mtime
# retrieve with full hashes
loc_file.unlink()
remote.pull(filename, command_hash="aaaa", content_hash="bbbb")
with loc_file.open(mode="r") as file_:
assert file_.read() == content
# retrieve with command hash
loc_file.unlink()
remote.pull(filename, command_hash="aaaa")
with loc_file.open(mode="r") as file_:
assert file_.read() == content
# retrieve with content hash
loc_file.unlink()
remote.pull(filename, content_hash="bbbb")
remote.pull(filename, content_hash=content_hash)
with loc_file.open(mode="r") as file_:
assert file_.read() == content