import pytest from common_cents.money import ( format_cents, format_cents_input, parse_cents_csv, parse_dollars, ) @pytest.mark.parametrize( "raw, expected", [ ("1", 100), ("1.5", 150), ("1.50", 150), ("$1,234.56", 123456), (".50", 50), ("5.", 500), ("5.999", 599), # truncate, not round (string-based) ("1.005", 100), ("-5.00", -500), ("-.50", -50), ("", None), (" ", None), ("abc", None), ("$", None), ("-", None), ("-$5", None), ], ) def test_parse_dollars(raw, expected): assert parse_dollars(raw) == expected @pytest.mark.parametrize( "raw, expected", [ ("100", 100), ("14,901", 14901), (" 50 ", 50), ], ) def test_parse_cents_csv(raw, expected): assert parse_cents_csv(raw) == expected def test_parse_cents_csv_invalid(): with pytest.raises(ValueError): parse_cents_csv("abc") @pytest.mark.parametrize( "cents, expected", [ (0, "$0.00"), (100, "$1.00"), (1234, "$12.34"), (123456, "$1,234.56"), (-500, "-$5.00"), (-12345, "-$123.45"), ], ) def test_format_cents(cents, expected): assert format_cents(cents) == expected @pytest.mark.parametrize( "cents, expected", [ (100, "1.00"), (1234, "12.34"), (5, "0.05"), ], ) def test_format_cents_input(cents, expected): assert format_cents_input(cents) == expected