Skip to content
Snippets Groups Projects
Commit b3ae9bc1 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST: extended test for getting file identifiables

parent f2a24be0
No related branches found
No related tags found
1 merge request!53Release 0.1
...@@ -256,7 +256,18 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter): ...@@ -256,7 +256,18 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
return self._records return self._records
def get_file(self, identifiable: db.File): def get_file(self, identifiable: db.File):
raise NotImplementedError() """
Just look in records for a file with the same path.
"""
candidates = []
for record in self._records:
if record.role == "File" and record.path == identifiable.path:
candidates.append(record)
if len(candidates) > 1:
raise RuntimeError("Identifiable was not defined unambigiously.")
if len(candidates) == 0:
return None
return candidates[0]
def store_state(self, filename): def store_state(self, filename):
with open(filename, "w") as f: with open(filename, "w") as f:
......
...@@ -24,8 +24,12 @@ def test_file_identifiable(): ...@@ -24,8 +24,12 @@ def test_file_identifiable():
assert identifiable.path == identifiable2.path assert identifiable.path == identifiable2.path
# ... and very boring: # ... and very boring:
assert identifiable.path is None assert identifiable.path is None
# Test functionality of retrieving the files:
# TODO: test for corresponding retrieval "get_file" identified_file = ident.get_file(identifiable)
identified_file2 = ident.get_file(file_obj)
# The both should be None currently as there are no files in the local store yet:
assert identified_file is None
assert identified_file2 is None
# Let's make it more interesting: # Let's make it more interesting:
file_obj.path = "/test/bla/bla.txt" file_obj.path = "/test/bla/bla.txt"
...@@ -43,5 +47,29 @@ def test_file_identifiable(): ...@@ -43,5 +47,29 @@ def test_file_identifiable():
identified_file = ident.get_file(identifiable) identified_file = ident.get_file(identifiable)
# or directly using: # or directly using:
identified_file2 = ident.get_file(file_obj) identified_file2 = ident.get_file(file_obj)
# The both should be None currently as there are no files in the local store yet:
assert identified_file is None
assert identified_file2 is None
# Try again with actual files in the store:
records = ident.get_records()
test_record_wrong_path = db.File(
path="/bla/bla/test.txt")
test_record_correct_path = db.File(
path="/test/bla/bla.txt")
test_record_alsocorrect_path = db.File(
path="/test/bla/bla.txt")
records.append(test_record_wrong_path)
identified_file = ident.get_file(file_obj)
assert identified_file is None
records.append(test_record_correct_path)
identified_file = ident.get_file(file_obj)
assert identified_file is not None
assert identified_file.path == file_obj.path
with raises(RuntimeError, match=".*unambigiously.*"):
records.append(test_record_alsocorrect_path)
identified_file = ident.get_file(file_obj)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment