From db766a93dfebe270a020cdb7755387b16fe33ecd Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 22:27:18 +0200 Subject: [PATCH 1/7] Unify formatting of fixtures --- scripts/tests_and_coverage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 801e44242..c54b96e74 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -39,4 +39,7 @@ if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then echo "... crafting fake_fixtures ..." PYTHONPATH=$(pwd) python3 scripts/fake_fixtures.py + + echo "... formatting fixtures ..." + PYTHONPATH=$(pwd) black -q fixtures/**/*json fi From bb84bccebca024c7d4041f4cbf673af1025c33c8 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 23:01:26 +0200 Subject: [PATCH 2/7] Add diffsyncer --- scripts/update_fixtures.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 scripts/update_fixtures.sh 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 From 9678cc8d7ea6ecea46d44996ea63a30f2b9c08e9 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 23:10:34 +0200 Subject: [PATCH 3/7] Write sorted to maintain order between repos --- scripts/fake_fixtures.py | 56 ++++++++++++++++++++++++++++++++++------ tests/test_smile.py | 1 + 2 files changed, 49 insertions(+), 8 deletions(-) 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/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, ) ) From c7f068085ec344ab90ed2f9dce41d6ad699cfe0f Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 23:17:05 +0200 Subject: [PATCH 4/7] Include in pre-commit --- .pre-commit-config.yaml | 6 ++++++ scripts/tests_and_coverage.sh | 2 ++ 2 files changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cc132642..2d61189b6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index c54b96e74..e2119f077 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 From 32e102df2c83147cf782b2f38e2567319a93ba9c Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 23:18:31 +0200 Subject: [PATCH 5/7] Ensure consistency with manual fixtures --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2d61189b6..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: From 955aaeac47252da46d3cf5490d46711bcbe7eab9 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Thu, 4 May 2023 23:24:38 +0200 Subject: [PATCH 6/7] Remove black due to strict json --- scripts/tests_and_coverage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index e2119f077..e995d2257 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -41,7 +41,4 @@ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "fixtures" ] ; then echo "... crafting fake_fixtures ..." PYTHONPATH=$(pwd) python3 scripts/fake_fixtures.py - - echo "... formatting fixtures ..." - PYTHONPATH=$(pwd) black -q fixtures/**/*json fi From e86e81fca65d70c4080da2b8911ef68dbccf86b9 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Fri, 5 May 2023 00:20:37 +0200 Subject: [PATCH 7/7] CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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)