mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 01:02:10 +03:00
Every run used to write all three files (en.md, ru.md, json) unconditionally.
Default is now English Markdown only, sourced from output.formats in
config.yaml; --format/--ru/--json pick exactly what a run writes, and any
explicit --format replaces the default rather than adding to it (all/none
supported). write_report() moved from a fixed 3-positional-arg signature to
a {format: text} mapping so writes are conditional instead of always-three.
The en/ru Markdown cross-link header is now only set when both languages are
actually being written.
85 lines
2.7 KiB
Python
85 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
import typer
|
|
|
|
from netsleuth.cli import format_siblings, parse_formats
|
|
|
|
DEFAULT = frozenset({"md"})
|
|
|
|
|
|
def test_no_flags_returns_the_default():
|
|
assert parse_formats([], ru=False, json_flag=False, default=DEFAULT) == DEFAULT
|
|
|
|
|
|
def test_json_shortcut_selects_json_only():
|
|
assert parse_formats([], ru=False, json_flag=True, default=DEFAULT) == frozenset({"json"})
|
|
|
|
|
|
def test_ru_shortcut_selects_ru_md_only():
|
|
assert parse_formats([], ru=True, json_flag=False, default=DEFAULT) == frozenset({"ru-md"})
|
|
|
|
|
|
def test_json_and_format_md_stack():
|
|
assert parse_formats(["md"], ru=False, json_flag=True, default=DEFAULT) == frozenset({"md", "json"})
|
|
|
|
|
|
def test_repeated_format_flags_union():
|
|
assert parse_formats(["md", "json"], ru=False, json_flag=False, default=DEFAULT) == frozenset(
|
|
{"md", "json"}
|
|
)
|
|
|
|
|
|
def test_comma_separated_single_flag():
|
|
assert parse_formats(["md,json"], ru=False, json_flag=False, default=DEFAULT) == frozenset(
|
|
{"md", "json"}
|
|
)
|
|
|
|
|
|
def test_all_expands_to_every_known_format():
|
|
assert parse_formats(["all"], ru=False, json_flag=False, default=DEFAULT) == frozenset(
|
|
{"md", "ru-md", "json"}
|
|
)
|
|
|
|
|
|
def test_none_alone_means_write_nothing():
|
|
assert parse_formats(["none"], ru=False, json_flag=False, default=DEFAULT) == frozenset()
|
|
|
|
|
|
def test_none_combined_with_another_format_is_an_error():
|
|
with pytest.raises(typer.BadParameter):
|
|
parse_formats(["none,md"], ru=False, json_flag=False, default=DEFAULT)
|
|
|
|
|
|
def test_unknown_format_is_an_error():
|
|
with pytest.raises(typer.BadParameter):
|
|
parse_formats(["pdf"], ru=False, json_flag=False, default=DEFAULT)
|
|
|
|
|
|
def test_case_and_whitespace_are_normalized():
|
|
assert parse_formats([" MD ", "JSON"], ru=False, json_flag=False, default=DEFAULT) == frozenset(
|
|
{"md", "json"}
|
|
)
|
|
|
|
|
|
def test_order_of_flags_never_changes_the_result():
|
|
a = parse_formats(["json", "md"], ru=False, json_flag=False, default=DEFAULT)
|
|
b = parse_formats(["md", "json"], ru=False, json_flag=False, default=DEFAULT)
|
|
assert a == b
|
|
|
|
|
|
def test_format_siblings_cross_link_when_both_languages_selected():
|
|
result = format_siblings(frozenset({"md", "ru-md"}), "report.md", "report.ru.md")
|
|
assert result == ("report.ru.md", "report.md")
|
|
|
|
|
|
def test_format_siblings_are_none_when_only_english_selected():
|
|
assert format_siblings(frozenset({"md"}), "report.md", "report.ru.md") == (None, None)
|
|
|
|
|
|
def test_format_siblings_are_none_when_only_russian_selected():
|
|
assert format_siblings(frozenset({"ru-md"}), "report.md", "report.ru.md") == (None, None)
|
|
|
|
|
|
def test_format_siblings_are_none_when_neither_markdown_selected():
|
|
assert format_siblings(frozenset({"json"}), "report.md", "report.ru.md") == (None, None)
|