diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cc132642..d9ff4b462 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ ci: # Defer autoupdate to quarterly (there is no 'off' button) to have renovate pick up first autoupdate_schedule: quarterly - skip: [pylint, markdownlint, testing] + skip: [pylint, markdownlint, testing, fixtures] submodules: true default_language_version: @@ -108,6 +108,12 @@ repos: entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" scripts/tests_and_coverage.sh test_and_coverage' language: script pass_filenames: false + - id: fixtures + name: "Fixture formatting" + # yamllint disable-line rule:line-length + entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" scripts/tests_and_coverage.sh fixtures' + language: script + pass_filenames: false - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.34.0 hooks: diff --git a/CHANGELOG.md b/CHANGELOG.md index da575018e..1f9aa85a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Ongoing + +- Improve fixture generation and manual fixtures + ## v0.31.3: Typing updates, improved fixture generation and manual mode-changes ## v0.31.2: Introduce strict-typing (py.typed) diff --git a/scripts/fake_fixtures.py b/scripts/fake_fixtures.py index b3eaf21b9..c6013dfd0 100755 --- a/scripts/fake_fixtures.py +++ b/scripts/fake_fixtures.py @@ -131,12 +131,22 @@ os.makedirs(f"./fixtures/{fake_name}") outfile = f"./fixtures/{fake_name}/all_data.json" -data = json.dumps(m_adam_cooling, indent=2) +data = json.dumps( + m_adam_cooling, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) outfile = f"./fixtures/{fake_name}/notifications.json" -data = json.dumps(base_n, indent=2) +data = json.dumps( + base_n, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) @@ -246,12 +256,22 @@ os.makedirs(f"./fixtures/{fake_name}") outfile = f"./fixtures/{fake_name}/all_data.json" -data = json.dumps(m_adam_heating, indent=2) +data = json.dumps( + m_adam_heating, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) outfile = f"./fixtures/{fake_name}/notifications.json" -data = json.dumps(base_n, indent=2) +data = json.dumps( + base_n, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) @@ -341,12 +361,22 @@ os.makedirs(f"./fixtures/{fake_name}") outfile = f"./fixtures/{fake_name}/all_data.json" -data = json.dumps(m_anna_heatpump_cooling, indent=2) +data = json.dumps( + m_anna_heatpump_cooling, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) outfile = f"./fixtures/{fake_name}/notifications.json" -data = json.dumps(base_n, indent=2) +data = json.dumps( + base_n, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) @@ -398,11 +428,21 @@ os.makedirs(f"./fixtures/{fake_name}") outfile = f"./fixtures/{fake_name}/all_data.json" -data = json.dumps(m_anna_heatpump_idle, indent=2) +data = json.dumps( + m_anna_heatpump_idle, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) outfile = f"./fixtures/{fake_name}/notifications.json" -data = json.dumps(base_n, indent=2) +data = json.dumps( + base_n, + indent=2, + sort_keys=True, + default=lambda x: list(x) if isinstance(x, set) else x, +) with open(outfile, "w") as f: f.write(data) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 801e44242..e995d2257 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -36,7 +36,9 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then echo "... pylint-ing ..." pylint plugwise/ tests/ +fi +if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "fixtures" ] ; then echo "... crafting fake_fixtures ..." PYTHONPATH=$(pwd) python3 scripts/fake_fixtures.py fi diff --git a/scripts/update_fixtures.sh b/scripts/update_fixtures.sh new file mode 100755 index 000000000..e2355f29a --- /dev/null +++ b/scripts/update_fixtures.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -eu + +# Fixtures consumed by plugwise-beta +test_fixtures="adam_multiple_devices_per_zone m_adam_cooling m_anna_heatpump_cooling p1v3_full_option stretch_v31 anna_heatpump_heating m_adam_heating m_anna_heatpump_idle p1v4_442_triple" + +# If plugwise-beta is relative to this repository, check if files differ and update accordingly +if [ -d ../plugwise-beta ]; then + for fixture in ${test_fixtures}; do + echo "Checking fixture ${fixture}: " + diff -qr "fixtures/${fixture}" "../plugwise-beta/tests/components/plugwise/fixtures/${fixture}" > /dev/null && continue + echo " - Out-of-date ... updating fixture in plugwise-beta" + if [ -d "../plugwise-beta/tests/components/plugwise/fixtures/${fixture}" ]; then + cp -pfr fixtures/"${fixture}"/* ../plugwise-beta/tests/components/plugwise/fixtures/"${fixture}"/ + fi + done +fi diff --git a/tests/test_smile.py b/tests/test_smile.py index f2badfbda..fca25ccf3 100644 --- a/tests/test_smile.py +++ b/tests/test_smile.py @@ -54,6 +54,7 @@ def _write_json(self, call, data): json.dumps( data, indent=2, + sort_keys=True, default=lambda x: list(x) if isinstance(x, set) else x, ) )