Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
56 changes: 48 additions & 8 deletions scripts/fake_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions scripts/tests_and_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions scripts/update_fixtures.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/test_smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
Expand Down