-
Notifications
You must be signed in to change notification settings - Fork 238
fix: correct inverted label on manual_refresh_only config option #2196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
custom_components/uk_bin_collection/tests/test_translations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| """Regression tests for the config-flow translation strings. | ||
|
|
||
| These guard against the `manual_refresh_only` label inversion (issue #2193): | ||
| the field stores "manual refresh only" semantics, but the UI used to label it | ||
| "Automatically refresh the sensor" — the exact inverse — so ticking the box | ||
| silently disabled automatic refresh. | ||
|
|
||
| Dependency-free on purpose: json + pathlib only. | ||
| """ | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
|
|
||
| # custom_components/uk_bin_collection/ | ||
| INTEGRATION_DIR = Path(__file__).resolve().parent.parent | ||
| STRINGS_JSON = INTEGRATION_DIR / "strings.json" | ||
| TRANSLATIONS_DIR = INTEGRATION_DIR / "translations" | ||
|
|
||
| KEY = "manual_refresh_only" | ||
| OLD_INVERTED_LABEL = "Automatically refresh the sensor" | ||
|
|
||
|
|
||
| def _load(path: Path) -> dict: | ||
| with path.open(encoding="utf-8") as handle: | ||
| return json.load(handle) | ||
|
|
||
|
|
||
| def _all_translation_files() -> list[Path]: | ||
| return sorted(TRANSLATIONS_DIR.glob("*.json")) | ||
|
|
||
|
|
||
| def _steps_with_key(data: dict) -> dict: | ||
| """Return {step_name: label} for every config.step.*.data carrying KEY.""" | ||
| found = {} | ||
| steps = data.get("config", {}).get("step", {}) | ||
| for step_name, step in steps.items(): | ||
| step_data = step.get("data", {}) | ||
| if KEY in step_data: | ||
| found[step_name] = step_data[KEY] | ||
| return found | ||
|
|
||
|
|
||
| def _steps_with_description(data: dict) -> dict: | ||
| """Return {step_name: text} for every config.step.*.data_description[KEY].""" | ||
| found = {} | ||
| steps = data.get("config", {}).get("step", {}) | ||
| for step_name, step in steps.items(): | ||
| descriptions = step.get("data_description", {}) | ||
| if KEY in descriptions: | ||
| found[step_name] = descriptions[KEY] | ||
| return found | ||
|
|
||
|
|
||
| def test_all_json_files_are_valid(): | ||
| """Every strings/translation file must parse as JSON.""" | ||
| _load(STRINGS_JSON) | ||
| for path in _all_translation_files(): | ||
| _load(path) | ||
|
|
||
|
|
||
| def test_manual_refresh_label_not_inverted(): | ||
| """No label may claim the field enables automatic refresh.""" | ||
| files = [STRINGS_JSON, *_all_translation_files()] | ||
| for path in files: | ||
| labels = _steps_with_key(_load(path)) | ||
| assert labels, f"{path.name}: expected at least one '{KEY}' label" | ||
| for step_name, label in labels.items(): | ||
| where = f"{path.name} :: config.step.{step_name}.data.{KEY}" | ||
|
|
||
| # The exact old inverted English string must be gone everywhere. | ||
| assert label != OLD_INVERTED_LABEL, ( | ||
| f"{where}: still uses the inverted label {OLD_INVERTED_LABEL!r}" | ||
| ) | ||
|
|
||
| # If the label mentions "automatic(ally)", it must be a negation | ||
| # (e.g. "disable automatic updates"), never a promise to refresh. | ||
| lowered = label.lower() | ||
| if "automatic" in lowered: | ||
| assert "manual" in lowered or "disable" in lowered, ( | ||
| f"{where}: label {label!r} mentions 'automatic' without a " | ||
| "negating 'manual'/'disable' — likely still inverted" | ||
| ) | ||
|
|
||
|
|
||
| def test_strings_and_en_translation_stay_in_sync(): | ||
| """strings.json and en.json must carry KEY in the same steps.""" | ||
| strings_steps = set(_steps_with_key(_load(STRINGS_JSON))) | ||
| en_steps = set(_steps_with_key(_load(TRANSLATIONS_DIR / "en.json"))) | ||
| assert strings_steps == en_steps, ( | ||
| f"strings.json steps {sorted(strings_steps)} != " | ||
| f"en.json steps {sorted(en_steps)}" | ||
| ) | ||
| # Guard against the key silently disappearing from both. | ||
| assert strings_steps, "manual_refresh_only missing from strings.json steps" | ||
|
|
||
|
|
||
| def test_manual_refresh_has_description_in_every_locale(): | ||
| """Every locale must carry data_description for KEY in each step that | ||
| labels it, so no locale falls back to English helper text.""" | ||
| files = [STRINGS_JSON, *_all_translation_files()] | ||
| for path in files: | ||
| data = _load(path) | ||
| label_steps = set(_steps_with_key(data)) | ||
| description_steps = set(_steps_with_description(data)) | ||
| assert label_steps, f"{path.name}: expected at least one '{KEY}' label" | ||
| missing = label_steps - description_steps | ||
| assert not missing, ( | ||
| f"{path.name}: missing data_description.{KEY} in step(s) " | ||
| f"{sorted(missing)}" | ||
| ) | ||
| for step_name, text in _steps_with_description(data).items(): | ||
| where = f"{path.name} :: config.step.{step_name}.data_description.{KEY}" | ||
| assert text.strip(), f"{where}: description must not be empty" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.