| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Tests for precq exonerating code.""" |
| |
| from __future__ import absolute_import |
| from __future__ import division |
| from __future__ import print_function |
| |
| import pytest |
| |
| from exonerator import gerrit_precq |
| from exonerator import gerrit_cq_test |
| |
| |
| REMOVED_BY_HUMAN = 'Trybot-Ready_removed_by_human_*.json' |
| REMOVED_BY_BOT = 'Trybot-Ready_removed_by_bot_*.json' |
| READY = 'precq_ready_for_exoneration_*.json' |
| NOT_READY = 'precq_not_ready_for_exoneration_*.json' |
| |
| GlobChangeDetails = gerrit_cq_test.GlobChangeDetails |
| |
| |
| # pylint: disable=protected-access |
| @pytest.mark.parametrize('change_details', GlobChangeDetails(READY)) |
| def TestReady(change_details): |
| """Test cases that are ready to exonerate.""" |
| # Pass 99 in as the "known_patch_number" - this will work as long as |
| # known_patch_number is greater-or-equal to the largest patch number in |
| # change_details. |
| assert bool(gerrit_precq._LabelIfShouldExonerate(change_details, 99)) |
| |
| |
| @pytest.mark.parametrize('change_details', GlobChangeDetails(NOT_READY)) |
| def TestNotReady(change_details): |
| """Test cases that are not ready to exonerate.""" |
| # Pass 99 in as the "known_patch_number" - this will work as long as |
| # known_patch_number is greater-or-equal to the largest patch number in |
| # change_details. |
| assert gerrit_precq._LabelIfShouldExonerate(change_details, 99) is None |
| |
| |
| @pytest.mark.parametrize('change_details', GlobChangeDetails(REMOVED_BY_HUMAN)) |
| def TestRemovedByHuman(change_details): |
| """If the Trybot-Ready label was removed by a human, don't exonerate.""" |
| assert not gerrit_precq._LabelToReapply(change_details) |
| assert not gerrit_precq._LabelIfShouldExonerate(change_details, 99) |
| |
| |
| @pytest.mark.parametrize('change_details', GlobChangeDetails(REMOVED_BY_BOT)) |
| def TestRemovedByBot(change_details): |
| """If the Trybot-Ready label was removed by a bot, can exonerate.""" |
| assert gerrit_precq._LabelToReapply(change_details) |
| assert gerrit_precq._LabelIfShouldExonerate(change_details, 99) |