def test_get_entry_slice(example_ledger): entry = example_ledger.get_entry('d4a067d229bfda57c8c984d1615da699') assert get_entry_slice(entry) == ( """2016-05-03 * "Chichipotle" "Eating out with Joe" Liabilities:US:Chase:Slate -21.70 USD Expenses:Food:Restaurant 21.70 USD""", 'd60da810c0c7b8a57ae16be409c5e17a640a837c1ac29719ebe9f43930463477')
def context( self, entry_hash: str ) -> tuple[Directive, dict[str, list[str]] | None, dict[str, list[str]] | None, str, str, ]: """Context for an entry. Arguments: entry_hash: Hash of entry. Returns: A tuple ``(entry, before, after, source_slice, sha256sum)`` of the (unique) entry with the given ``entry_hash``. If the entry is a Balance or Transaction then ``before`` and ``after`` contain the balances before and after the entry of the affected accounts. """ entry = self.get_entry(entry_hash) source_slice, sha256sum = get_entry_slice(entry) if not isinstance(entry, (Balance, Transaction)): return entry, None, None, source_slice, sha256sum balances = compute_entry_context(self.all_entries, entry) before = { acc: [pos.to_string() for pos in sorted(inv)] for acc, inv in balances[0].items() } after = { acc: [pos.to_string() for pos in sorted(inv)] for acc, inv in balances[1].items() } return entry, before, after, source_slice, sha256sum
def test_get_entry_slice(example_ledger: FavaLedger) -> None: entry = _get_entry(example_ledger, "Chichipotle", "2016-05-03") assert get_entry_slice(entry) == ( """2016-05-03 * "Chichipotle" "Eating out with Joe" Liabilities:US:Chase:Slate -21.70 USD Expenses:Food:Restaurant 21.70 USD""", "d60da810c0c7b8a57ae16be409c5e17a640a837c1ac29719ebe9f43930463477", )
def test_save_entry_slice(example_ledger): entry = example_ledger.get_entry("d4a067d229bfda57c8c984d1615da699") entry_source, sha256sum = get_entry_slice(entry) new_source = """2016-05-03 * "Chichipotle" "Eating out with Joe" Expenses:Food:Restaurant 21.70 USD""" filename = entry.meta["filename"] contents = open(filename, encoding="utf-8").read() with pytest.raises(FavaAPIException): save_entry_slice(entry, new_source, "wrong hash") assert open(filename, encoding="utf-8").read() == contents new_sha256sum = save_entry_slice(entry, new_source, sha256sum) assert open(filename, encoding="utf-8").read() != contents sha256sum = save_entry_slice(entry, entry_source, new_sha256sum) assert open(filename, encoding="utf-8").read() == contents
def test_save_entry_slice(example_ledger): entry = example_ledger.get_entry('d4a067d229bfda57c8c984d1615da699') entry_source, sha256sum = get_entry_slice(entry) new_source = """2016-05-03 * "Chichipotle" "Eating out with Joe" Expenses:Food:Restaurant 21.70 USD""" filename = entry.meta['filename'] contents = open(filename).read() with pytest.raises(FavaAPIException): save_entry_slice(entry, new_source, 'wrong hash') assert open(filename).read() == contents new_sha256sum = save_entry_slice(entry, new_source, sha256sum) assert open(filename).read() != contents sha256sum = save_entry_slice(entry, entry_source, new_sha256sum) assert open(filename).read() == contents
def test_save_entry_slice(example_ledger) -> None: entry = _get_entry(example_ledger, "Chichipotle", "2016-05-03") entry_source, sha256sum = get_entry_slice(entry) new_source = """2016-05-03 * "Chichipotle" "Eating out with Joe" Expenses:Food:Restaurant 21.70 USD""" filename = Path(entry.meta["filename"]) contents = filename.read_text("utf-8") with pytest.raises(FavaAPIException): save_entry_slice(entry, new_source, "wrong hash") assert filename.read_text("utf-8") == contents new_sha256sum = save_entry_slice(entry, new_source, sha256sum) assert filename.read_text("utf-8") != contents sha256sum = save_entry_slice(entry, entry_source, new_sha256sum) assert filename.read_text("utf-8") == contents
def context(self, entry_hash: str) -> Tuple[Directive, Any, str, str]: """Context for an entry. Arguments: entry_hash: Hash of entry. Returns: A tuple ``(entry, balances, source_slice, sha256sum)`` of the (unique) entry with the given ``entry_hash``. If the entry is a Balance or Transaction then ``balances`` is a 2-tuple containing the balances before and after the entry of the affected accounts. """ entry = self.get_entry(entry_hash) balances = None if isinstance(entry, (Balance, Transaction)): balances = compute_entry_context(self.all_entries, entry) source_slice, sha256sum = get_entry_slice(entry) return entry, balances, source_slice, sha256sum
def context(self, entry_hash): """Context for an entry. Arguments: entry_hash: Hash of entry. Returns: A tuple ``(entry, balances, source_slice, sha256sum)`` of the (unique) entry with the given ``entry_hash``. If the entry is a Balance or Transaction then ``balances`` is a 2-tuple containing the balances before and after the entry of the affected accounts. """ entry = self.get_entry(entry_hash) balances = None if isinstance(entry, (Balance, Transaction)): balances = interpolate.compute_entry_context( self.all_entries, entry) source_slice, sha256sum = get_entry_slice(entry) return entry, balances, source_slice, sha256sum