Skip to content

Commit

Permalink
added code to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Ortiz authored and Carlos Ortiz committed Sep 8, 2021
1 parent e244337 commit 6452838
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
7 changes: 4 additions & 3 deletions datajoint/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def delete(self, *, delete_external_files=None, limit=None, display_progress=Tru
error_list = []
for uuid, external_path in items:
try:
count = len(self & {'hash': uuid}).delete_quick(get_count=True) # optimize
count = len(self & {'hash': uuid}) # optimize
print(f'\n\n\nCOUNT IS: {count}')
except Exception:
pass # if delete failed, do not remove the external file
Expand All @@ -351,8 +351,9 @@ def delete(self, *, delete_external_files=None, limit=None, display_progress=Tru
self._remove_external_file(external_path)
except Exception as error:
error_list.append((uuid, external_path, str(error)))
else:
#(self & {'hash': uuid}).delete_quick(get_count=True)
else:
(self & {'hash': uuid}).delete_quick(get_count=True)

return error_list


Expand Down
Binary file added djtest_extern/4/c/4c16e9e15b64474e4b56ba22bb17faae
Binary file not shown.
Binary file not shown.
61 changes: 40 additions & 21 deletions tests/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,53 +121,72 @@ def test_remove_fail():



data = dict(simple = 1, item = [1, 2, 3])
data = dict(simple = 2, item = [1, 2, 3])
Simple.insert1(data)

#print('location')
print('\n BEFORE DELETE: list of dir stores, local, location')
print(os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c'))
# print('\n IN TEST: BEFORE DELETE: list of dir stores, local, location')
print('stores location -----------\n')
print(dj.config['stores']['local']['location'])
print('local location -----------\n')
print(schema.external['local'])
print('----------------------------')

path1 = dj.config['stores']['local']['location'] + '/djtest_extern/4/c/'

path2 = os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c/')
argDir = dj.config['stores']['local']['location'] + '/djtest_extern/4/c/'

print(f'argDir----------\n{argDir}\n')

path2 = os.listdir(argDir)

print(path1 + path2[0])
# print(path1 + path2[0])

old_name = path1 + path2[0]

new_name = "/tmp/newfile"

os.rename(old_name, new_name)

print(f'\nis the new file name a file? {os.path.isfile(new_name)}')
print(f'\nis the old file name a file? {os.path.isfile(old_name)}')
# print(f'\n IN TEST: is the new file name a file? {os.path.isfile(new_name)}')
# print(f'\n IN TEST: is the old file name a file? {os.path.isfile(old_name)}')

print(os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c/'))
# print(os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c/'))

# st = stat(path1 + path2[0])
# print(bool(st.st_mode & stat.S_IXUSR))

#print(getpwuid(stat(path3).st_uid).pw_name)

print(f'simple table before delete {Simple()}')
(Simple & 'simple=1').delete()
print(f'simple table after delete {Simple()}')
print('-------------showing external store before delete with flag---------')
print(schema.external['local'])
# print(f' IN TEST: simple table before delete {Simple()}')
(Simple & 'simple=2').delete()
# print(f' IN TEST: simple table after delete {Simple()}')
# print(' IN TEST: -------------showing external store before delete with flag---------')
# print(schema.external['local'])
listOfErrors = schema.external['local'].delete(delete_external_files=True)
print(f'list of errors: {listOfErrors}')
print('list of dir stores, local, location')
print(os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c'))
print('-------------showing external store after delete with flag---------')
print(schema.external['local'])
# print(f' IN TEST: list of errors: {listOfErrors}')
# print(' IN TEST: list of dir stores, local, location')
# print(os.listdir(dj.config['stores']['local']['location'] + '/djtest_extern/4/c'))
# print(' IN TEST: -------------showing external store after delete with flag---------')
# print(schema.external['local'])

print(f'\n is this the UID or HASH? {listOfErrors[0][0]} ')
# print(f'\n IN TEST: is this the UID or HASH? {listOfErrors[0][0]}')

LENGTH_OF_QUERY = len(schema.external['local'] & dict(hash = listOfErrors[0][0]))
# LENGTH_OF_QUERY = len(schema.external['local'] & dict(hash = listOfErrors[0][0]))

print(f'\nWHAT IS THE LENGTH OF THIS? {LENGTH_OF_QUERY}')
# print(f'\n IN TEST: WHAT IS THE LENGTH OF THIS? {LENGTH_OF_QUERY}')

assert len(listOfErrors) == 1, 'unexpected number of errors'
assert len(schema.external['local'] & dict(hash = listOfErrors[0][0])) == 1, 'unexpected number of rows in external table'

#---------------------CLEAN UP--------------------
os.rename(new_name, old_name) #switching from the new name back to the old name

# print(f'this is the old_name after the asserts {old_name}')

# print(f'\n IN TEST: is the new file name a file? {os.path.isfile(new_name)}')
# print(f'\n IN TEST: is the old file name a file? {os.path.isfile(old_name)}')

listOfErrors = schema.external['local'].delete(delete_external_files=True)

print(len(listOfErrors))

0 comments on commit 6452838

Please sign in to comment.