Skip to content

Commit

Permalink
Support writing expected YAML for tests, add missing RF YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Dec 13, 2023
1 parent d116368 commit 6871a2a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
20 changes: 18 additions & 2 deletions upk2esphome/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@

errors = []

argv = list(sys.argv)
if "-w" in argv:
write_expected = True
argv.remove("-w")
else:
write_expected = False

for file in glob(join(dirname(__file__), "tests", mask)):
if len(sys.argv) == 2 and sys.argv[1] not in file:
if len(argv) == 2 and argv[1] not in file:
continue
with open(file, "r") as f:
d = f.read().strip()
Expand All @@ -45,9 +52,18 @@
expected = join(
dirname(__file__), "tests", "expected_output", basename(file)
).replace(".txt", ".yaml")
if not isfile(expected):
if write_expected:
with open(expected, "w") as f:
f.write(yr.text)
continue
errors.append(
f"missing expected output for {basename(file)}, run with -w to write"
)
continue
with open(expected, "r") as f:
expected_yaml = f.read()
if expected_yaml != yr.text:
if expected_yaml.strip() != yr.text.strip():
errors.append(f"content of {expected} was not as expected")

if errors:
Expand Down
17 changes: 17 additions & 0 deletions upk2esphome/tests/expected_output/ty02-1ch-rf-v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
output:
- platform: libretiny_pwm
id: output_cold
pin: P8

light:
- platform: monochromatic
id: light_monochromatic
name: Light
output: output_cold

remote_receiver:
pin:
number: P7
inverted: true
mode: INPUT_PULLUP
# dump: all

0 comments on commit 6871a2a

Please sign in to comment.