Skip to main content
tests/test_no_hardcoding.py · chapter Tests and team tooling, file 6 · 163 lines · open in the repository

What it does

Pipeline code must not type in a value that config/ or common/ already defines (decision 0005). Otherwise adding a retailer, an event or a year means hunting through scripts, and the copies drift apart. If a test here fails, import the value instead: tickers common.contracts.price_tickers(), load_retailers(); common.study.MARKET_TICKER event ids and dates common.contracts.expand_events(), load_event_types() Wikipedia titles common.contracts.load_wiki_articles() FRED series common.contracts.load_retail_series() years and dates common.study.STUDY_START, STUDY_END, STUDY_START_YEAR, STUDY_END_YEAR file locations common.settings.clean_path(), RAW_DIR, DATA_DIR, REPLAY_DIR, STREAM_DIR, CHECKPOINT_DIR Kafka topic and servers common.contracts.KAFKA_TOPICS, common.settings.KAFKA_BOOTSTRAP Only code is checked: comments, docstrings and argparse help texts may show examples. A value that only looks like config (pandas’ month code ‘M’, a bootstrap count of 2000) can be kept by ending its line with # not-config: <reason>, which reviewers can see. The modules that define the values (DEFINING_MODULES) and the tests are not scanned.

What is inside

  • ROOT · line 35
  • CODE_DIRS · line 36
  • DEFINING_MODULES · line 37
  • EXCEPTION_MARKER · line 38: not-config:\s*\S”) # a reason must follow
  • TICKERS · line 40
  • EVENT_IDS · line 41
  • NAMES · line 42
  • YEAR_IN_TEXT · line 44
  • DATA_PATH · line 45
  • DATA_FOLDERS · line 46
  • mentions(text, values) · line 49: Values that appear in text as whole words, e.g. ‘SPY’ in “ticker != ‘SPY’”.
  • ticker_rule(v) · line 55
  • event_rule(v) · line 60
  • name_rule(v) · line 65
  • year_rule(v) · line 70
  • path_rule(v) · line 77
  • kafka_rule(v) · line 82
  • RULES · line 87
  • code_files() · line 91
  • code_literals(path) · line 96: (line, value) for every str/int literal in the file’s code, minus docstrings, argparse help texts and lines marked # not-config: &lt;reason>.
  • scan(paths, rule_names) · line 119

What it checks

  • the scan sees the pipeline code (line 131)
  • no hard coded values (line 137)
  • the scanner catches literals and skips docs (line 160)

Connections

Uses: src/common/contracts.py, src/common/study.py

Source

tests/test_no_hardcoding.py