core/tests/helpers
Phil Bruckner b2d7bc40dc
Add support for simultaneous runs of Script helper ()
* Add tests for legacy Script helper behavior

* Add Script helper if_running and run_mode options

- if_running controls what happens if Script run while previous run
  has not completed. Can be:
  - error: Raise an exception
  - ignore: Return without doing anything (previous run continues as-is)
  - parallel: Start run in new task
  - restart: Stop previous run before starting new run
- run_mode controls when call to async_run will return. Can be:
  - background: Returns immediately
  - legacy: Implements previous behavior, which is to return when done,
            or when suspended by delay or wait_template
  - blocking: Returns when run has completed
- If neither is specified, default is run_mode=legacy (and if_running
  is not used.) Otherwise, defaults are if_running=parallel and
  run_mode=background. If run_mode is set to legacy then if_running must
  be None.
- Caller may supply a logger which will be used throughout instead of
  default module logger.
- Move Script running state into new helper classes, comprised of an
  abstract base class and two concrete clases, one for legacy behavior
  and one for new behavior.
- Remove some non-async methods, as well as call_from_config which has
  only been used in tests.
- Adjust tests accordingly.

* Change per review

- Change run_mode default from background to blocking.
- Make sure change listener is called, even when there's an unexpected
  exception.
- Make _ScriptRun.async_stop more graceful by using an asyncio.Event for
  signaling instead of simply cancelling Task.
- Subclass _ScriptRun for background & blocking behavior.

Also:

- Fix timeouts in _ScriptRun by converting timedeltas to float seconds.
- General cleanup.

* Change per review 2

- Don't propagate exceptions if call from user has already returned
  (i.e., for background runs or legacy runs that have suspended.)
- Allow user to specify if exceptions should be logged. They will still
  be logged regardless if exception is not propagated.
- Rename _start_script_delay and _start_wait_template_delay for
  clarity.
- Remove return value from Script.async_run.
- Fix missing await.
- Change call to self.is_running in Script.async_run to direct test of
  self._runs.

* Change per review 3 and add tests

- Remove Script.set_logger().
- Enhance existing tests to check all run modes.
- Add tests for new features.
- Fix a few minor bugs found by tests.
2020-02-24 14:56:00 -08:00
..
__init__.py Fix PEP257 issues 2016-03-09 11:15:04 +01:00
test_aiohttp_client.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_area_registry.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_check_config.py Remove unnecessary string literal concatenations () 2020-01-02 21:17:10 +02:00
test_collection.py Add person reload service () 2020-01-05 11:16:37 +01:00
test_condition.py Find related items scripts/automations () 2020-01-29 16:19:13 -08:00
test_config_entry_flow.py Various string cleanups () 2020-01-03 14:47:06 +01:00
test_config_entry_oauth2_flow.py Fix discovery for oauth2 flow implementations () 2020-01-12 07:37:34 -08:00
test_config_validation.py Use ciso8601 library to parse datetime faster () 2020-02-24 08:33:10 -08:00
test_debounce.py Update the update coordinator API to make it easier to use () 2020-02-06 09:29:29 -08:00
test_deprecation.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_device_registry.py Remove unnecessary string literal concatenations () 2020-01-02 21:17:10 +02:00
test_discovery.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_dispatcher.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_entity.py Adjust entity slow warning for custom component () 2020-02-10 16:32:47 -08:00
test_entity_component.py Log warning when entities referenced in service call not found () 2020-02-04 14:42:07 -08:00
test_entity_platform.py Use entity.async_request_call in service helper () 2020-02-04 15:30:15 -08:00
test_entity_registry.py Fix entity registry not saving name/icon () 2020-02-18 08:32:34 -08:00
test_entity_values.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_entityfilter.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_event.py Fix typos found by codespell () 2020-01-31 08:33:00 -08:00
test_icon.py StarLine integration () 2019-11-26 11:17:11 -08:00
test_init.py Black 2019-07-31 12:25:30 -07:00
test_integration_platform.py Add integration platform helper () 2019-12-13 15:38:41 +01:00
test_intent.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_json.py Black 2019-07-31 12:25:30 -07:00
test_location.py Black 2019-07-31 12:25:30 -07:00
test_network.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_restore_state.py Restore state helper to work with entity registry restoration () 2020-01-05 11:58:59 +01:00
test_script.py Add support for simultaneous runs of Script helper () 2020-02-24 14:56:00 -08:00
test_service.py Use entity.async_request_call in service helper () 2020-02-04 15:30:15 -08:00
test_state.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_storage.py Be consistent with Home Assistant and Hass.io spelling () 2020-01-05 14:09:17 +02:00
test_sun.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_system_info.py Black 2019-07-31 12:25:30 -07:00
test_temperature.py Various string cleanups () 2020-01-03 14:47:06 +01:00
test_template.py Be consistent with Home Assistant and Hass.io spelling () 2020-01-05 14:09:17 +02:00
test_translation.py Sort imports according to PEP8 for 'tests' () 2019-12-09 16:52:24 +01:00
test_update_coordinator.py Update the update coordinator API to make it easier to use () 2020-02-06 09:29:29 -08:00