diff --git a/trollmoves/server.py b/trollmoves/server.py index 332401a8..2d65a21b 100644 --- a/trollmoves/server.py +++ b/trollmoves/server.py @@ -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 @@ -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 @@ -931,7 +931,7 @@ def unpack(pathname, compression=None, working_directory=None, prog=None, - delete="False", + delete=False, **kwargs): """Unpack *pathname*.""" del kwargs @@ -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 diff --git a/trollmoves/tests/test_server.py b/trollmoves/tests/test_server.py index fc3090d9..e41a12af 100644 --- a/trollmoves/tests/test_server.py +++ b/trollmoves/tests/test_server.py @@ -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]