mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 21:54:54 +03:00
Reduce duplication in test
This commit is contained in:
parent
ee9f7ce232
commit
45cdf47877
|
@ -861,70 +861,39 @@ def test_span_length_freq_dist_output_must_be_correct():
|
||||||
def test_local_remote_storage():
|
def test_local_remote_storage():
|
||||||
with make_tempdir() as d:
|
with make_tempdir() as d:
|
||||||
filename = "a.txt"
|
filename = "a.txt"
|
||||||
content = "older context"
|
|
||||||
|
|
||||||
loc_file = d / "root" / filename
|
for content_hash in ("aaaa", "bbbb", "cccc"):
|
||||||
loc_file.parent.mkdir(parents=True)
|
content = f"{content_hash} content"
|
||||||
with loc_file.open(mode="w") as file_:
|
loc_file = d / "root" / filename
|
||||||
file_.write(content)
|
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
|
# push first version to remote storage
|
||||||
remote = RemoteStorage(d / "root", str(d / "remote"))
|
remote = RemoteStorage(d / "root", str(d / "remote"))
|
||||||
remote.push(filename, "aaaa", "aaaa")
|
remote.push(filename, "aaaa", content_hash)
|
||||||
|
|
||||||
# retrieve with full hashes
|
# retrieve with full hashes
|
||||||
loc_file.unlink()
|
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_:
|
with loc_file.open(mode="r") as file_:
|
||||||
assert file_.read() == content
|
assert file_.read() == content
|
||||||
|
|
||||||
# retrieve with command hash
|
# retrieve with command hash
|
||||||
loc_file.unlink()
|
loc_file.unlink()
|
||||||
remote.pull(filename, command_hash="aaaa")
|
remote.pull(filename, command_hash="aaaa")
|
||||||
with loc_file.open(mode="r") as file_:
|
with loc_file.open(mode="r") as file_:
|
||||||
assert file_.read() == content
|
assert file_.read() == content
|
||||||
|
|
||||||
# retrieve with content hash
|
# retrieve with content hash
|
||||||
loc_file.unlink()
|
loc_file.unlink()
|
||||||
remote.pull(filename, content_hash="aaaa")
|
remote.pull(filename, content_hash=content_hash)
|
||||||
with loc_file.open(mode="r") as file_:
|
with loc_file.open(mode="r") as file_:
|
||||||
assert file_.read() == content
|
assert file_.read() == content
|
||||||
|
|
||||||
# retrieve with no hashes
|
# retrieve with no hashes
|
||||||
loc_file.unlink()
|
loc_file.unlink()
|
||||||
remote.pull(filename)
|
remote.pull(filename)
|
||||||
with loc_file.open(mode="r") as file_:
|
with loc_file.open(mode="r") as file_:
|
||||||
assert file_.read() == content
|
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")
|
|
||||||
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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user