def test_purge_method(hass, hass_recorder):
    'Test purge method.'
    hass = hass_recorder()
    service_data = {'keep_days': 4}
    _add_test_events(hass)
    _add_test_states(hass)
    _add_test_recorder_runs(hass)
    with session_scope(hass=hass) as session:
        states = session.query(States)
        assert (states.count() == 6)
        events = session.query(Events).filter(Events.event_type.like('EVENT_TEST%'))
        assert (events.count() == 6)
        recorder_runs = session.query(RecorderRuns)
        assert (recorder_runs.count() == 7)
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        hass.services.call('recorder', 'purge')
        hass.block_till_done()
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        assert (states.count() == 4)
        assert (events.count() == 4)
        hass.services.call('recorder', 'purge', service_data=service_data)
        hass.block_till_done()
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        assert (states.count() == 2)
        assert (events.count() == 2)
        assert (recorder_runs.count() == 3)
        assert (not ('EVENT_TEST_PURGE' in (event.event_type for event in events.all())))
        with patch('homeassistant.components.recorder.purge._LOGGER') as mock_logger:
            service_data['repack'] = True
            hass.services.call('recorder', 'purge', service_data=service_data)
            hass.block_till_done()
            hass.data[DATA_INSTANCE].block_till_done()
            wait_recording_done(hass)
            assert (mock_logger.debug.mock_calls[5][1][0] == 'Vacuuming SQL DB to free space')
Test purge method.
def test_purge_method(hass, hass_recorder):
    
    hass = hass_recorder()
    service_data = {'keep_days': 4}
    _add_test_events(hass)
    _add_test_states(hass)
    _add_test_recorder_runs(hass)
    with session_scope(hass=hass) as session:
        states = session.query(States)
        assert (states.count() == 6)
        events = session.query(Events).filter(Events.event_type.like('EVENT_TEST%'))
        assert (events.count() == 6)
        recorder_runs = session.query(RecorderRuns)
        assert (recorder_runs.count() == 7)
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        hass.services.call('recorder', 'purge')
        hass.block_till_done()
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        assert (states.count() == 4)
        assert (events.count() == 4)
        hass.services.call('recorder', 'purge', service_data=service_data)
        hass.block_till_done()
        hass.data[DATA_INSTANCE].block_till_done()
        wait_recording_done(hass)
        assert (states.count() == 2)
        assert (events.count() == 2)
        assert (recorder_runs.count() == 3)
        assert (not ('EVENT_TEST_PURGE' in (event.event_type for event in events.all())))
        with patch('homeassistant.components.recorder.purge._LOGGER') as mock_logger:
            service_data['repack'] = True
            hass.services.call('recorder', 'purge', service_data=service_data)
            hass.block_till_done()
            hass.data[DATA_INSTANCE].block_till_done()
            wait_recording_done(hass)
            assert (mock_logger.debug.mock_calls[5][1][0] == 'Vacuuming SQL DB to free space')