Skip to content

Commit

Permalink
Add stub of command snapshot
Browse files Browse the repository at this point in the history
In order to test the automatic release generation, some more reasons to increase the version number have to be found. Adding stubs of commands already planned to support is a good idea.

Thus, this change set provides a snapshot command and a test to ensure that this command is triggered if the program is called without arguments.
  • Loading branch information
MaxG87 committed Sep 12, 2023
2 parents a04f464 + 4e1e90d commit 9b5f88e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/root_subvol_snapshot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module provides the CLI to enter the program.
"""
import sys
import typing as t
from pathlib import Path

Expand All @@ -11,6 +12,13 @@
app = typer.Typer()


def main() -> None:
if len(sys.argv) == 1:
snapshot()
else:
app()


@app.command()
def open(device: t.Annotated[t.Optional[Path], typer.Argument()] = None) -> None:
typer.echo(f"Opening {device}...")
Expand All @@ -21,5 +29,10 @@ def close(device: t.Annotated[t.Optional[Path], typer.Argument()] = None) -> Non
typer.echo(f"Closing {device}...")


@app.command()
def snapshot(device: t.Annotated[t.Optional[Path], typer.Argument()] = None) -> None:
typer.echo("Making a snapshot of the root subvolume...")


if __name__ == "__main__":
app()
main()
Empty file.
17 changes: 16 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from root_subvol_snapshot.cli import app
import sys

from root_subvol_snapshot.cli import app, main
from typer.testing import CliRunner

runner = CliRunner()
Expand All @@ -10,6 +12,13 @@ def test_cli():
assert "Show this message and exit." in result.output


def test_cli_without_args_snapshots(capsys, monkeypatch):
monkeypatch.setattr(sys, "argv", [sys.argv[0]])
main()
captured = capsys.readouterr()
assert captured.out == "Making a snapshot of the root subvolume...\n"


def test_open():
result = runner.invoke(app, ["open"])
assert result.exit_code == 0
Expand All @@ -32,3 +41,9 @@ def test_close_with_argument(tmp_path):
result = runner.invoke(app, ["close", str(tmp_path)])
assert result.exit_code == 0
assert result.output.endswith(f"{tmp_path}...\n")


def test_snapshot():
result = runner.invoke(app, ["snapshot"])
assert result.exit_code == 0
assert result.output.startswith("Making a snapshot of the root subvolume...")

0 comments on commit 9b5f88e

Please sign in to comment.