async def test_shared_context(hass):
    'Test that the shared context is passed down the chain.'
    event = 'test_event'
    context = Context()
    event_mock = Mock()
    run_mock = Mock()
    hass.bus.async_listen(event, event_mock)
    hass.bus.async_listen(EVENT_SCRIPT_STARTED, run_mock)
    assert (await async_setup_component(hass, 'script', {'script': {'test': {'sequence': [{'event': event}]}}}))
    (await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, context=context))
    (await hass.async_block_till_done())
    assert (event_mock.call_count == 1)
    assert (run_mock.call_count == 1)
    (args, kwargs) = run_mock.call_args
    assert (args[0].context == context)
    assert (args[0].data.get(ATTR_NAME) == 'test')
    assert (args[0].data.get(ATTR_ENTITY_ID) == 'script.test')
    (args, kwargs) = event_mock.call_args
    assert (args[0].context == context)
    state = hass.states.get('script.test')
    assert (state is not None)
    assert (state.context == context)
Test that the shared context is passed down the chain.
async def test_shared_context(hass):
    
    event = 'test_event'
    context = Context()
    event_mock = Mock()
    run_mock = Mock()
    hass.bus.async_listen(event, event_mock)
    hass.bus.async_listen(EVENT_SCRIPT_STARTED, run_mock)
    assert (await async_setup_component(hass, 'script', {'script': {'test': {'sequence': [{'event': event}]}}}))
    (await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, context=context))
    (await hass.async_block_till_done())
    assert (event_mock.call_count == 1)
    assert (run_mock.call_count == 1)
    (args, kwargs) = run_mock.call_args
    assert (args[0].context == context)
    assert (args[0].data.get(ATTR_NAME) == 'test')
    assert (args[0].data.get(ATTR_ENTITY_ID) == 'script.test')
    (args, kwargs) = event_mock.call_args
    assert (args[0].context == context)
    state = hass.states.get('script.test')
    assert (state is not None)
    assert (state.context == context)