> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# tests/test_config.py

> The registries in config/ (retailers, Wikipedia articles, retail series) must follow their contracts, so anyone can add a retailer, an article or a series by adding a row without breaking the pipeline. The event calendar has its own tests (test_event_calendar.py).

`tests/test_config.py` · chapter [Tests and team tooling](https://calendar-effects.mintlify.site/tour/10-tests-and-tooling.md), file 2 · 89 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_config.py)

## What it does

The registries in config/ (retailers, Wikipedia articles, retail series) must follow
their contracts, so anyone can add a retailer, an article or a series by adding a row
without breaking the pipeline. The event calendar has its own tests (test\_event\_calendar.py).

## What is inside

* **`TICKER`** · [line 13](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_config.py#L13)
* **`COUNTRY`** · [line 14](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_config.py#L14)
* **`SNAKE_CASE`** · [line 15](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_config.py#L15)
* **`duplicates(values)`** · [line 18](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/tests/test_config.py#L18)

## What it checks

* retailer tickers are unique yahoo symbols (line 23)
* retailer columns use known values (line 30)
* market index is not listed as a retailer (line 38)
* some retailers are in scope (line 44)
* every wiki article belongs to a listed retailer (line 48)
* every in scope retailer has a wiki article (line 54)
* wiki titles are unique and use underscores (line 60)
* in scope articles skip candidate retailers (line 66)
* retail series ids and categories are unique (line 71)
* loaders reject a file whose columns do not match the contract (line 79)
* loaders read files saved by excel (line 86)

## Connections

**Uses:** [`src/common/contracts.py`](https://calendar-effects.mintlify.site/reference/src/common/contracts), [`src/common/study.py`](https://calendar-effects.mintlify.site/reference/src/common/study)

## Source

```python title="tests/test_config.py" lines expandable theme={null}
"""The registries in config/ (retailers, Wikipedia articles, retail series) must follow
their contracts, so anyone can add a retailer, an article or a series by adding a row
without breaking the pipeline. The event calendar has its own tests (test_event_calendar.py)."""
from __future__ import annotations

import re

import pytest

from common.contracts import load_retail_series, load_retailers, load_wiki_articles
from common.study import MARKET_TICKER

TICKER = re.compile(r"^[A-Z0-9][A-Z0-9.\-]*$")
COUNTRY = re.compile(r"^[A-Z]{2}$")
SNAKE_CASE = re.compile(r"^[a-z][a-z0-9_]*$")


def duplicates(values) -> set:
    values = list(values)
    return {v for v in values if values.count(v) > 1}


def test_retailer_tickers_are_unique_yahoo_symbols():
    tickers = [r["ticker"] for r in load_retailers()]
    assert not duplicates(tickers), f"duplicate ticker: {duplicates(tickers)}"
    bad = [t for t in tickers if not TICKER.match(t)]
    assert not bad, f"tickers must be Yahoo Finance symbols in capitals: {bad}"


def test_retailer_columns_use_known_values():
    for r in load_retailers():
        assert r["company"].strip(), f"{r['ticker']}: company is empty"
        assert COUNTRY.match(r["country"]), f"{r['ticker']}: country must be a two-letter code like US or CA"
        assert r["retailer_type"] in {"online", "store"}, f"{r['ticker']}: retailer_type must be online or store"
        assert r["in_scope"] in {"yes", "no"}, f"{r['ticker']}: in_scope must be yes or no"


def test_market_index_is_not_listed_as_a_retailer():
    assert MARKET_TICKER not in {r["ticker"] for r in load_retailers()}, (
        f"{MARKET_TICKER} is the market index (common.study.MARKET_TICKER); remove it from config/retailers.csv"
    )


def test_some_retailers_are_in_scope():
    assert load_retailers(in_scope_only=True)


def test_every_wiki_article_belongs_to_a_listed_retailer():
    tickers = {r["ticker"] for r in load_retailers()}
    unknown = {a["ticker"] for a in load_wiki_articles()} - tickers
    assert not unknown, f"config/wiki_articles.csv uses tickers missing from config/retailers.csv: {unknown}"


def test_every_in_scope_retailer_has_a_wiki_article():
    covered = {a["ticker"] for a in load_wiki_articles()}
    missing = {r["ticker"] for r in load_retailers(in_scope_only=True)} - covered
    assert not missing, f"in-scope retailers with no row in config/wiki_articles.csv: {missing}"


def test_wiki_titles_are_unique_and_use_underscores():
    titles = [a["article"] for a in load_wiki_articles()]
    assert not duplicates(titles), f"duplicate article: {duplicates(titles)}"
    assert not [t for t in titles if " " in t or not t], "titles use underscores instead of spaces"


def test_in_scope_articles_skip_candidate_retailers():
    in_scope = {r["ticker"] for r in load_retailers(in_scope_only=True)}
    assert {a["ticker"] for a in load_wiki_articles(in_scope_only=True)} <= in_scope


def test_retail_series_ids_and_categories_are_unique():
    series = load_retail_series()
    assert series
    assert not duplicates(s["series_id"] for s in series)
    assert not duplicates(s["category"] for s in series)
    assert all(SNAKE_CASE.match(s["category"]) for s in series), "categories must be snake_case"


def test_loaders_reject_a_file_whose_columns_do_not_match_the_contract(tmp_path):
    wrong = tmp_path / "retailers.csv"
    wrong.write_text("ticker,company,exchange\nWMT,Walmart,NYSE\n")
    with pytest.raises(ValueError, match="retailers"):
        load_retailers(wrong)


def test_loaders_read_files_saved_by_excel(tmp_path):
    excel = tmp_path / "retail_series.csv"
    excel.write_bytes(b"\xef\xbb\xbfseries_id,category,notes\r\nRSXFS,all_retail,\r\n")
    assert load_retail_series(excel) == [{"series_id": "RSXFS", "category": "all_retail", "notes": ""}]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.