review/tests/test_check.py @ 2310846513b8

tests: factor out get_identifiers and log errors better
author Steve Losh <steve@stevelosh.com>
date Sat, 19 Jun 2010 15:43:22 -0400
parents fe2edf9c9098
children 01a47fb22911
from nose import with_setup
from util import setup_reviewed_sandbox, teardown_sandbox, review, should_fail_with

from .. import messages

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_empty():
    review(check=True)

    output = review(check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, no=True, message='.')
    output = review(check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, yes=False, message='.', force=True)
    output = review(check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(comment=True, message='.')
    output = review(check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_empty_non_tip():
    review(rev='0', check=True)

    output = review(rev='0', check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=False, message='.')
    output = review(rev='0', check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, message='.')
    output = review(rev='0', check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

    review(comment=True, message='.')
    output = review(rev='0', check=True, verbose=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_no_nos():
    output = review(check=True, verbose=True, no_nos=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, no=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True)

    review(signoff=True, yes=True, message='.', force=True)
    output = review(check=True, verbose=True, no_nos=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_yeses():
    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1')

    output = review(check=True, verbose=True, yeses='0')
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, yeses='1')
    assert messages.CHECK_SUCCESS in output

    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='2')

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_seen():
    should_fail_with(messages.CHECK_UNSEEN, check=True, verbose=True, seen=True)

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

    review(signoff=True, no=True, message='.', force=True)
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

    should_fail_with(messages.CHECK_UNSEEN, rev='0', check=True, verbose=True, seen=True)

    review(rev='0', comment=True, message='.')
    output = review(check=True, verbose=True, seen=True)
    assert messages.CHECK_SUCCESS in output

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_priority_no_nos():
    review(signoff=True, no=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, yeses='0')
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True)
    should_fail_with(messages.CHECK_HAS_NOS, check=True, verbose=True, no_nos=True, seen=True, yeses='0')

    review(signoff=True, yes=True, message='.', force=True)
    output = review(check=True, verbose=True, no_nos=True, seen=True, yeses='0')
    assert messages.CHECK_SUCCESS in output

    review(rev='0', signoff=True, no=True, message='.')
    review(rev='0', comment=True, message='.')
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True)
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True)
    should_fail_with(messages.CHECK_HAS_NOS, rev='0', check=True, verbose=True, no_nos=True, seen=True, yeses='0')

@with_setup(setup_reviewed_sandbox, teardown_sandbox)
def test_check_priority_yeses():
    review(comment=True, message='.')
    should_fail_with(messages.CHECK_TOO_FEW_YESES, check=True, verbose=True, yeses='1', seen=True)

    review(signoff=True, yes=True, message='.')
    output = review(check=True, verbose=True, yeses='1', seen=True)
    assert messages.CHECK_SUCCESS in output

    # TODO: For multiple signoffs, no_nos should take priority over "yes" signoffs.