Skip to content

Commit 7dac5f7

Browse files
committed
misc: test robustness
1 parent ff40647 commit 7dac5f7

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed

tests/__snapshots__/test_json_api-test_api-documents.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"account": "Expenses:Food",
44
"date": "2012-12-15",
5-
"filename": "TEST_DATA_DIR/import.csv",
5+
"filename": "/tmp/import.csv",
66
"links": [
77
"link1"
88
],
@@ -18,7 +18,7 @@
1818
{
1919
"account": "Expenses:Food",
2020
"date": "2012-12-15",
21-
"filename": "TEST_DATA_DIR/receipt.pdf",
21+
"filename": "/tmp/receipt.pdf",
2222
"links": [],
2323
"meta": {
2424
"filename": "TEST_DATA_DIR/example.beancount",

tests/__snapshots__/test_json_api-test_api_context-2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
},
1313
"t": "Open"
1414
},
15-
"sha256sum": "ENTRY_HASH260d384e80c9af182390e419d4a0bbc8",
15+
"sha256sum": "7198a732bba60e03bfebbf4368637a66260d384e80c9af182390e419d4a0bbc8",
1616
"slice": "1980-05-12 open Expenses:Food:Alcohol"
1717
}

tests/__snapshots__/test_json_api-test_api_context.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@
121121
"t": "Transaction",
122122
"tags": []
123123
},
124-
"sha256sum": "ENTRY_HASH045ed99d2af148ec815727c3b136906e",
124+
"sha256sum": "b8d184b8ffadddbdc915a9dbf7e4d94a045ed99d2af148ec815727c3b136906e",
125125
"slice": "2016-05-09 * \"Investing 40% of cash in VBMPX\"\n Assets:US:Vanguard:VBMPX 15.957 VBMPX {30.08 USD}\n Assets:US:Vanguard:Cash -479.99 USD"
126126
}

tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ def snapshot_data(
121121
today = local_today()
122122
out = out.replace(str(today), "TODAY")
123123
# replace entry hashes
124-
out = re.sub(r'"[0-9a-f]{32}', '"ENTRY_HASH', out)
125-
out = re.sub(r"context-[0-9a-f]{32}", "context-ENTRY_HASH", out)
124+
out = re.sub(r'_hash": "[0-9a-f]+', '_hash": "ENTRY_HASH', out)
125+
out = re.sub(r"context-[0-9a-f]+", "context-ENTRY_HASH", out)
126+
out = re.sub(
127+
r"data-entry=\\\"[0-9a-f]+", 'data-entry=\\"ENTRY_HASH', out
128+
)
126129
# replace mtimes
127130
out = re.sub(r"mtime=\d+", "mtime=MTIME", out)
128131
out = re.sub(r'id="ledger-mtime">\d+', 'id="ledger-mtime">MTIME', out)

tests/data/example.beancount

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ plugin "beancount.plugins.auto_accounts"
7575
test: TRUE
7676
account: Expenses:Food
7777

78-
2012-12-15 document Expenses:Food "import.csv" #tag ^link1
79-
2012-12-15 document Expenses:Food "receipt.pdf" #discovered
78+
2012-12-15 document Expenses:Food "/tmp/import.csv" #tag ^link1
79+
2012-12-15 document Expenses:Food "/tmp/receipt.pdf" #discovered
8080

8181
2014-01-01 close Assets:Account1

tests/data/off-by-one.beancount

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ option "operating_currency" "USD"
1111

1212
2022-01-01 * "Buy"
1313
Assets:Cash -100 USD
14-
Assets:Commodity 1 COM {{100 USD}}
14+
Assets:Commodity 1 COM {100 USD}
1515

1616
2022-01-01 price COM 101 USD
1717
2022-01-02 price COM 102 USD

tests/test_core_charts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ def test_net_worth_off_by_one(
7575
) -> None:
7676
off_by_one = get_ledger("off-by-one")
7777
off_by_one_filtered = off_by_one.get_filtered()
78+
assert not off_by_one.errors
79+
assert len(off_by_one_filtered.entries) == 9
7880

7981
for interval in [Interval.DAY, Interval.MONTH]:
8082
data = off_by_one.charts.net_worth(
8183
off_by_one_filtered,
8284
interval,
8385
"at_value",
8486
)
87+
assert len(data) == 4 if interval == Interval.DAY else 1
8588
snapshot(data, json=True)
8689

8790

tests/test_json_api.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import datetime
4+
import sys
45
from http import HTTPStatus
56
from io import BytesIO
67
from pathlib import Path
@@ -661,11 +662,29 @@ def test_api_filter_error(
661662
assert_api_error(response, status=HTTPStatus.BAD_REQUEST)
662663

663664

665+
@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
664666
@pytest.mark.parametrize(
665667
("name", "url"),
666668
[
667-
("commodities", "/long-example/api/commodities"),
668669
("documents", "/example/api/documents"),
670+
],
671+
)
672+
def test_api_unix_only(
673+
test_client: FlaskClient,
674+
snapshot: SnapshotFunc,
675+
name: str,
676+
url: str,
677+
) -> None:
678+
response = test_client.get(url)
679+
data = assert_api_success(response)
680+
assert data
681+
snapshot(data, name=name, json=True)
682+
683+
684+
@pytest.mark.parametrize(
685+
("name", "url"),
686+
[
687+
("commodities", "/long-example/api/commodities"),
669688
("events", "/long-example/api/events"),
670689
("income_statement", "/long-example/api/income_statement?time=2014"),
671690
("trial_balance", "/long-example/api/trial_balance?time=2014"),

0 commit comments

Comments
 (0)