Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
- more direct logic for calling load_file on modules in ledger
- reset data in test to avoid modifying ledger used in other tests
  • Loading branch information
yagebu committed Feb 9, 2024
1 parent 89ba9bd commit 0646e9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/fava/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pathlib import Path
from typing import Iterable
from typing import TYPE_CHECKING
from typing import TypeVar

from beancount.core.data import iter_entry_dates
from beancount.core.inventory import Inventory
Expand Down Expand Up @@ -67,23 +66,6 @@
from fava.util.date import Interval


MODULES = [
"accounts",
"attributes",
"budgets",
"charts",
"commodities",
"extensions",
"file",
"format_decimal",
"misc",
"query_shell",
"ingest",
]

T = TypeVar("T")


class FilteredLedger:
"""Filtered Beancount ledger."""

Expand Down Expand Up @@ -314,8 +296,18 @@ def load_file(self) -> None:
if not self._is_encrypted:
self._watcher.update(*self.paths_to_watch())

for mod in MODULES:
getattr(self, mod).load_file()
# Call load_file of all modules.
self.accounts.load_file()
self.attributes.load_file()
self.budgets.load_file()
self.charts.load_file()
self.commodities.load_file()
self.extensions.load_file()
self.file.load_file()
self.format_decimal.load_file()
self.misc.load_file()
self.query_shell.load_file()
self.ingest.load_file()

self.extensions.after_load_file()

Expand Down
3 changes: 3 additions & 0 deletions tests/test_core_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_format_decimal_locale(
monkeypatch: pytest.MonkeyPatch,
) -> None:
fmt = example_ledger.format_decimal
assert fmt(Decimal("1111111.333"), "USD") == "1111111.33"

monkeypatch.setattr(example_ledger.fava_options, "locale", "en_IN")
fmt.load_file()
Expand All @@ -64,4 +65,6 @@ def test_format_decimal_locale(
fmt.load_file()
assert fmt(Decimal("1111111.333"), "USD") == "1.111.111,33"

monkeypatch.undo()
fmt.load_file()
assert fmt(Decimal("1111111.333"), "USD") == "1111111.33"

0 comments on commit 0646e9f

Please sign in to comment.