From cb360463163b4cdedd64e4fe152a3a3706eb0639 Mon Sep 17 00:00:00 2001 From: tr4nt0r <4445816+tr4nt0r@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:08:34 +0100 Subject: [PATCH] Apply ruff fixes --- pyproject.toml | 8 +++- src/pyloadapi/api.py | 88 ++++++++++++++++++++++++---------- src/pyloadapi/cli.py | 110 +++++++++++++++++++++++++++++-------------- tests/conftest.py | 3 +- tests/test_api.py | 57 +++++++++++++++------- tests/test_cli.py | 21 +++++---- 6 files changed, 195 insertions(+), 92 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d90d964..da6c87c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,8 +106,12 @@ pythonpath = [ asyncio_default_fixture_loop_scope = "function" [tool.ruff.lint] -extend-select = ["I", "TRY", "UP", "D", "W"] -extend-ignore = ["D213", "D202", "D203", "D213", "UP038", "TRY003"] +extend-select = ["ALL"] +extend-ignore = ["D213", "D202", "D203", "D213", "TRY003", "E501", "ANN401", "A005", "N818", "N812"] + +[tool.ruff.lint.per-file-ignores] +"cli.py" = ["FBT001"] +"tests/*" = ["SLF001", "S101", "S105", "ARG001", "FBT001"] [tool.ruff.lint.pydocstyle] convention = "numpy" diff --git a/src/pyloadapi/api.py b/src/pyloadapi/api.py index 7bb17a4..5d8168e 100644 --- a/src/pyloadapi/api.py +++ b/src/pyloadapi/api.py @@ -15,8 +15,13 @@ import aiohttp from yarl import URL -from .exceptions import CannotConnect, InvalidAuth, ParserError -from .types import Destination, LoginResponse, PyLoadCommand, StatusServerResponse +from pyloadapi.exceptions import CannotConnect, InvalidAuth, ParserError +from pyloadapi.types import ( + Destination, + LoginResponse, + PyLoadCommand, + StatusServerResponse, +) _LOGGER = logging.getLogger(__package__) @@ -74,7 +79,10 @@ async def login(self) -> LoginResponse: try: async with self._session.post(url, data=user_data) as r: _LOGGER.debug( - "Response from %s [%s]: %s", url, r.status, await r.text() + "Response from %s [%s]: %s", + url, + r.status, + await r.text(), ) r.raise_for_status() @@ -82,10 +90,12 @@ async def login(self) -> LoginResponse: data: LoginResponse = await r.json() except (JSONDecodeError, TypeError, aiohttp.ContentTypeError) as e: _LOGGER.debug( - "Exception: Cannot parse login response:\n %s", exc_info=True + "Exception: Cannot parse login response:\n %s", + exc_info=True, ) + msg = "Login failed during parsing of request response." raise ParserError( - "Login failed during parsing of request response." + msg, ) from e else: if not data: @@ -96,7 +106,9 @@ async def login(self) -> LoginResponse: raise CannotConnect from e async def get( - self, command: PyLoadCommand, params: dict[str, Any] | None = None + self, + command: PyLoadCommand, + params: dict[str, Any] | None = None, ) -> Any: """Execute a pyLoad API command. @@ -139,12 +151,16 @@ async def get( try: async with self._session.get(url, params=params) as r: _LOGGER.debug( - "Response from %s [%s]: %s", r.url, r.status, await r.text() + "Response from %s [%s]: %s", + r.url, + r.status, + await r.text(), ) if r.status == HTTPStatus.UNAUTHORIZED: + msg = "Request failed due invalid or expired authentication cookie." raise InvalidAuth( - "Request failed due invalid or expired authentication cookie." + msg, ) r.raise_for_status() try: @@ -155,8 +171,9 @@ async def get( command, exc_info=True, ) + msg = "Get {command} failed during parsing of request response." raise ParserError( - "Get {command} failed during parsing of request response." + msg, ) from e return data @@ -167,8 +184,9 @@ async def get( command, exc_info=True, ) + msg = "Executing command {command} failed due to request exception" raise CannotConnect( - "Executing command {command} failed due to request exception" + msg, ) from e async def post( @@ -224,12 +242,16 @@ async def post( try: async with self._session.post(url, data=data) as r: _LOGGER.debug( - "Response from %s [%s]: %s", r.url, r.status, await r.text() + "Response from %s [%s]: %s", + r.url, + r.status, + await r.text(), ) if r.status == HTTPStatus.UNAUTHORIZED: + msg = "Request failed due invalid or expired authentication cookie." raise InvalidAuth( - "Request failed due invalid or expired authentication cookie." + msg, ) r.raise_for_status() try: @@ -240,8 +262,9 @@ async def post( command, exc_info=True, ) + msg = f"Get {command} failed during parsing of request response." raise ParserError( - f"Get {command} failed during parsing of request response." + msg, ) from e return data @@ -252,8 +275,9 @@ async def post( command, exc_info=True, ) + msg = f"Executing command {command} failed due to request exception" raise CannotConnect( - f"Executing command {command} failed due to request exception" + msg, ) from e async def get_status(self) -> StatusServerResponse: @@ -291,7 +315,8 @@ async def get_status(self) -> StatusServerResponse: try: data: StatusServerResponse = await self.get(PyLoadCommand.STATUS) except CannotConnect as e: - raise CannotConnect("Get status failed due to request exception") from e + msg = "Get status failed due to request exception" + raise CannotConnect(msg) from e else: return data @@ -323,8 +348,9 @@ async def pause(self) -> None: try: await self.get(PyLoadCommand.PAUSE) except CannotConnect as e: + msg = "Pausing download queue failed due to request exception" raise CannotConnect( - "Pausing download queue failed due to request exception" + msg, ) from e async def unpause(self) -> None: @@ -355,8 +381,9 @@ async def unpause(self) -> None: try: await self.get(PyLoadCommand.UNPAUSE) except CannotConnect as e: + msg = "Unpausing download queue failed due to request exception" raise CannotConnect( - "Unpausing download queue failed due to request exception" + msg, ) from e async def toggle_pause(self) -> None: @@ -387,8 +414,9 @@ async def toggle_pause(self) -> None: try: await self.get(PyLoadCommand.TOGGLE_PAUSE) except CannotConnect as e: + msg = "Toggling pause download queue failed due to request exception" raise CannotConnect( - "Toggling pause download queue failed due to request exception" + msg, ) from e async def stop_all_downloads(self) -> None: @@ -419,8 +447,9 @@ async def stop_all_downloads(self) -> None: try: await self.get(PyLoadCommand.ABORT_ALL) except CannotConnect as e: + msg = "Aborting all running downlods failed due to request exception" raise CannotConnect( - "Aborting all running downlods failed due to request exception" + msg, ) from e async def restart_failed(self) -> None: @@ -451,8 +480,9 @@ async def restart_failed(self) -> None: try: await self.get(PyLoadCommand.RESTART_FAILED) except CannotConnect as e: + msg = "Restarting all failed files failed due to request exception" raise CannotConnect( - "Restarting all failed files failed due to request exception" + msg, ) from e async def toggle_reconnect(self) -> None: @@ -510,8 +540,9 @@ async def delete_finished(self) -> None: try: await self.get(PyLoadCommand.DELETE_FINISHED) except CannotConnect as e: + msg = "Deleting all finished files failed due to request exception" raise CannotConnect( - "Deleting all finished files failed due to request exception" + msg, ) from e async def restart(self) -> None: @@ -542,8 +573,9 @@ async def restart(self) -> None: try: await self.get(PyLoadCommand.RESTART) except CannotConnect as e: + msg = "Restarting pyLoad core failed due to request exception" raise CannotConnect( - "Restarting pyLoad core failed due to request exception" + msg, ) from e async def version(self) -> str: @@ -580,7 +612,8 @@ async def version(self) -> str: r = await self.get(PyLoadCommand.VERSION) return str(r) except CannotConnect as e: - raise CannotConnect("Get version failed due to request exception") from e + msg = "Get version failed due to request exception" + raise CannotConnect(msg) from e async def free_space(self) -> int: """Get the available free space at the download directory in bytes. @@ -617,7 +650,8 @@ async def free_space(self) -> int: r = await self.get(PyLoadCommand.FREESPACE) return int(r) except CannotConnect as e: - raise CannotConnect("Get free space failed due to request exception") from e + msg = "Get free space failed due to request exception" + raise CannotConnect(msg) from e async def add_package( self, @@ -675,7 +709,8 @@ async def add_package( ) return int(r) except CannotConnect as e: - raise CannotConnect("Adding package failed due to request exception") from e + msg = "Adding package failed due to request exception" + raise CannotConnect(msg) from e async def upload_container( self, @@ -719,6 +754,7 @@ async def upload_container( ) except CannotConnect as e: + msg = "Uploading container to pyLoad failed due to request exception" raise CannotConnect( - "Uploading container to pyLoad failed due to request exception" + msg, ) from e diff --git a/src/pyloadapi/cli.py b/src/pyloadapi/cli.py index ee32fc3..277c026 100644 --- a/src/pyloadapi/cli.py +++ b/src/pyloadapi/cli.py @@ -34,12 +34,18 @@ def save_config(config: dict[str, Any]) -> None: async def init_api( - session: aiohttp.ClientSession, api_url: str, username: str, password: str + session: aiohttp.ClientSession, + api_url: str, + username: str, + password: str, ) -> PyLoadAPI: """Initialize the PyLoadAPI.""" api = PyLoadAPI( - session=session, api_url=api_url, username=username, password=password + session=session, + api_url=api_url, + username=username, + password=password, ) await api.login() @@ -81,8 +87,9 @@ def cli( ctx.obj["password"] = config.get("password") if not all([ctx.obj["api_url"], ctx.obj["username"], ctx.obj["password"]]): + msg = "URL, username, and password must be provided either via command line or config file." raise click.ClickException( - "URL, username, and password must be provided either via command line or config file." + msg, ) @@ -110,16 +117,19 @@ async def _status() -> None: f" - Download speed: {round((stat['speed'] * 8) / 1000000, 2)} Mbit/s\n" f" - Free space: {round(free_space / (1024**3), 2)} GiB\n" f" - Reconnect: {'Enabled' if stat['reconnect'] else 'Disabled'}\n" - f" - Queue : {'Paused' if stat['pause'] else 'Running'}\n" + f" - Queue : {'Paused' if stat['pause'] else 'Running'}\n", ) except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_status()) @@ -149,17 +159,20 @@ async def _queue(pause: bool, resume: bool) -> None: s = await api.get_status() click.echo( - f"{'Paused' if s.get('pause') else 'Resumed'} download queue." + f"{'Paused' if s.get('pause') else 'Resumed'} download queue.", ) except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_queue(pause, resume)) @@ -182,13 +195,16 @@ async def _stop_all() -> None: await api.stop_all_downloads() click.echo("Aborted all running downloads.") except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_stop_all()) @@ -211,13 +227,16 @@ async def _retry() -> None: await api.restart_failed() click.echo("Retrying failed downloads.") except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_retry()) @@ -240,13 +259,16 @@ async def _delete_finished() -> None: await api.delete_finished() click.echo("Deleted finished files and packages.") except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_delete_finished()) @@ -269,13 +291,16 @@ async def _restart() -> None: await api.restart() click.echo("Restarting pyLoad...") except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_restart()) @@ -298,16 +323,19 @@ async def _toggle_reconnect() -> None: await api.toggle_reconnect() s = await api.get_status() click.echo( - f"{'Enabled' if s.get('reconnect') else 'Disabled'} auto-reconnect" + f"{'Enabled' if s.get('reconnect') else 'Disabled'} auto-reconnect", ) except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_toggle_reconnect()) @@ -325,7 +353,7 @@ async def _toggle_reconnect() -> None: def upload_container(ctx: click.Context, container: Path) -> None: """Upload a container file to pyLoad.""" - with open(container, "rb") as f: + with Path(container).open("rb") as f: binary_data = f.read() async def _upload_container() -> None: @@ -344,13 +372,16 @@ async def _upload_container() -> None: ) except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_upload_container()) @@ -369,12 +400,16 @@ def add_package(ctx: click.Context, package_name: str, queue: bool) -> None: links = [] while value := click.prompt( - "Please enter a link", type=str, default="", show_default=False + "Please enter a link", + type=str, + default="", + show_default=False, ): links.append(value) if not links: - raise click.ClickException("No links entered") + msg = "No links entered" + raise click.ClickException(msg) async def _add_package() -> None: try: @@ -393,12 +428,15 @@ async def _add_package() -> None: ) except CannotConnect as e: - raise click.ClickException("Unable to connect to pyLoad") from e + msg = "Unable to connect to pyLoad" + raise click.ClickException(msg) from e except InvalidAuth as e: + msg = "Authentication failed, verify username and password" raise click.ClickException( - "Authentication failed, verify username and password" + msg, ) from e except ParserError as e: - raise click.ClickException("Unable to parse response from pyLoad") from e + msg = "Unable to parse response from pyLoad" + raise click.ClickException(msg) from e asyncio.run(_add_package()) diff --git a/tests/conftest.py b/tests/conftest.py index ba44e31..2a99151 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,13 +57,12 @@ async def aiohttp_client_session() -> AsyncGenerator[aiohttp.ClientSession, Any] @pytest.fixture(name="pyload") async def pyloadapi_client(session: aiohttp.ClientSession) -> PyLoadAPI: """Create pyLoad instance.""" - pyload = PyLoadAPI( + return PyLoadAPI( session, TEST_API_URL, TEST_USERNAME, TEST_PASSWORD, ) - return pyload @pytest.fixture(name="mocked_aiohttp") diff --git a/tests/test_api.py b/tests/test_api.py index 296807b..1a0a4a4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -25,7 +25,9 @@ async def test_login(pyload: PyLoadAPI, mocked_aiohttp: aioresponses) -> None: """Test login.""" mocked_aiohttp.post( - f"{TEST_API_URL}api/login", status=HTTPStatus.OK, payload=TEST_LOGIN_RESPONSE + f"{TEST_API_URL}api/login", + status=HTTPStatus.OK, + payload=TEST_LOGIN_RESPONSE, ) result = await pyload.login() @@ -33,7 +35,8 @@ async def test_login(pyload: PyLoadAPI, mocked_aiohttp: aioresponses) -> None: async def test_login_invalidauth( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test login.""" mocked_aiohttp.post(f"{TEST_API_URL}api/login", status=HTTPStatus.OK) @@ -59,7 +62,10 @@ async def test_login_invalidauth( ], ) async def test_api_methods( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses, method: str, result: Any + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, + method: str, + result: Any, ) -> None: """Test API methods.""" @@ -78,7 +84,8 @@ async def test_api_methods( async def test_status_no_captcha( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test status for pre 0.5.0 pyLoad response.""" @@ -107,7 +114,9 @@ async def test_status_no_captcha( ], ) async def test_invalidauth( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses, method: str + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, + method: str, ) -> None: """Test login.""" @@ -168,7 +177,8 @@ async def test_parse_exceptions( mocked_aiohttp.post(re.compile(r".*"), status=HTTPStatus.OK) async def json(*args: Any) -> None: - raise JSONDecodeError("", "", 0) + msg = "" + raise JSONDecodeError(msg, "", 0) monkeypatch.setattr(aiohttp.ClientResponse, "json", json) @@ -177,7 +187,8 @@ async def json(*args: Any) -> None: async def test_upload_container( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test upload_container method.""" @@ -194,12 +205,14 @@ async def test_upload_container( async def test_upload_container_exception( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test upload_container exception.""" mocked_aiohttp.post( - f"{TEST_API_URL}api/uploadContainer", exception=aiohttp.ClientError + f"{TEST_API_URL}api/uploadContainer", + exception=aiohttp.ClientError, ) with pytest.raises(expected_exception=CannotConnect): @@ -207,12 +220,14 @@ async def test_upload_container_exception( async def test_upload_container_unauthorized( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test upload_container authentication error.""" mocked_aiohttp.post( - f"{TEST_API_URL}api/uploadContainer", status=HTTPStatus.UNAUTHORIZED + f"{TEST_API_URL}api/uploadContainer", + status=HTTPStatus.UNAUTHORIZED, ) with pytest.raises(expected_exception=InvalidAuth): @@ -229,7 +244,8 @@ async def test_upload_container_parse_exception( mocked_aiohttp.post(re.compile(r".*"), status=HTTPStatus.OK) async def json(*args: Any) -> None: - raise JSONDecodeError("", "", 0) + msg = "" + raise JSONDecodeError(msg, "", 0) monkeypatch.setattr(aiohttp.ClientResponse, "json", json) @@ -265,12 +281,15 @@ async def test_add_package(pyload: PyLoadAPI, mocked_aiohttp: aioresponses) -> N async def test_add_package_exception( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test add_package with exception.""" mocked_aiohttp.post( - f"{TEST_API_URL}api/addPackage", payload=1, exception=aiohttp.ClientError + f"{TEST_API_URL}api/addPackage", + payload=1, + exception=aiohttp.ClientError, ) with pytest.raises(expected_exception=CannotConnect): await pyload.add_package( @@ -284,12 +303,15 @@ async def test_add_package_exception( async def test_add_package_unauthorized( - pyload: PyLoadAPI, mocked_aiohttp: aioresponses + pyload: PyLoadAPI, + mocked_aiohttp: aioresponses, ) -> None: """Test add_package authentication error.""" mocked_aiohttp.post( - f"{TEST_API_URL}api/addPackage", payload=1, status=HTTPStatus.UNAUTHORIZED + f"{TEST_API_URL}api/addPackage", + payload=1, + status=HTTPStatus.UNAUTHORIZED, ) with pytest.raises(expected_exception=InvalidAuth): await pyload.add_package( @@ -312,7 +334,8 @@ async def test_add_package_parse_exception( mocked_aiohttp.post(re.compile(r".*"), status=HTTPStatus.OK) async def json(*args: Any) -> None: - raise JSONDecodeError("", "", 0) + msg = "" + raise JSONDecodeError(msg, "", 0) monkeypatch.setattr(aiohttp.ClientResponse, "json", json) diff --git a/tests/test_cli.py b/tests/test_cli.py index 946bcdf..afb0d94 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -55,14 +55,14 @@ def test_missing_credentials(tmp_path: Path) -> None: @pytest.mark.parametrize( ("command", "msg"), - ( + [ ("queue", "Resumed download queue.\n"), ("stop-all", "Aborted all running downloads.\n"), ("retry", "Retrying failed downloads.\n"), ("delete-finished", "Deleted finished files and packages.\n"), ("restart", "Restarting pyLoad...\n"), ("toggle-reconnect", "Disabled auto-reconnect\n"), - ), + ], ) @pytest.mark.usefixtures("mock_pyloadapi") def test_all_commands( @@ -90,7 +90,10 @@ def test_all_commands( ], ) def test_queue_with_options( - mock_pyloadapi: MagicMock, msg: str, command: str, pause: bool + mock_pyloadapi: MagicMock, + msg: str, + command: str, + pause: bool, ) -> None: """Test status.""" runner = CliRunner() @@ -114,7 +117,7 @@ def test_queue_with_options( ) @pytest.mark.parametrize( ("command"), - ( + [ "status", "queue", "queue -p", @@ -124,7 +127,7 @@ def test_queue_with_options( "delete-finished", "restart", "toggle-reconnect", - ), + ], ) def test_exceptions( mock_pyloadapi: MagicMock, @@ -165,7 +168,7 @@ def test_upload_container( runner = CliRunner() with runner.isolated_filesystem(temp_dir=tmp_path) as tmp: dlc = Path(tmp, "container.dlc") - with open(dlc, "wb") as f: + with Path(dlc).open("wb") as f: f.write(BYTE_DATA) result = runner.invoke( @@ -194,7 +197,7 @@ def test_upload_container_exceptions( runner = CliRunner() with runner.isolated_filesystem(temp_dir=tmp_path) as tmp: dlc = Path(tmp, "container.dlc") - with open(dlc, "wb") as f: + with Path(dlc).open("wb") as f: f.write(BYTE_DATA) mock_pyloadapi.upload_container.side_effect = exception @@ -215,7 +218,7 @@ def test_add_package(tmp_path: Path) -> None: result = runner.invoke( cli, args=f"--username {TEST_USERNAME} --password {TEST_PASSWORD} --api-url {TEST_API_URL} add-package Test-Package", - input=("http://example.com/file1.zip\n" "http://example.com/file2.iso\n\n"), + input=("http://example.com/file1.zip\nhttp://example.com/file2.iso\n\n"), ) assert result.exit_code == 0 assert result.output == ( @@ -260,7 +263,7 @@ def test_add_package_exceptions( result = runner.invoke( cli, args=f"--username {TEST_USERNAME} --password {TEST_PASSWORD} --api-url {TEST_API_URL} add-package Test-Package", - input=("http://example.com/file1.zip\n" "http://example.com/file2.iso\n\n"), + input=("http://example.com/file1.zip\nhttp://example.com/file2.iso\n\n"), ) assert result.exit_code == 1 assert msg in result.output