"""CLI parsing tests — argv → (subcommand, Args).""" from __future__ import annotations import pytest from cloud_sync.cli import Args, parse def test_parses_pull_with_required_url() -> None: cmd, args = parse(["pull", "--url=https://cloud.tm.center"]) assert cmd == "pull" assert isinstance(args, Args) assert args.url == "https://cloud.tm.center" assert args.allow_download is True assert args.headless is False def test_default_token_file_under_pack_folder() -> None: _, args = parse(["pull", "--url=https://x", "--pack-folder=/tmp/inst"]) assert args.token_file.as_posix().endswith(".cloud-sync/token") assert "/tmp/inst" in args.token_file.as_posix() def test_custom_token_file_overrides_default() -> None: _, args = parse( ["pull", "--url=https://x", "--pack-folder=/tmp/inst", "--token-file=/etc/cloud-creds"] ) assert args.token_file.as_posix() == "/etc/cloud-creds" def test_inline_and_space_separated_both_work() -> None: _, a1 = parse(["pull", "--url=https://x", "--pack-folder=/srv"]) _, a2 = parse(["pull", "--url", "https://x", "--pack-folder", "/srv"]) assert a1.url == a2.url assert a1.pack_folder == a2.pack_folder def test_no_gui_flag() -> None: _, a = parse(["push", "--url=https://x", "-g"]) assert a.headless is True _, b = parse(["push", "--url=https://x", "--no-gui"]) assert b.headless is True def test_no_download_flag() -> None: _, a = parse(["push", "--url=https://x", "--no-download"]) assert a.allow_download is False def test_restic_binary_override() -> None: _, a = parse(["push", "--url=https://x", "--restic-binary=/opt/restic"]) assert a.restic_binary is not None assert a.restic_binary.as_posix() == "/opt/restic" def test_missing_url_exits() -> None: with pytest.raises(SystemExit): parse(["pull"]) def test_missing_subcommand_exits() -> None: with pytest.raises(SystemExit): parse([]) def test_unknown_subcommand_exits() -> None: with pytest.raises(SystemExit): parse(["bogus", "--url=https://x"]) def test_pack_folder_is_resolved_to_absolute() -> None: _, a = parse(["pull", "--url=https://x", "--pack-folder=."]) assert a.pack_folder.is_absolute()