us-short-interest / tests /test_docs.py
ZipLime's picture
Update the US short interest licensing audit
9368d93 verified
Raw History Blame Contribute Delete
3.08 kB
"""What the repository says about itself, checked against the repository."""
from __future__ import annotations
import re
from pathlib import Path
import pytest
import yaml
from recipe.licensing import publishable_subsets
from recipe.private import UnsafePrivateDirectory, check_private_dir
from recipe.schema import CONFIG_SCHEMAS
ROOT = Path(__file__).resolve().parent.parent
# Written as escapes so the pattern does not trip over itself.
CYRILLIC = re.compile("[\u0400-\u04ff]")
def test_the_readme_states_the_finding_in_its_first_lines():
text = (ROOT / "README.md").read_text(encoding="utf-8")
head = text.split("## ")[0]
assert "publishes no short-interest data" in head
assert len(text) > 4000
def test_the_readme_quotes_the_clauses_the_decision_rests_on():
text = (ROOT / "README.md").read_text(encoding="utf-8")
assert "No Further Redistribution" in text
assert "non-commercial" in text
assert "34-104303" in text
assert "January 2, 2028" in text
def test_the_readme_names_every_subset_that_is_withheld():
text = (ROOT / "README.md").read_text(encoding="utf-8")
assert "short_interest" in text
assert "sec_form_sho" in text
for subset in CONFIG_SCHEMAS:
assert subset in text or subset.startswith("sec_form_sho"), subset
def test_the_readme_says_where_to_get_the_data_instead():
"""A refusal without an alternative is less useful than it could be."""
text = (ROOT / "README.md").read_text(encoding="utf-8")
assert "developer.finra.org" in text
assert "Where to get the data instead" in text
def test_the_readme_refuses_the_easy_substitute():
"""Short-sale volume is a different quantity and must not stand in."""
text = (ROOT / "README.md").read_text(encoding="utf-8")
assert "short-sale volume" in text
def test_every_source_is_recorded_even_though_none_is_canonical():
sources = yaml.safe_load((ROOT / "metadata" / "sources.yaml").read_text(encoding="utf-8"))
entries = sources["sources"]
assert len(entries) >= 4
assert all(entry["canonical"] is False for entry in entries)
assert publishable_subsets() == []
@pytest.mark.parametrize(
"path",
sorted(
path
for pattern in ("recipe/**/*.py", "tests/**/*.py", "*.md", "metadata/*.yaml")
for path in ROOT.glob(pattern)
if path.is_file()
),
ids=lambda path: str(path.relative_to(ROOT)),
)
def test_the_repository_is_written_in_english(path: Path):
found = CYRILLIC.search(path.read_text(encoding="utf-8"))
assert found is None, f"{path.relative_to(ROOT)} contains Cyrillic at offset {found.start()}"
def test_a_private_directory_inside_the_repository_is_refused():
"""That directory is the tree that gets published."""
with pytest.raises(UnsafePrivateDirectory):
check_private_dir(ROOT / "data" / "private")
with pytest.raises(UnsafePrivateDirectory):
check_private_dir(ROOT)
def test_a_private_directory_outside_the_repository_is_allowed(tmp_path):
assert check_private_dir(tmp_path).is_absolute()