Option C Tools
Loading...
Searching...
No Matches
test_version_option.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_cli/test_version_option.py
4
5"""
6Purpose
7-------
8OI-524 regression tests — ``oct --version`` / ``-V`` must surface the OCT
9version, and ``oct --help`` must show the version at the top of its output.
10This closes the HIGH-priority developer note in V5.0 Phase 2 requiring the
11version to be visible without a dedicated command.
12
13Responsibilities
14----------------
15- ``oct --version`` prints ``oct <version>`` and exits 0.
16- ``-V`` shortcut behaves identically.
17- ``oct --help`` output begins with the version line.
18- ``__version__`` resolves to a non-empty, non-"unknown" value in the
19 installed editable environment.
20
21Diagnostics
22-----------
23Domain: CLI-TESTS
24Levels:
25 L2 — test lifecycle
26 L3 — assertion details
27 L4 — deep tracing
28
29Contracts
30---------
31- Must never regress: any future change to ``OctGroup.format_help`` or the
32 ``@click.version_option`` decorator must keep the version on the first
33 non-empty line of ``--help``.
34"""
35
36from click.testing import CliRunner
37
38from oct import __version__
39from oct.cli import cli
40
41
43 runner = CliRunner()
44 result = runner.invoke(cli, ["--version"])
45 assert result.exit_code == 0
46 assert f"oct {__version__}" in result.output
47
48
50 runner = CliRunner()
51 result = runner.invoke(cli, ["-V"])
52 assert result.exit_code == 0
53 assert f"oct {__version__}" in result.output
54
55
57 runner = CliRunner()
58 result = runner.invoke(cli, ["--help"])
59 assert result.exit_code == 0
60 first_line = result.output.splitlines()[0].strip()
61 assert first_line == f"oct {__version__}", (
62 f"expected version on first line of --help, got: {first_line!r}"
63 )
64
65
67 assert __version__, "__version__ must be non-empty"
68 assert __version__ != "unknown", (
69 "importlib.metadata could not resolve oct version — "
70 "package likely not installed in editable mode"
71 )
Definition cli.py:1