You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.3 KiB
90 lines
3.3 KiB
---
|
|
title: Test assertions failed after extracting SVD_THEMES to separate module
|
|
date: 2026-04-04
|
|
category: docs/solutions/test-failures/
|
|
module: Stemwijzer Data Analysis
|
|
problem_type: test_failure
|
|
component: explorer
|
|
symptoms:
|
|
- "test_display_label_for_modal" assertion failed with "EU-integratie" not found
|
|
- "test_get_svd_label_returns_correct_label" assertion failed with "Nationalisme" not found
|
|
- Tests expected old fallback labels but SVD_THEMES had updated values
|
|
root_cause: test_failure
|
|
resolution_type: test_fix
|
|
severity: medium
|
|
tags: [svd, test-assertions, refactoring, constants]
|
|
affected_files:
|
|
- tests/test_axis_label_fallback.py
|
|
- tests/test_svd_labels.py
|
|
- analysis/config.py
|
|
---
|
|
|
|
# Test assertions failed after extracting SVD_THEMES to separate module
|
|
|
|
## Problem
|
|
|
|
After extracting `SVD_THEMES` constant from `explorer.py` to `analysis/config.py`, tests failed because they hardcoded assertions for old label text.
|
|
|
|
## Symptoms
|
|
|
|
- `test_display_label_for_modal`: expected `"EU-integratie" in x_label or "Nationalisme" in x_label`
|
|
- `test_get_svd_label_returns_correct_label`: expected `"EU-integratie" in label1`
|
|
- `test_manifest_loads`: manifest.yaml had `categories:` key instead of `files:`
|
|
|
|
## What Didn't Work
|
|
|
|
- Investigating `get_svd_label()` function — it correctly returned values from `SVD_THEMES`
|
|
- Checking import chain — no circular import issues
|
|
- The problem was purely that test assertions hardcoded OLD expected label values
|
|
|
|
## Solution
|
|
|
|
Updated test assertions to match the current `SVD_THEMES` values:
|
|
|
|
**tests/test_axis_label_fallback.py:**
|
|
|
|
```python
|
|
# Before (incorrect)
|
|
assert "EU-integratie" in x_label or "Nationalisme" in x_label
|
|
assert "Populistisch" in y_label or "Institutioneel" in y_label
|
|
|
|
# After (correct)
|
|
assert "Rechts kabinetsbeleid" in x_label or "links oppositiebeleid" in x_label
|
|
assert "PVV/FVD-populisme" in y_label or "mainstream-partijen" in y_label
|
|
```
|
|
|
|
**tests/test_svd_labels.py:**
|
|
|
|
```python
|
|
# Before (incorrect)
|
|
assert "EU-integratie" in label1 or "Nationalisme" in label1
|
|
|
|
# After (correct)
|
|
assert "Rechts kabinetsbeleid" in label1 or "links oppositiebeleid" in label1
|
|
```
|
|
|
|
**Fix manifest.yaml:**
|
|
|
|
```yaml
|
|
# Before (incorrect)
|
|
categories:
|
|
|
|
# After (correct)
|
|
files:
|
|
```
|
|
|
|
## Why This Works
|
|
|
|
The tests were asserting on hardcoded string values that no longer matched the actual `SVD_THEMES` content. After updating the assertions to check for current label text, tests pass because they correctly verify the actual values returned.
|
|
|
|
## Prevention
|
|
|
|
1. **Audit tests when extracting constants** — When extracting constants to separate modules, grep for all test references to those constants and update assertions
|
|
2. **Use flexible assertions** — Prefer `in` checks over exact matches when testing label text, or better yet, import the constant directly in tests and assert equality
|
|
3. **Update manifest tests early** — When changing YAML structure in config files, check for corresponding manifest/schema tests
|
|
|
|
## Related Issues
|
|
|
|
- `analysis/config.py` — Contains `SVD_THEMES` (extracted from `explorer.py`)
|
|
- `analysis/svd_labels.py` — Uses `SVD_THEMES` via runtime import from `explorer.py`
|
|
- `docs/solutions/logic-errors/svd-component-labels-mismatch.md` — Background on why SVD labels were updated from semantic to voting-pattern based
|
|
|