clan-cli: format

This commit is contained in:
DavHau
2023-07-25 15:43:45 +02:00
parent 2a31d785cf
commit 1183ac9618
2 changed files with 29 additions and 20 deletions

View File

@@ -36,8 +36,9 @@ def ssh(
subprocess.run(cmd) subprocess.run(cmd)
def qrcode_scan(pictureFile: str) -> dict: # pragma: no cover def qrcode_scan(pictureFile: str) -> str: # pragma: no cover
subprocess.Popen( return (
subprocess.run(
[ [
"nix", "nix",
"shell", "shell",
@@ -49,7 +50,11 @@ def qrcode_scan(pictureFile: str) -> dict: # pragma: no cover
pictureFile, pictureFile,
], ],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
).stdout.read() check=True,
)
.stdout.decode()
.strip()
)
def main(args: argparse.Namespace) -> None: # pragma: no cover 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"]) ssh(host=ssh_data["address"], password=ssh_data["password"])
def register_parser(parser: argparse.ArgumentParser) -> None: def register_parser(parser: argparse.ArgumentParser) -> None:
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument( group.add_argument(

View File

@@ -1,20 +1,18 @@
import argparse
import json
import tempfile
import pytest
import sys import sys
from typing import Union from typing import Union
import pytest
import pytest_subprocess.fake_process import pytest_subprocess.fake_process
from pytest_subprocess import utils from pytest_subprocess import utils
import clan_cli.ssh import clan_cli.ssh
def test_no_args( def test_no_args(
capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPatch
) -> None: ) -> None:
monkeypatch.setattr(sys, "argv", ["", "ssh"]) monkeypatch.setattr(sys, "argv", ["", "ssh"])
with pytest.raises(SystemExit) as pytest_wrapped_e: with pytest.raises(SystemExit):
clan_cli.main() clan_cli.main()
captured = capsys.readouterr() captured = capsys.readouterr()
assert captured.err.startswith("usage:") assert captured.err.startswith("usage:")
@@ -59,3 +57,10 @@ def test_ssh_with_pass(fp: pytest_subprocess.fake_process.FakeProcess) -> None:
password="XXX", password="XXX",
) )
assert fp.call_count(cmd) == 1 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"