Skip to content

Commit

Permalink
ENH: working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jotelha committed Oct 14, 2024
1 parent 7174f98 commit c10df9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
15 changes: 4 additions & 11 deletions datalad_dtool/dtool_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ def checkpresent(self, key):
# return True if the key is present in the remote
# return False if the key is not present
# raise RemoteError if the presence of the key couldn't be determined, eg. in case of connection error
logger.debug("Looking for item %s in dataset %s", key, self.uri)

urls = self.annex.geturls(key, "dtool:")

exceptions = []
for url in urls:
url = url[len('dtool:'):]
try:
Expand All @@ -73,17 +72,11 @@ def checkpresent(self, key):
except Exception as e:
exceptions.append(e)

if len(exceptions) > 0:
raise exceptions[-1]

return False

logger.debug("Present at %s", urls)

if isinstance(self.dtool_dataset, ProtoDataSet):
self.dtool_dataset.freeze()
self.dtool_dataset = DataSet.from_uri(self.uri)



return False

def claimurl(self, url: str) -> bool:
return url.startswith("dtool:")
Expand Down
20 changes: 5 additions & 15 deletions examples/test_git-annex-remote-dtool
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,15 @@ git config user.email "[email protected]"
git config user.name "Some User"
git annex init

cp ${TESTFILE_PATH} .
git annex add testfile.txt
git commit -m "Add test file to git annex"

# get git annex-generated key
ANNEX_KEY=$(git annex lookupkey testfile.txt)

# put item into dataset at git annex-expected key
dtool add item testfile.txt "${SOURCE_DATASET}" "${ANNEX_KEY}"
dtool add item "${TESTFILE_PATH}" "${SOURCE_DATASET}"
dtool freeze "${SOURCE_DATASET}"

git annex initremote --verbose --debug dtool_remote type=external externaltype=dtool encryption=none uri="${SOURCE_DATASET}"

git annex info
ITEM_UUID=$(dtool ls "${SOURCE_DATASET}" | awk '{ print $1 }')

SPECIAL_REMOTE_UUID=$(git config --get remote.dtool_remote.annex-uuid)
git annex initremote --verbose --debug dtool_remote type=external externaltype=dtool encryption=none

# tell git annex that file is retrievable from special remote
git annex setpresentkey "${ANNEX_KEY}" "${SPECIAL_REMOTE_UUID}" 1
git annex addurl --file testfile.txt "dtool:${SOURCE_DATASET}/${ITEM_UUID}"

# test read-only special remote
git annex testremote --verbose --debug dtool_remote --test-readonly=testfile.txt 2>&1 | tail -n 1000
git annex testremote --debug --verbose dtool_remote --test-readonly=testfile.txt 2>&1 | tail -n 1000

0 comments on commit c10df9c

Please sign in to comment.