def get_previous_release(current_release): """ Return the previously active release from the history file """ releases = list_releases() try: current_index = last_index(releases, current_release) previous_index = current_index - 1 if previous_index < 0: return None else: return releases[previous_index] except ValueError: # raised if the current release is not found return None
def test_last_index_empty(): with pytest.raises(ValueError): last_index([], 1)
def test_last_index(): assert last_index([1, 1], 1) == 1 assert last_index([1, 1, 2], 1) == 1
def test_last_index_missing(): with pytest.raises(ValueError): last_index([1], 2)