Skip to content

Commit

Permalink
Make sure unpack takes delete as a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
mraspaud committed Oct 9, 2023
1 parent a644491 commit 4ed30c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions trollmoves/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def pong(self, message):
def push(self, message):
"""Reply to push request."""
new_msg = self._move_files(message)
if new_msg and new_msg.type is not 'err':
if new_msg and new_msg.type != 'err':
_destination = clean_url(new_msg.data['destination'])
new_msg = Message(message.subject,
_get_push_message_type(message),
data=message.data.copy())
new_msg.data['destination'] = _destination
new_msg.data['destination'] = _destination

return new_msg

Expand All @@ -147,7 +147,7 @@ def _move_files(self, message):
if return_message is not None:
break
return_message = self._move_file(pathname, message, rel_path)
if return_message.type is "err":
if return_message.type == "err":
break

return return_message
Expand Down Expand Up @@ -931,7 +931,7 @@ def unpack(pathname,
compression=None,
working_directory=None,
prog=None,
delete="False",
delete=False,
**kwargs):
"""Unpack *pathname*."""
del kwargs
Expand All @@ -945,7 +945,7 @@ def unpack(pathname,
except Exception:
LOGGER.exception("Could not decompress %s", pathname)
else:
if delete.lower() in ["1", "yes", "true", "on"]:
if delete:
os.remove(pathname)
return new_path
return pathname
Expand Down
14 changes: 14 additions & 0 deletions trollmoves/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,17 @@ def test_requestmanager_is_delete_set_True(patch_validate_file_pattern):
port = 9876
req_man = RequestManager(port, attrs={'delete': True})
assert req_man._is_delete_set() is True


def test_unpack_with_delete(tmp_path):
"""Test unpacking with deletion."""
import bz2
zipped_file = tmp_path / "my_file.txt.bz2"
with open(zipped_file, 'wb') as fd_:
fd_.write(bz2.compress(b"hello world", 5))

from trollmoves.server import unpack

res = unpack(zipped_file, delete=True, working_directory=tmp_path, compression="bzip")
assert not os.path.exists(zipped_file)
assert res == os.path.splitext(zipped_file)[0]

0 comments on commit 4ed30c1

Please sign in to comment.