|
1 | 1 | """Tests for to_context() implementations on DataObject classes.""" |
| 2 | +import datetime |
2 | 3 | from decimal import Decimal |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
6 | | -from edgar.display.formatting import format_currency_short |
| 7 | +from edgar.display.formatting import datefmt, format_currency_short |
7 | 8 |
|
8 | 9 |
|
9 | 10 | class TestFormatCurrencyShort: |
@@ -60,6 +61,31 @@ def test_just_under_billion_promotes_negative(self): |
60 | 61 | assert format_currency_short(-999_950_000) == "-$1.0B" |
61 | 62 |
|
62 | 63 |
|
| 64 | +class TestDatefmt: |
| 65 | + """Unit tests for the shared date formatting helper.""" |
| 66 | + |
| 67 | + def test_compact_yyyymmdd(self): |
| 68 | + assert datefmt("20220304", "%B %d, %Y") == "March 04, 2022" |
| 69 | + |
| 70 | + def test_iso_date(self): |
| 71 | + assert datefmt("2022-03-04", "%B %d, %Y") == "March 04, 2022" |
| 72 | + |
| 73 | + def test_compact_datetime(self): |
| 74 | + assert datefmt("20220304120000", "%Y-%m-%d") == "2022-03-04" |
| 75 | + |
| 76 | + def test_datetime_object(self): |
| 77 | + assert datefmt(datetime.datetime(2022, 3, 4), "%B %d, %Y") == "March 04, 2022" |
| 78 | + |
| 79 | + @pytest.mark.parametrize( |
| 80 | + "value", |
| 81 | + ["2022/03/04", "2022-3-4", "March 4, 2022", "N/A", ""], |
| 82 | + ) |
| 83 | + def test_unrecognized_string_passes_through(self, value): |
| 84 | + # Strings that match none of the known patterns must be returned |
| 85 | + # unchanged instead of raising ``AttributeError`` on ``str.strftime``. |
| 86 | + assert datefmt(value, "%B %d, %Y") == value |
| 87 | + |
| 88 | + |
63 | 89 | class TestTenKToContext: |
64 | 90 | """Tests for TenK.to_context() using a known filing.""" |
65 | 91 |
|
|
0 commit comments