Example #1
0
def test_status_magic():
    """ Generator for testing magic methods in the Status class """
    obj = status.Status('foo', 0, (0, 0))
    comparitor = status.Status('bar', 10, (0, 0))

    for func, name, result in [
            (str, 'str', 'foo'),
            (unicode, 'unicode', u'foo'),
            (repr, 'repr', 'foo'),
            (int, 'int', 0)]:
        check_operator.description = 'Operator {0} works on class {1}'.format(
            str(func), 'status.Status')
        yield check_operator, obj, func, result

    for func, name in [
            (lambda x, y: x.__lt__(y), 'lt'),
            (lambda x, y: y.__gt__(x), 'gt')]:

        check_operator_equal.description = \
            'Operator {0} works on class {1} when True'.format(
                name, 'status.Status')
        yield check_operator_equal, obj, comparitor, func, True

    for func, name in [
            (lambda x, y: x.__le__(x), 'le, when ='),
            (lambda x, y: x.__le__(y), 'le, when !='),
            (lambda x, y: x.__eq__(x), 'eq'),
            (lambda x, y: x.__ge__(x), 'ge, when ='),
            (lambda x, y: y.__ge__(x), 'ge, when !='),
            (lambda x, y: x.__ne__(y), 'ne'),
            (lambda x, y: x.__eq__(x), 'eq')]:
        check_operator_not_equal.description = \
            'Operator {0} works on class {1} when False'.format(
                name, 'status.Status')
        yield check_operator_not_equal, obj, comparitor, func, False
Example #2
0
def test_nochangestatus_magic():
    """ Test that operators unique to NoChangeStatus work """
    obj = status.NoChangeStatus('Test')
    stat = status.Status('Test', 0, (0, 0))

    # generator equality tests
    for comp, type_ in [(obj, 'status.NoChangeStatus'),
                        (stat, 'status.Status'), ('Test', 'unicode')]:
        check_operator_equal.description = (
            'Status.NoChangeStatus: Operator eq works with type: {}'.format(
                type_))
        yield check_operator_equal, obj, comp, lambda x, y: x.__eq__(y), True

        check_operator_not_equal.description = (
            'status.NoChangeStatus: Operator ne works with type: {}'.format(
                type_))
        yield check_operator_not_equal, obj, comp, lambda x, y: x.__ne__(
            y), True
Example #3
0
@pytest.mark.parametrize('new,old', FIXES)
def test_fixes(new, old):
    assert status.status_lookup(new) > status.status_lookup(old)


@pytest.mark.parametrize('new,old', itertools.permutations(STATUSES, 2))
def test_changes(new, old):
    assert status.status_lookup(new) != status.status_lookup(old)


@pytest.mark.parametrize('new,old', itertools.permutations(NO_OPS, 2))
def test_no_change(new, old):
    new = status.status_lookup(new)
    old = status.status_lookup(old)
    assert not new < old
    assert not new > old


@pytest.mark.parametrize("stat,op,expected", [
    (status.Status('Test', 0, (0, 0)), str, 'Test'),
    (status.Status('Test', 0, (0, 0)), bytes, b'Test'),
    (status.Status('Test', 0, (0, 0)), int, 0),
    (status.Status('Test', 0, (0, 0)), repr, 'Status("Test", 0, (0, 0))'),
    (status.Status('Test', 0, (0, 0)), hash, hash('Test')),
    (status.NoChangeStatus('No'), hash, hash('No')),
])
def test_status_comparisons(stat, op, expected):
    """Test status.Status equality protocol."""
    assert op(stat) == expected
Example #4
0
def initialize_status():
    """ status.Status inializes """
    test = status.Status('test', 1)
    assert test
Example #5
0
def initialize_status():
    """status.Status: class inializes"""
    status.Status('test', 1)
Example #6
0
@pytest.mark.parametrize('new,old', FIXES)
def test_fixes(new, old):
    assert status.status_lookup(new) > status.status_lookup(old)


@pytest.mark.parametrize('new,old', itertools.permutations(STATUSES, 2))
def test_changes(new, old):
    assert status.status_lookup(new) != status.status_lookup(old)


@pytest.mark.parametrize('new,old', itertools.permutations(NO_OPS, 2))
def test_no_change(new, old):
    new = status.status_lookup(new)
    old = status.status_lookup(old)
    assert not new < old
    assert not new > old


@pytest.mark.parametrize("stat,op,expected", [
    (status.Status('Test', 0, (0, 0)), six.text_type, 'Test'),
    (status.Status('Test', 0, (0, 0)), six.binary_type, b'Test'),
    (status.Status('Test', 0, (0, 0)), int, 0),
    (status.Status('Test', 0, (0, 0)), repr, 'Status("Test", 0, (0, 0))'),
    (status.Status('Test', 0, (0, 0)), hash, hash('Test')),
    (status.NoChangeStatus('No'), hash, hash('No')),
])
def test_status_comparisons(stat, op, expected):
    """Test status.Status equality protocol."""
    assert op(stat) == expected