diff options
| author | Max Nanis | 2026-03-06 16:49:46 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-03-06 16:49:46 -0500 |
| commit | 91d040211a4ed6e4157896256a762d3854777b5e (patch) | |
| tree | cd95922ea4257dc8d3f4e4cbe8534474709a20dc /tests/models/thl/test_payout_format.py | |
| download | generalresearch-91d040211a4ed6e4157896256a762d3854777b5e.tar.gz generalresearch-91d040211a4ed6e4157896256a762d3854777b5e.zip | |
Initial commitv3.3.4
Diffstat (limited to 'tests/models/thl/test_payout_format.py')
| -rw-r--r-- | tests/models/thl/test_payout_format.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/models/thl/test_payout_format.py b/tests/models/thl/test_payout_format.py new file mode 100644 index 0000000..dc91f39 --- /dev/null +++ b/tests/models/thl/test_payout_format.py @@ -0,0 +1,46 @@ +import pytest +from pydantic import BaseModel + +from generalresearch.models.thl.payout_format import ( + PayoutFormatType, + PayoutFormatField, + format_payout_format, +) + + +class PayoutFormatTestClass(BaseModel): + payout_format: PayoutFormatType = PayoutFormatField + + +class TestPayoutFormat: + def test_payout_format_cls(self): + # valid + PayoutFormatTestClass(payout_format="{payout*10:,.0f} Points") + PayoutFormatTestClass(payout_format="{payout:.0f}") + PayoutFormatTestClass(payout_format="${payout/100:.2f}") + + # invalid + with pytest.raises(expected_exception=Exception) as e: + PayoutFormatTestClass(payout_format="{payout10:,.0f} Points") + + with pytest.raises(expected_exception=Exception) as e: + PayoutFormatTestClass(payout_format="payout:,.0f} Points") + + with pytest.raises(expected_exception=Exception): + PayoutFormatTestClass(payout_format="payout") + + with pytest.raises(expected_exception=Exception): + PayoutFormatTestClass(payout_format="{payout;import sys:.0f}") + + def test_payout_format(self): + assert "1,230 Points" == format_payout_format( + payout_format="{payout*10:,.0f} Points", payout_int=123 + ) + + assert "123" == format_payout_format( + payout_format="{payout:.0f}", payout_int=123 + ) + + assert "$1.23" == format_payout_format( + payout_format="${payout/100:.2f}", payout_int=123 + ) |
