Skip to content

Commit

Permalink
Fix unrelated test
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Jan 25, 2024
1 parent 61ff928 commit b1e8675
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions ibllib/plots/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def register_image(self, image_file, text='', json_field=None, width=None):
"""
# the protocol is not compatible with byte streaming and json, so serialize the json object here
# Make sure that user is logged in, if not, try to log in
assert self.one.alyx.is_logged_in, "No Alyx user is logged in, try running one.alyx.authenticate() first"
assert self.one.alyx.is_logged_in, 'No Alyx user is logged in, try running one.alyx.authenticate() first'
note = {
'user': self.one.alyx.user, 'content_type': self.content_type, 'object_id': self.object_id,
'text': text, 'width': width, 'json': json.dumps(json_field)}
Expand All @@ -232,16 +232,15 @@ def register_image(self, image_file, text='', json_field=None, width=None):
# Catch error that results from object_id - content_type mismatch
try:
note_db = self.one.alyx.rest('notes', 'create', data=note, files={'image': fig_open})
fig_open.close()
return note_db
except requests.HTTPError as e:
if "matching query does not exist.'" in str(e):
fig_open.close()
if 'matching query does not exist' in str(e):
_logger.error(f'The object_id {self.object_id} does not match an object of type {self.content_type}')
_logger.debug(traceback.format_exc())
else:
fig_open.close()
raise
raise e
finally:
fig_open.close()

def register_images(self, image_list=None, texts=None, widths=None, jsons=None):
"""
Expand Down
4 changes: 2 additions & 2 deletions ibllib/tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestSnapshot(unittest.TestCase):

@classmethod
def setUpClass(cls):
# Make a small image an store in tmp file
# Make a small image and store in tmp file
cls.tmp_dir = tempfile.TemporaryDirectory()
cls.img_file = Path(cls.tmp_dir.name).joinpath('test.png')
image = Image.new('RGBA', size=(WIDTH, HEIGHT), color=(155, 0, 0))
Expand All @@ -40,7 +40,7 @@ def setUpClass(cls):
cls.eid = str(eid)

def _get_image(self, url):
# This is a bit of a hack because when running a the server locally, the request to the media folder fail
# This is a bit of a hack because when running the server locally, the request to the media folder fails
rel_path = urlparse(url).path[1:]
try:
img_file = list(Path('/var/www/').rglob(rel_path))[0]
Expand Down

0 comments on commit b1e8675

Please sign in to comment.