예제 #1
0

RANK_CASES = [(score, _compute_cc_rank(score)) for score in range(-1, 100)]


@pytest.mark.parametrize('score,expected_rank', RANK_CASES)
def test_rank(score, expected_rank):
    if (hasattr(expected_rank, '__call__') and
            isinstance(expected_rank(), Exception)):
        with pytest.raises(expected_rank):
            cc_rank(score)
    else:
        assert cc_rank(score) == expected_rank


fun = lambda complexity: Function('randomname', 1, 4, 23, False, None, [], complexity)
cls = lambda complexity: Class('randomname_', 3, 21, 18, [], [], complexity)

# This works with both the next two tests
SIMPLE_BLOCKS = [
    ([], [], 0.),
    ([fun(12), fun(14), fun(1)], [1, 0, 2], 9.),
    ([fun(4), cls(5), fun(2), cls(21)], [3, 1, 0, 2], 8.),
]


@pytest.mark.parametrize('blocks,indices,_', SIMPLE_BLOCKS)
def test_sorted_results(blocks, indices, _):
    expected_result = list(map(get_index(blocks), indices))
    assert sorted_results(blocks) == expected_result
예제 #2
0
    assert_pequal(
        iter_files(['file.py', 'random/path'], None, 'tests'),
        ['file.py', 'amod.py', 'test_all.py', 'sub/amod.py', 'sub/bmod.py'],
    )

    assert_pequal(
        iter_files(['file.py', 'random/path'], None, 'tests,sub'),
        ['file.py', 'amod.py', 'test_all.py'],
    )
    tools._is_python_file = _orig_is_python_file
    os_mod.walk = _orig_walk


CC_RESULTS_CASES = [
    (
        Function('name', 12, 0, 16, False, None, [], 6),
        {
            'type': 'function',
            'name': 'name',
            'lineno': 12,
            'col_offset': 0,
            'endline': 16,
            'closures': [],
            'complexity': 6,
            'rank': 'B',
        },
    ),
    (
        Class(
            'Classname',
            17,