[BUGFIX] Properly align summary numbers (#517)
This commit is contained in:
parent
ce877a32f9
commit
d46829b4ab
2 changed files with 37 additions and 6 deletions
|
|
@ -218,11 +218,13 @@ def _red(value: str) -> str:
|
|||
return Fore.RED + value + Fore.RESET
|
||||
|
||||
|
||||
def _no_color(value: str) -> str:
|
||||
return Fore.RESET + value + Fore.RESET
|
||||
|
||||
|
||||
def _str_int(value: int) -> str:
|
||||
if value > 0:
|
||||
return f"+{value}"
|
||||
if value < 0:
|
||||
return f"-{value}"
|
||||
return str(value)
|
||||
|
||||
|
||||
|
|
@ -232,7 +234,7 @@ def _color_int(value: int) -> str:
|
|||
return _green(str_int)
|
||||
if value < 0:
|
||||
return _red(str_int)
|
||||
return str_int
|
||||
return _no_color(str_int)
|
||||
|
||||
|
||||
def _output_summary(transaction_logs: List[Tuple[Subscription, FileHandlerTransactionLog]]):
|
||||
|
|
@ -249,13 +251,13 @@ def _output_summary(transaction_logs: List[Tuple[Subscription, FileHandlerTransa
|
|||
for subscription, _ in transaction_logs:
|
||||
width_sub_name = max(width_sub_name, len(subscription.name))
|
||||
width_num_entries_added = max(
|
||||
width_num_entries_added, len(_str_int(subscription.num_entries_added))
|
||||
width_num_entries_added, len(_color_int(subscription.num_entries_added))
|
||||
)
|
||||
width_num_entries_modified = max(
|
||||
width_num_entries_modified, len(_str_int(subscription.num_entries_modified))
|
||||
width_num_entries_modified, len(_color_int(subscription.num_entries_modified))
|
||||
)
|
||||
width_num_entries_removed = max(
|
||||
width_num_entries_removed, len(_str_int(subscription.num_entries_removed * -1))
|
||||
width_num_entries_removed, len(_color_int(subscription.num_entries_removed * -1))
|
||||
)
|
||||
width_num_entries = max(width_num_entries, len(str(subscription.num_entries)))
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import tempfile
|
|||
import time
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import patch
|
||||
|
||||
import mergedeep
|
||||
|
|
@ -14,6 +18,7 @@ import pytest
|
|||
from conftest import assert_logs
|
||||
|
||||
from ytdl_sub.cli.main import _download_subscriptions_from_yaml_files
|
||||
from ytdl_sub.cli.main import _output_summary
|
||||
from ytdl_sub.cli.main import logger as main_logger
|
||||
from ytdl_sub.cli.main import main
|
||||
from ytdl_sub.config.config_file import ConfigFile
|
||||
|
|
@ -246,3 +251,27 @@ def test_transaction_log_to_logger(
|
|||
):
|
||||
transaction_logs = main()
|
||||
assert transaction_logs
|
||||
|
||||
|
||||
def test_output_summary():
|
||||
subscription_values: List[Tuple[str, int, int, int, int]] = [
|
||||
("long_name_but_lil_values", 0, 0, 0, 6),
|
||||
("john_smith", 1, 0, 0, 52),
|
||||
("david_gore", 0, 0, 0, 4),
|
||||
("christopher_snoop", 50, 0, 3, 518),
|
||||
("beyond funk", 0, 0, 0, 176),
|
||||
]
|
||||
|
||||
mock_subscriptions: List[Tuple[MagicMock, FileHandlerTransactionLog]] = []
|
||||
for values in subscription_values:
|
||||
sub = Mock()
|
||||
sub.name = values[0]
|
||||
sub.num_entries_added = values[1]
|
||||
sub.num_entries_modified = values[2]
|
||||
sub.num_entries_removed = values[3]
|
||||
sub.num_entries = values[4]
|
||||
|
||||
mock_subscriptions.append((sub, FileHandlerTransactionLog()))
|
||||
|
||||
_ = _output_summary(transaction_logs=mock_subscriptions)
|
||||
assert True # Test used for manual inspection - too hard to test ansi color codes
|
||||
|
|
|
|||
Loading…
Reference in a new issue