Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nummus/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING

import colorama
from colorama import Fore

if TYPE_CHECKING:
Expand Down Expand Up @@ -40,6 +41,7 @@ def __init__(

"""
super().__init__()
colorama.init(autoreset=True)

path_db = path_db.expanduser().absolute()
if path_password:
Expand Down
4 changes: 2 additions & 2 deletions nummus/controllers/budgeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def target(uri: str) -> str | flask.Response:
new_target = tar is None
if tar is None:
# New target
tar = Target(
tar = Target( # nummus: ignore
category_id=t_cat_id,
amount=0,
type_=TargetType.ACCUMULATE,
Expand Down Expand Up @@ -635,7 +635,7 @@ def target(uri: str) -> str | flask.Response:
try:
if flask.request.method == "POST":
with s.begin_nested():
s.add(tar)
s.add(tar) # nummus: ignore
return base.dialog_swap(
event="budget",
snackbar=f"{emoji_name} target created",
Expand Down
4 changes: 2 additions & 2 deletions nummus/controllers/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,12 @@ def new() -> str | flask.Response:

try:
with s.begin_nested():
txn = Transaction(
txn = Transaction( # nummus: ignore
statement="Manually added",
)
if err := _transaction_edit(txn, today):
return base.error(err)
s.add(txn)
s.add(txn) # nummus: ignore
s.flush()
if err := _transaction_split_edit(txn):
return base.error(err)
Expand Down
2 changes: 1 addition & 1 deletion nummus/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def _import_asset_transaction(
payee=d["payee"],
cleared=True,
)
TransactionSplit(
TransactionSplit.create(
parent=txn,
amount=d["amount"],
memo=d["memo"],
Expand Down
2 changes: 1 addition & 1 deletion nummus/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def init_app(self, app: flask.Flask) -> None:
app: Flask app to initialize

"""
config = flask.Config(app.root_path)
config = flask.Config(app.root_path) # nummus: ignore
config.from_prefixed_env("NUMMUS")
self._portfolio = self._open_portfolio(config)

Expand Down
18 changes: 5 additions & 13 deletions tests/commands/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING

from colorama import Fore

from nummus.commands.backup import Backup, Restore

if TYPE_CHECKING:
Expand All @@ -22,10 +20,7 @@ def test_backup(capsys: pytest.CaptureFixture[str], empty_portfolio: Portfolio)
assert path_backup.exists()

captured = capsys.readouterr()
target = (
f"{Fore.GREEN}Portfolio is unlocked\n"
f"{Fore.GREEN}Portfolio backed up to {path_backup}\n"
)
target = f"Portfolio is unlocked\nPortfolio backed up to {path_backup}\n"
assert captured.out == target
assert not captured.err

Expand All @@ -39,10 +34,7 @@ def test_restore(
assert c.run() == 0

captured = capsys.readouterr()
target = (
f"{Fore.CYAN}Extracted backup tar\n"
f"{Fore.GREEN}Portfolio restored for {empty_portfolio.path}\n"
)
target = f"Extracted backup tar\nPortfolio restored for {empty_portfolio.path}\n"
assert captured.out == target
assert not captured.err

Expand All @@ -56,7 +48,7 @@ def test_restore_missing(

captured = capsys.readouterr()
assert not captured.out
target = f"{Fore.RED}No backup exists for {empty_portfolio.path}\n"
target = f"No backup exists for {empty_portfolio.path}\n"
assert captured.err == target


Expand All @@ -69,7 +61,7 @@ def test_restore_list_empty(

captured = capsys.readouterr()
assert not captured.out
target = f"{Fore.RED}No backups found, run 'nummus backup'\n"
target = "No backups found, run 'nummus backup'\n"
assert captured.err == target


Expand All @@ -85,6 +77,6 @@ def test_restore_list(
ts_local = utc_frozen.astimezone().isoformat(timespec="seconds")

captured = capsys.readouterr()
target = f"{Fore.CYAN}Backup # 1 created at {ts_local} (0.0 seconds ago)\n"
target = f"Backup # 1 created at {ts_local} (0.0 seconds ago)\n"
assert captured.out == target
assert not captured.err
26 changes: 11 additions & 15 deletions tests/commands/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import override, TYPE_CHECKING

import pytest
from colorama import Fore

from nummus.commands.backup import Backup, Restore
from nummus.commands.base import Command
Expand Down Expand Up @@ -50,15 +49,15 @@ def test_no_file(capsys: pytest.CaptureFixture[str], tmp_path: Path) -> None:

captured = capsys.readouterr()
assert not captured.out
target = f"{Fore.RED}Portfolio does not exist at {path}. Run nummus create\n"
target = f"Portfolio does not exist at {path}. Run nummus create\n"
assert captured.err == target


def test_unlock(capsys: pytest.CaptureFixture[str], empty_portfolio: Portfolio) -> None:
MockCommand(empty_portfolio.path, None)

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio is unlocked\n"
target = "Portfolio is unlocked\n"
assert captured.out == target
assert not captured.err

Expand All @@ -73,10 +72,7 @@ def test_migration_required(
captured = capsys.readouterr()
assert not captured.out
v = MIGRATORS[-1].min_version()
target = (
f"{Fore.RED}Portfolio requires migration to v{v}\n"
f"{Fore.YELLOW}Run 'nummus migrate' to resolve\n"
)
target = f"Portfolio requires migration to v{v}\nRun 'nummus migrate' to resolve\n"
assert captured.err == target


Expand All @@ -94,7 +90,7 @@ def test_unlock_encrypted_path(
MockCommand(p.path, path_password)

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio is unlocked\n"
target = "Portfolio is unlocked\n"
assert captured.out == target
assert not captured.err

Expand All @@ -115,7 +111,7 @@ def test_unlock_encrypted_path_bad_key(

captured = capsys.readouterr()
assert not captured.out
target = f"{Fore.RED}Could not decrypt with password file\n"
target = "Could not decrypt with password file\n"
assert captured.err == target


Expand All @@ -138,10 +134,10 @@ def mock_get_pass(to_print: str) -> str | None:
MockCommand(p.path, None)

captured = capsys.readouterr()
assert captured.out == f"{Fore.GREEN}Portfolio is unlocked\n"
assert captured.out == "Portfolio is unlocked\n"
target = (
"\u26bf Please enter password: \n"
f"{Fore.RED}Incorrect password\n"
"Incorrect password\n"
"\u26bf Please enter password: \n"
)
assert captured.err == target
Expand Down Expand Up @@ -193,12 +189,12 @@ def mock_get_pass(to_print: str) -> str | None:
assert not captured.out
target = (
"\u26bf Please enter password: \n"
f"{Fore.RED}Incorrect password\n"
"Incorrect password\n"
"\u26bf Please enter password: \n"
f"{Fore.RED}Incorrect password\n"
"Incorrect password\n"
"\u26bf Please enter password: \n"
f"{Fore.RED}Incorrect password\n"
f"{Fore.RED}Too many incorrect attempts\n"
"Incorrect password\n"
"Too many incorrect attempts\n"
)
assert captured.err == target

Expand Down
11 changes: 5 additions & 6 deletions tests/commands/test_change_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import override, TYPE_CHECKING

import pytest
from colorama import Fore

from nummus.commands.change_password import ChangePassword
from nummus.portfolio import Portfolio
Expand Down Expand Up @@ -37,8 +36,8 @@ def test_no_change_unencrypted(
assert c.run() != 0

captured = capsys.readouterr()
assert captured.out == f"{Fore.GREEN}Portfolio is unlocked\n"
assert captured.err == f"{Fore.YELLOW}Neither password changing\n"
assert captured.out == "Portfolio is unlocked\n"
assert captured.err == "Neither password changing\n"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -66,9 +65,9 @@ def test_change(

captured = capsys.readouterr()
target_out = (
f"{Fore.GREEN}Portfolio is unlocked\n"
f"{Fore.GREEN}Changed password(s)\n"
f"{Fore.CYAN}Run 'nummus clean' to remove backups with old password\n"
"Portfolio is unlocked\n"
"Changed password(s)\n"
"Run 'nummus clean' to remove backups with old password\n"
)
assert captured.out == target_out
assert captured.err == target
Expand Down
8 changes: 3 additions & 5 deletions tests/commands/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING

from colorama import Fore

from nummus.commands.clean import Clean

if TYPE_CHECKING:
Expand All @@ -21,9 +19,9 @@ def test_clean(capsys: pytest.CaptureFixture[str], empty_portfolio: Portfolio) -

captured = capsys.readouterr()
target = (
f"{Fore.GREEN}Portfolio is unlocked\n"
f"{Fore.GREEN}Portfolio cleaned\n"
f"{Fore.CYAN}Portfolio was optimized by 0.0KB/0.0KiB\n"
"Portfolio is unlocked\n"
"Portfolio cleaned\n"
"Portfolio was optimized by 0.0KB/0.0KiB\n"
)
assert captured.out == target
assert not captured.err
12 changes: 5 additions & 7 deletions tests/commands/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import sys
from typing import override, TYPE_CHECKING

from colorama import Fore

from nummus.commands.create import Create
from nummus.portfolio import Portfolio

Expand Down Expand Up @@ -39,7 +37,7 @@ def test_create_existing(

captured = capsys.readouterr()
assert not captured.out
target = f"{Fore.RED}Cannot overwrite portfolio at {path}. Try with --force\n"
target = f"Cannot overwrite portfolio at {path}. Try with --force\n"
assert captured.err == target


Expand All @@ -56,7 +54,7 @@ def test_create_unencrypted_forced(
assert c.run() == 0

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio created at {path}\n"
target = f"Portfolio created at {path}\n"
assert captured.out == target
target = f"Creating {path} with None\n"
assert captured.err == target
Expand All @@ -74,7 +72,7 @@ def test_create_unencrypted(
assert c.run() == 0

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio created at {path}\n"
target = f"Portfolio created at {path}\n"
assert captured.out == target
target = f"Creating {path} with None\n"
assert captured.err == target
Expand All @@ -101,7 +99,7 @@ def mock_get_pass(_: str) -> str | None:
assert c.run() == 0

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio created at {path}\n"
target = f"Portfolio created at {path}\n"
assert captured.out == target
target = f"Creating {path} with {rand_str}\n"
assert captured.err == target
Expand All @@ -123,7 +121,7 @@ def test_create_encrypted_pass_file(
assert c.run() == 0

captured = capsys.readouterr()
target = f"{Fore.GREEN}Portfolio created at {path}\n"
target = f"Portfolio created at {path}\n"
assert captured.out == target
target = f"Creating {path} with {rand_str}\n"
assert captured.err == target
Expand Down
12 changes: 2 additions & 10 deletions tests/commands/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from typing import TYPE_CHECKING

from colorama import Fore

from nummus.commands.export import Export
from nummus.models.currency import CURRENCY_FORMATS, DEFAULT_CURRENCY

Expand All @@ -28,10 +26,7 @@ def test_export_empty(
assert c.run() == 0

captured = capsys.readouterr()
target = (
f"{Fore.GREEN}Portfolio is unlocked\n"
f"{Fore.GREEN}0 transactions exported to {path_csv}\n"
)
target = f"Portfolio is unlocked\n0 transactions exported to {path_csv}\n"
assert captured.out == target
assert not captured.err

Expand All @@ -57,10 +52,7 @@ def test_export(
assert c.run() == 0

captured = capsys.readouterr()
target = (
f"{Fore.GREEN}Portfolio is unlocked\n"
f"{Fore.GREEN}1 transactions exported to {path_csv}\n"
)
target = f"Portfolio is unlocked\n1 transactions exported to {path_csv}\n"
assert captured.out == target
assert not captured.err

Expand Down
Loading