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
"""
6
Purpose
7
-------
8
OI-524 regression tests — ``oct --version`` / ``-V`` must surface the OCT
9
version, and ``oct --help`` must show the version at the top of its output.
10
This closes the HIGH-priority developer note in V5.0 Phase 2 requiring the
11
version to be visible without a dedicated command.
12
13
Responsibilities
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
21
Diagnostics
22
-----------
23
Domain: CLI-TESTS
24
Levels:
25
L2 — test lifecycle
26
L3 — assertion details
27
L4 — deep tracing
28
29
Contracts
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
36
from
click.testing
import
CliRunner
37
38
from
oct
import
__version__
39
from
oct.cli
import
cli
40
41
42
def
test_version_long_flag_prints_version
():
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
49
def
test_version_short_flag_prints_version
():
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
56
def
test_help_output_starts_with_version
():
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
66
def
test_version_is_resolved_from_metadata
():
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
)
oct.cli
Definition
cli.py:1
test_version_option.test_version_short_flag_prints_version
test_version_short_flag_prints_version()
Definition
test_version_option.py:49
test_version_option.test_version_is_resolved_from_metadata
test_version_is_resolved_from_metadata()
Definition
test_version_option.py:66
test_version_option.test_help_output_starts_with_version
test_help_output_starts_with_version()
Definition
test_version_option.py:56
test_version_option.test_version_long_flag_prints_version
test_version_long_flag_prints_version()
Definition
test_version_option.py:42
tests
tests_cli
test_version_option.py
Generated by
1.15.0