clan-cli: write some unit tests
This commit is contained in:
17
pkgs/clan-cli/tests/test_clan_admin.py
Normal file
17
pkgs/clan-cli/tests/test_clan_admin.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import argparse
|
||||
|
||||
import clan_admin
|
||||
|
||||
|
||||
def test_make_parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
clan_admin.make_parser(parser)
|
||||
|
||||
# using fp fixture from pytest-subprocess
|
||||
def test_create(fp):
|
||||
cmd = ["nix", "flake", "init", "-t", fp.any()]
|
||||
fp.register(cmd)
|
||||
args = argparse.Namespace(folder="./my-clan")
|
||||
clan_admin.create(args)
|
||||
assert fp.call_count(cmd) == 1
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import sys
|
||||
|
||||
import my_tool
|
||||
import pytest
|
||||
|
||||
import clan
|
||||
|
||||
|
||||
def test_no_args(capsys):
|
||||
my_tool.my_cli()
|
||||
clan.clan()
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.startswith("usage:")
|
||||
|
||||
|
||||
def test_version(capsys, monkeypatch):
|
||||
monkeypatch.setattr(sys, "argv", ["", "--version"])
|
||||
my_tool.my_cli()
|
||||
def test_help(capsys, monkeypatch):
|
||||
monkeypatch.setattr(sys, "argv", ["", "--help"])
|
||||
with pytest.raises(SystemExit):
|
||||
clan.clan()
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.startswith("Version:")
|
||||
assert captured.out.startswith("usage:")
|
||||
|
||||
Reference in New Issue
Block a user