Download tests/test_documents.py from ZipLime/fomc-events: direct link, hf CLI and curl.
- Browser
- Download file 3.06 kB
-
https://huggingface.co/datasets/ZipLime/fomc-events/resolve/main/tests/test_documents.py
- Command line
-
hf download hf://datasets/ZipLime/fomc-events/tests/test_documents.py
-
curl -L -o test_documents.py https://huggingface.co/datasets/ZipLime/fomc-events/resolve/main/tests/test_documents.py
3.06 kB
| """Stripping the site around a Federal Reserve page, and reading its tables.""" | |
| from __future__ import annotations | |
| from datetime import date | |
| from recipe.documents import html_tables | |
| from recipe.sources.article import balanced, read, to_text | |
| from recipe.sources.implementation import parse_implementation_note | |
| def test_the_share_widget_is_removed_and_the_article_is_not(load_fixture): | |
| page = read(load_fixture("statements/2022-06-15_embargo_line.htm.gz")) | |
| assert "Share" not in page.text | |
| assert "Twitter" not in page.text | |
| # The first paragraph of the statement, not the third: an earlier version | |
| # of the embargo-line pattern consumed everything up to the first closing | |
| # `</p>` it could find, which on this page was two paragraphs in. | |
| assert page.text.startswith("Overall economic activity appears to have picked up") | |
| assert "The invasion of Ukraine" in page.text | |
| assert "Implementation Note issued June 15, 2022" in page.text | |
| def test_the_stamps_above_the_headline_are_read(load_fixture): | |
| page = read(load_fixture("statements/2022-06-15_embargo_line.htm.gz")) | |
| assert page.posted_on == date(2022, 6, 15) | |
| assert page.title == "Federal Reserve issues FOMC statement" | |
| assert page.release_line == "For release at 2:00 p.m. EDT" | |
| def test_a_page_with_no_article_marker_still_reads(load_fixture): | |
| """Implementation notes have no `id="article"`, only the date stamp.""" | |
| page = read(load_fixture("notes/2022-06-15_implementation.htm.gz")) | |
| assert page.posted_on == date(2022, 6, 15) | |
| assert page.text.startswith("Decisions Regarding Monetary Policy Implementation") | |
| assert "footer" not in page.text.lower() | |
| def test_the_administered_rates_come_from_their_own_sentences(load_fixture): | |
| note = parse_implementation_note(load_fixture("notes/2022-06-15_implementation.htm.gz")) | |
| assert note.iorb_rate == 1.65 | |
| assert note.on_rrp_rate == 1.55 | |
| assert note.primary_credit_rate == 1.75 | |
| assert note.effective_date == date(2022, 6, 16) | |
| # The note states no time of its own, so it does not get one. | |
| assert note.knowledge_time_precision == "date" | |
| def test_minutes_carry_no_embargo_line_at_all(load_fixture): | |
| page = read(load_fixture("minutes/2026-06-17_minutes.htm.gz")) | |
| assert page.release_line is None | |
| assert len(page.text.split()) > 3000 | |
| def test_balanced_finds_the_matching_close_tag(): | |
| html = "<ul><li><ul><li>x</li></ul></li></ul>after" | |
| assert html[balanced(html, 0):] == "after" | |
| def test_to_text_keeps_paragraph_order(): | |
| html = "<p>first</p><p>second</p><p>third</p>" | |
| assert to_text(html).split("\n") == ["first", "second", "third"] | |
| def test_row_and_column_spans_are_expanded(load_fixture): | |
| """A projections header spans four columns per statistic.""" | |
| table = html_tables(load_fixture("projections/2026-06-17_en_dash_intervals.htm.gz"))[0] | |
| labels = table.column_labels() | |
| assert labels[0] == "Variable" | |
| assert labels[1].startswith("Median") | |
| assert labels[1].endswith("2026") | |
| assert len(labels) == 13 | |