def test_purge_old_states(hass, hass_recorder):
    'Test deleting old states.'
    hass = hass_recorder()
    _add_test_states(hass)
    with session_scope(hass=hass) as session:
        states = session.query(States)
        assert (states.count() == 6)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert (not finished)
        assert (states.count() == 4)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert (not finished)
        assert (states.count() == 2)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert finished
        assert (states.count() == 2)
Test deleting old states.
def test_purge_old_states(hass, hass_recorder):
    
    hass = hass_recorder()
    _add_test_states(hass)
    with session_scope(hass=hass) as session:
        states = session.query(States)
        assert (states.count() == 6)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert (not finished)
        assert (states.count() == 4)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert (not finished)
        assert (states.count() == 2)
        finished = purge_old_data(hass.data[DATA_INSTANCE], 4, repack=False)
        assert finished
        assert (states.count() == 2)