Completed
Push — master ( a208b6...2c60dc )
by Kolen
01:08
created

test_check_table_options()   F

Complexity

Conditions 10

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 10
c 2
b 0
f 1
dl 0
loc 43
rs 3.1304

How to fix   Complexity   

Complexity

Complex classes like test_check_table_options() 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
#!/usr/bin/env python3
2
"""
3
`header` and `markdown` is checked by `test_to_bool` instead
4
"""
5
from .context import init_table_options, check_table_options
6
7
8
def test_check_table_options():
9
    init_options = {}
10
    init_table_options(init_options)
11
    options = init_options.copy()
12
    # check init is preserved
13
    check_table_options(options)
14
    assert options == init_options
15
    # check width
16
    # negative width
17
    options['width'] = [0.1, -0.2]
18
    check_table_options(options)
19
    assert options['width'] is None
20
    # invalid width
21
    options['width'] = "happy"
22
    check_table_options(options)
23
    assert options['width'] is None
24
    # invalid width 2
25
    options['width'] = ["happy", "birthday"]
26
    check_table_options(options)
27
    assert options['width'] is None
28
    # check table-width
29
    # negative table-width
30
    options['table-width'] = -1
31
    check_table_options(options)
32
    assert options['table-width'] == 1.0
33
    # invalid table-width
34
    options['table-width'] = "happy"
35
    check_table_options(options)
36
    assert options['table-width'] == 1.0
37
    # check include
38
    # invalid include: file doesn't exist
39
    options['include'] = 'abc.xyz'
40
    check_table_options(options)
41
    assert options['include'] is None
42
    # invalid include: wrong type
43
    options['include'] = True
44
    check_table_options(options)
45
    assert options['include'] is None
46
    # valid include
47
    options['include'] = 'tests/csv_tables.csv'
48
    check_table_options(options)
49
    assert options['include'] == 'tests/csv_tables.csv'
50
    return
51