From 5ddad2647605b28da208029e7959aa12701904bd Mon Sep 17 00:00:00 2001 From: Keith Burzinski Date: Wed, 1 May 2024 14:17:11 -0500 Subject: [PATCH] Extend and consolidate `script` tests (#6663) --- tests/components/script/common.yaml | 55 +++++++++++++++++++ tests/components/script/test.bk72xx.yaml | 1 + .../components/script/test.esp32-c3-idf.yaml | 27 +-------- tests/components/script/test.esp32-c3.yaml | 27 +-------- tests/components/script/test.esp32-idf.yaml | 27 +-------- tests/components/script/test.esp32.yaml | 27 +-------- tests/components/script/test.esp8266.yaml | 27 +-------- tests/components/script/test.rp2040.yaml | 27 +-------- 8 files changed, 62 insertions(+), 156 deletions(-) create mode 100644 tests/components/script/common.yaml create mode 100644 tests/components/script/test.bk72xx.yaml diff --git a/tests/components/script/common.yaml b/tests/components/script/common.yaml new file mode 100644 index 000000000..bfd5d0e7f --- /dev/null +++ b/tests/components/script/common.yaml @@ -0,0 +1,55 @@ +esphome: + on_boot: + then: + - script.execute: my_script + - script.execute: + id: my_script_with_params + prefix: "Test" + param2: 0 + param3: true + - script.wait: my_script + - script.stop: my_script + - if: + condition: + - script.is_running: my_script + then: + - logger.log: my_script is running + +script: + - id: my_script + mode: single + then: + - lambda: 'ESP_LOGD("main", "Hello World!");' + - id: my_script_queued + mode: queued + max_runs: 2 + then: + - lambda: 'ESP_LOGD("main", "Hello World!");' + - id: my_script_parallel + mode: parallel + max_runs: 2 + then: + - lambda: 'ESP_LOGD("main", "Hello World!");' + - id: my_script_restart + mode: restart + then: + - lambda: 'ESP_LOGD("main", "Hello World!");' + - id: my_script_with_params + parameters: + prefix: string + param2: uint8_t + param3: bool + then: + - lambda: 'ESP_LOGD(prefix.c_str(), "Hello World! %u %u", param2, param3);' + - if: + condition: + for: + time: !lambda "return param2;" + condition: + script.is_running: my_script + then: + - lambda: 'ESP_LOGD("main", "API has stayed connected for at least %u minutes", param2);' + - repeat: + count: 5 + then: + - logger.log: looping! diff --git a/tests/components/script/test.bk72xx.yaml b/tests/components/script/test.bk72xx.yaml new file mode 100644 index 000000000..dade44d14 --- /dev/null +++ b/tests/components/script/test.bk72xx.yaml @@ -0,0 +1 @@ +<<: !include common.yaml diff --git a/tests/components/script/test.esp32-c3-idf.yaml b/tests/components/script/test.esp32-c3-idf.yaml index 3872c690f..dade44d14 100644 --- a/tests/components/script/test.esp32-c3-idf.yaml +++ b/tests/components/script/test.esp32-c3-idf.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD("main", (prefix + " Hello World!" + to_string(param2) + " " + to_string(param3)).c_str());' +<<: !include common.yaml diff --git a/tests/components/script/test.esp32-c3.yaml b/tests/components/script/test.esp32-c3.yaml index 3872c690f..dade44d14 100644 --- a/tests/components/script/test.esp32-c3.yaml +++ b/tests/components/script/test.esp32-c3.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD("main", (prefix + " Hello World!" + to_string(param2) + " " + to_string(param3)).c_str());' +<<: !include common.yaml diff --git a/tests/components/script/test.esp32-idf.yaml b/tests/components/script/test.esp32-idf.yaml index 3872c690f..dade44d14 100644 --- a/tests/components/script/test.esp32-idf.yaml +++ b/tests/components/script/test.esp32-idf.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD("main", (prefix + " Hello World!" + to_string(param2) + " " + to_string(param3)).c_str());' +<<: !include common.yaml diff --git a/tests/components/script/test.esp32.yaml b/tests/components/script/test.esp32.yaml index 3872c690f..dade44d14 100644 --- a/tests/components/script/test.esp32.yaml +++ b/tests/components/script/test.esp32.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD("main", (prefix + " Hello World!" + to_string(param2) + " " + to_string(param3)).c_str());' +<<: !include common.yaml diff --git a/tests/components/script/test.esp8266.yaml b/tests/components/script/test.esp8266.yaml index ce0e40e7e..dade44d14 100644 --- a/tests/components/script/test.esp8266.yaml +++ b/tests/components/script/test.esp8266.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD(prefix.c_str(), "Hello World! %i %i", param2, param3);' +<<: !include common.yaml diff --git a/tests/components/script/test.rp2040.yaml b/tests/components/script/test.rp2040.yaml index 3872c690f..dade44d14 100644 --- a/tests/components/script/test.rp2040.yaml +++ b/tests/components/script/test.rp2040.yaml @@ -1,26 +1 @@ -script: - - id: my_script - mode: single - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_queued - mode: queued - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_parallel - mode: parallel - max_runs: 2 - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_restart - mode: restart - then: - - lambda: 'ESP_LOGD("main", "Hello World!");' - - id: my_script_with_params - parameters: - prefix: string - param2: int - param3: bool - then: - - lambda: 'ESP_LOGD("main", (prefix + " Hello World!" + to_string(param2) + " " + to_string(param3)).c_str());' +<<: !include common.yaml