GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

test_excluded_logging()   F
last analyzed

Complexity

Conditions 14

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
c 1
b 0
f 0
dl 0
loc 31
rs 2.7581

How to fix   Complexity   

Complexity

Complex classes like test_excluded_logging() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import pytest
2
import sys
3
4
from tests.conftest import EmptyPlugin, get_test_data_path
5
6
7
@pytest.mark.parametrize('orientation', ['column_based', 'row_based'])
8
def test_filtering(empty_app, caplog, orientation):
9
    plugin = EmptyPlugin(empty_app)
10
    workbook_path = get_test_data_path(orientation + '.xlsx')
11
    config_path = get_test_data_path(orientation + '.json')
12
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
13
    assert 2 in data
14
    assert data[2]['Enum'] == 'ape'
15
    assert 3 not in data
16
    assert 4 in data
17
    assert data[4]['Enum'] == 'cat'
18
    if orientation == 'column_based':
19
        assert 'The row 3 was excluded due to an exclude filter on cell B3 (dog not in [ape, cat])' in caplog.text()
20
    else:
21
        assert 'The column 3 was excluded due to an exclude filter on cell C2 (dog not in [ape, cat])' in caplog.text()
22
23
24
@pytest.mark.parametrize('path, config', [
25
    ('excluded_fail_on_type_error.xlsx', 'excluded_fail_on_type_error.json'),
26
    ('excluded_fail_on_empty_cell.xlsx', 'excluded_fail_on_empty_cell.json')
27
])
28
def test_excluded_fail_on_errors(empty_app, path, config):
29
    plugin = EmptyPlugin(empty_app)
30
    workbook_path = get_test_data_path(path)
31
    config_path = get_test_data_path(config)
32
    with pytest.raises(ValueError):
33
        plugin.excel_validation.read_excel(config_path, workbook_path)
34
35
36
@pytest.mark.parametrize('activation_state', ['enable', 'disable'])
37
def test_excluded_logging(empty_app, caplog, activation_state):
38
    plugin = EmptyPlugin(empty_app)
39
    workbook_path = get_test_data_path('excluded_logging.xlsx')
40
    config_path = get_test_data_path('excluded_' + activation_state + '_logging.json')
41
    data = plugin.excel_validation.read_excel(config_path, workbook_path)
42
    assert 2 in data
43
    assert data[2]['Enum'] == 'ape'
44
    assert 3 not in data
45
    assert 4 in data
46
    assert data[4]['Enum'] == 'cat'
47
    assert 'The row 3 was excluded due to an exclude filter on cell B3 (dog not in [ape, cat])' in caplog.text()
48
49
    if sys.version.startswith('2.7'):
50
        str_type = 'unicode'
51
        type_class = 'type'
52
    elif sys.version.startswith('3'):
53
        str_type = 'str'
54
        type_class = 'class'
55
    else:
56
        raise RuntimeError('This test case does only support Python 2.7 and 3.x')
57
58
    msg1 = "The value Text in cell A3 is of type <{0} '{1}'>; required by specification " \
59
           "is datetime".format(type_class, str_type)
60
    msg2 = "The 'Text' in cell E3 is empty"
61
    if activation_state == 'enable':
62
        assert msg1 in caplog.text()
63
        assert msg2 in caplog.text()
64
    else:
65
        assert msg1 not in caplog.text()
66
        assert msg2 not in caplog.text()
67