Add --fmt-jsonnums option.

This commit is contained in:
Chris Berkhout 2022-04-04 17:01:09 +02:00
parent a3e19f9bcf
commit aabce7fe6f
6 changed files with 58 additions and 3 deletions

View file

@ -125,3 +125,44 @@ def test_format_custom(json_out, series, mocker):
).strip()
+ "\n"
)
def test_format_numbers(json_out, series, mocker):
source = mocker.MagicMock()
source.id = mocker.MagicMock(return_value="sourceid")
fmt = Format(jsonnums=True)
result = json_out.format(series, source, fmt)
assert (
result
== dedent(
"""
[
{
"date": "2021-01-01",
"base": "BTC",
"quote": "EUR",
"amount": 24139.4648,
"source": "sourceid",
"type": "close"
},
{
"date": "2021-01-02",
"base": "BTC",
"quote": "EUR",
"amount": 26533.576,
"source": "sourceid",
"type": "close"
},
{
"date": "2021-01-03",
"base": "BTC",
"quote": "EUR",
"amount": 27001.2846,
"source": "sourceid",
"type": "close"
}
]
"""
).strip()
+ "\n"
)

View file

@ -14,6 +14,7 @@ def test_fromargs():
"formatdatesep": None,
"formatcsvdelim": None,
"formatbase": None,
"formatjsonnums": None,
}
args = namedtuple("args", arg_values.keys())(**arg_values)
fmt = Format.fromargs(args)