From 1183ac96182f04d74d155da22853c635ad0990db Mon Sep 17 00:00:00 2001 From: DavHau Date: Tue, 25 Jul 2023 15:43:45 +0200 Subject: [PATCH] clan-cli: format --- pkgs/clan-cli/clan_cli/ssh.py | 34 ++++++++++++++++------------ pkgs/clan-cli/tests/test_clan_ssh.py | 15 ++++++++---- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/ssh.py b/pkgs/clan-cli/clan_cli/ssh.py index 797dc42e0..65e896f26 100644 --- a/pkgs/clan-cli/clan_cli/ssh.py +++ b/pkgs/clan-cli/clan_cli/ssh.py @@ -36,20 +36,25 @@ def ssh( subprocess.run(cmd) -def qrcode_scan(pictureFile: str) -> dict: # pragma: no cover - subprocess.Popen( - [ - "nix", - "shell", - "nixpkgs#zbar", - "-c", - "zbarimg", - "--quiet", - "--raw", - pictureFile, - ], - stdout=subprocess.PIPE, - ).stdout.read() +def qrcode_scan(pictureFile: str) -> str: # pragma: no cover + return ( + subprocess.run( + [ + "nix", + "shell", + "nixpkgs#zbar", + "-c", + "zbarimg", + "--quiet", + "--raw", + pictureFile, + ], + stdout=subprocess.PIPE, + check=True, + ) + .stdout.decode() + .strip() + ) def main(args: argparse.Namespace) -> None: # pragma: no cover @@ -62,7 +67,6 @@ def main(args: argparse.Namespace) -> None: # pragma: no cover ssh(host=ssh_data["address"], password=ssh_data["password"]) - def register_parser(parser: argparse.ArgumentParser) -> None: group = parser.add_mutually_exclusive_group(required=True) group.add_argument( diff --git a/pkgs/clan-cli/tests/test_clan_ssh.py b/pkgs/clan-cli/tests/test_clan_ssh.py index 7465c2e95..77dcc4e91 100644 --- a/pkgs/clan-cli/tests/test_clan_ssh.py +++ b/pkgs/clan-cli/tests/test_clan_ssh.py @@ -1,20 +1,18 @@ -import argparse -import json -import tempfile -import pytest import sys from typing import Union +import pytest import pytest_subprocess.fake_process from pytest_subprocess import utils import clan_cli.ssh + def test_no_args( capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch ) -> None: monkeypatch.setattr(sys, "argv", ["", "ssh"]) - with pytest.raises(SystemExit) as pytest_wrapped_e: + with pytest.raises(SystemExit): clan_cli.main() captured = capsys.readouterr() assert captured.err.startswith("usage:") @@ -59,3 +57,10 @@ def test_ssh_with_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None: password="XXX", ) assert fp.call_count(cmd) == 1 + + +def test_qrcode_scan(fp: pytest_subprocess.fake_process.FakeProcess) -> None: + cmd: list[Union[str, utils.Any]] = [fp.any()] + fp.register(cmd, stdout="https://test.test") + result = clan_cli.ssh.qrcode_scan("test.png") + assert result == "https://test.test"