diff --git a/tests/fixtures/full_index/1993/QTR1/form.gz b/tests/fixtures/full_index/1993/QTR1/form.gz new file mode 100644 index 000000000..1a467124d Binary files /dev/null and b/tests/fixtures/full_index/1993/QTR1/form.gz differ diff --git a/tests/fixtures/full_index/1993/QTR2/form.gz b/tests/fixtures/full_index/1993/QTR2/form.gz new file mode 100644 index 000000000..08da45986 Binary files /dev/null and b/tests/fixtures/full_index/1993/QTR2/form.gz differ diff --git a/tests/fixtures/full_index/1993/QTR3/form.gz b/tests/fixtures/full_index/1993/QTR3/form.gz new file mode 100644 index 000000000..cbf85ebf3 Binary files /dev/null and b/tests/fixtures/full_index/1993/QTR3/form.gz differ diff --git a/tests/fixtures/full_index/1994/QTR1/form.gz b/tests/fixtures/full_index/1994/QTR1/form.gz new file mode 100644 index 000000000..b9e3eb975 Binary files /dev/null and b/tests/fixtures/full_index/1994/QTR1/form.gz differ diff --git a/tests/fixtures/full_index/1994/QTR2/form.gz b/tests/fixtures/full_index/1994/QTR2/form.gz new file mode 100644 index 000000000..03a201e85 Binary files /dev/null and b/tests/fixtures/full_index/1994/QTR2/form.gz differ diff --git a/tests/fixtures/full_index/README.md b/tests/fixtures/full_index/README.md new file mode 100644 index 000000000..b1a04b986 --- /dev/null +++ b/tests/fixtures/full_index/README.md @@ -0,0 +1,30 @@ +# SEC quarterly full-index fixtures + +Verbatim quarterly form indexes from SEC EDGAR, laid out under the same path SEC serves +them from: `/QTR/form.gz` here is +`https://www.sec.gov/Archives/edgar/full-index//QTR/form.gz`. Each file was +downloaded on 2026-11-23, decompressed, and recompressed at level 9 with mtime 0 (`gzip.compress(data, 9, mtime=0)`), so +the bytes are reproducible. Gzip is lossless: decompressing a file gives back exactly the +index SEC served. Never edit a file here. To replace one, download it again from SEC and +recompress it, then check its SHA-256 against the table. + +These quarters predate 1994 Q3, the old hardcoded start of `available_quarters()`. EFTS +only indexes 2001 onward, so `get_by_accession_number()` resolves a filing from these +quarters by scanning the quarterly index, and the tests serve that scan from here. + +Used by `tests/issues/regression/test_issue_g00j_pre_1994q3_quarters.py`. + +| Index | Gzipped bytes | Decompressed bytes | SHA-256 of decompressed content | +|---|---|---|---| +| `1993/QTR1/form.gz` | 436 | 1,081 | `6f1734583bf47d6da38bc6f56061b1aaef901c678530875cd46c2cd085128059` | +| `1993/QTR2/form.gz` | 398 | 1,080 | `7dc68eea3b80ebdf064f7d32293ce87b0ba0fd81b72406edf114d4bfb51969c6` | +| `1993/QTR3/form.gz` | 585 | 1,553 | `52cfb80882b14158189d43b119fdffede003642046940d51bcdf074582de1ade` | +| `1994/QTR1/form.gz` | 361,376 | 3,257,581 | `0b943c3539aa949a50be422d705b1d1f7ffe3bb01303fdb0ae8b9dd5f6fe28cb` | +| `1994/QTR2/form.gz` | 310,801 | 2,574,456 | `09ebf81661a775a9eafd8766ea91835537a6780683d21fb4ade3c28400398388` | + +The filings the tests resolve: + +| Accession | Company | Form | Filed | Index | +|---|---|---|---|---| +| `0000003673-94-000052` | ALLEGHENY POWER SYSTEM INC | 35-CERT | 1994-06-30 | `1994/QTR2` | +| `0000873611-93-000002` | MERRILL LYNCH FL MUN BOND FD OF MERRILL LYNCH MUL ST MUN SER | 24F-2NT | 1993-09-28 | `1993/QTR3` | diff --git a/tests/issues/regression/test_issue_g00j_pre_1994q3_quarters.py b/tests/issues/regression/test_issue_g00j_pre_1994q3_quarters.py index f213804d7..d16f306cd 100644 --- a/tests/issues/regression/test_issue_g00j_pre_1994q3_quarters.py +++ b/tests/issues/regression/test_issue_g00j_pre_1994q3_quarters.py @@ -11,11 +11,14 @@ `get_by_accession_number("0000003673-94-000052")` - a real 35-CERT filed by Allegheny Power System Inc on 1994-06-30 (1994 Q2) - returned None. """ +import gzip import itertools +from pathlib import Path import pytest from edgar._filings import available_quarters, expand_quarters +from edgar.httprequests import decode_content @pytest.mark.fast @@ -52,11 +55,50 @@ def test_expand_quarters_still_excludes_1992(self): assert expand_quarters(1992, 4) == [] -@pytest.mark.network +FULL_INDEX = Path(__file__).parents[2] / "fixtures" / "full_index" + + +def _serve_full_index(requested: list): + """A `download_text` stand-in serving the committed SEC quarterly form indexes.""" + + def _download_text(url, *args, **kwargs): + requested.append(url) + prefix = "https://www.sec.gov/Archives/edgar/full-index/" + if not url.startswith(prefix): + raise AssertionError(f"unexpected request in an offline test: {url}") + path = FULL_INDEX / url[len(prefix):] + if not path.is_file(): + raise AssertionError(f"no recorded full-index for {url} (expected {path})") + return decode_content(gzip.decompress(path.read_bytes())) + + return _download_text + + +@pytest.fixture +def recorded_full_index(monkeypatch): + """Resolve accessions through the committed 1993-1994 H1 full-index files. + + EFTS only indexes 2001 onward, so for these accessions it always misses and + the lookup falls through to the quarterly index scan, which is the path this + bug blocked. Stubbing the EFTS miss keeps the test on that path offline. + """ + from edgar import _filings + + requested = [] + monkeypatch.setattr(_filings, "_filing_from_efts", lambda accession_number: None) + monkeypatch.setattr(_filings, "download_text", _serve_full_index(requested)) + _filings.get_filing_by_accession.cache_clear() + _filings._get_cached_filings.cache_clear() + yield requested + _filings.get_filing_by_accession.cache_clear() + _filings._get_cached_filings.cache_clear() + + +@pytest.mark.fast class TestPre1994Q3AccessionLookup: """End-to-end: a real filing from before the old 1994 Q3 boundary must resolve.""" - def test_1994_q2_filing_resolves(self): + def test_1994_q2_filing_resolves(self, recorded_full_index): from edgar import get_by_accession_number # Real 35-CERT filed by Allegheny Power System Inc, 1994 Q2 - previously @@ -69,8 +111,11 @@ def test_1994_q2_filing_resolves(self): assert filing.company == "ALLEGHENY POWER SYSTEM INC" assert filing.form == "35-CERT" assert str(filing.filing_date) == "1994-06-30" + # Q1 is scanned and misses, Q2 holds the filing. + assert [u.split("full-index/")[1] for u in recorded_full_index] == [ + "1994/QTR1/form.gz", "1994/QTR2/form.gz"] - def test_1993_filing_resolves(self): + def test_1993_filing_resolves(self, recorded_full_index): from edgar import get_by_accession_number # Real 24F-2NT filed 1993-09-28, accessioned with a genuine "-93-" year @@ -83,3 +128,5 @@ def test_1993_filing_resolves(self): assert filing.company == "MERRILL LYNCH FL MUN BOND FD OF MERRILL LYNCH MUL ST MUN SER" assert filing.form == "24F-2NT" assert str(filing.filing_date) == "1993-09-28" + assert [u.split("full-index/")[1] for u in recorded_full_index] == [ + "1993/QTR1/form.gz", "1993/QTR2/form.gz", "1993/QTR3/form.gz"]