Passed
Push — master ( 5bd2df...d8239a )
by
unknown
01:16
created

test_usage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 41.56 %

Importance

Changes 0
Metric Value
wmc 5
eloc 61
dl 32
loc 77
rs 10
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A test_read_dict_without_inheritance2() 10 10 1
A test_read_dict_with_inheritance() 12 12 1
A test_read_dict_with_inheritance2() 0 12 1
A test_read_dict_without_inheritance() 10 10 1
A test_constructor() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from opinionated_configparser import OpinionatedConfigParser
2
3
4
TEST_DICT1 = {
5
    "_common": {
6
        "key1[foo_bar_1]": "value6",
7
        "key3": "value7",
8
        "key4": "value8"
9
    },
10
    "section1": {
11
        "key1": "value1",
12
        "key1[foo]": "value2",
13
        "key1[foo_bar]": "value3",
14
        "key2": "value4"
15
    },
16
    "section2": {
17
        "key3": "value5"
18
    }
19
}
20
21
22
def test_constructor():
23
    x = OpinionatedConfigParser()
24
    assert x is not None
25
26
27 View Code Duplication
def test_read_dict_without_inheritance():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
28
    x = OpinionatedConfigParser(configuration_name="foo")
29
    x.read_dict(TEST_DICT1)
30
    assert x.get("section1", "key1") == "value2"
31
    assert x.get("section1", "key2") == "value4"
32
    assert x.get("section1", "key3", fallback=None) is None
33
    assert x.get("section1", "key4", fallback=None) is None
34
    assert x.get("section2", "key1", fallback=None) is None
35
    assert x.get("section2", "key3") == "value5"
36
    assert x.get("section2", "key4", fallback=None) is None
37
38
39 View Code Duplication
def test_read_dict_without_inheritance2():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
    x = OpinionatedConfigParser(configuration_name="foo_foo_foo_foo")
41
    x.read_dict(TEST_DICT1)
42
    assert x.get("section1", "key1") == "value2"
43
    assert x.get("section1", "key2") == "value4"
44
    assert x.get("section1", "key3", fallback=None) is None
45
    assert x.get("section1", "key4", fallback=None) is None
46
    assert x.get("section2", "key1", fallback=None) is None
47
    assert x.get("section2", "key3") == "value5"
48
    assert x.get("section2", "key4", fallback=None) is None
49
50
51 View Code Duplication
def test_read_dict_with_inheritance():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
52
    x = OpinionatedConfigParser(configuration_name="foo",
53
                                default_section="_common")
54
    x.read_dict(TEST_DICT1)
55
    assert x.get("section1", "key1") == "value2"
56
    assert x.get("section1", "key2") == "value4"
57
    assert x.get("section1", "key3") == "value7"
58
    assert x.get("section1", "key4") == "value8"
59
    assert x.get("section2", "key1", fallback=None) is None
60
    assert x.get("section2", "key3") == "value5"
61
    assert x.get("section1", "key4") == "value8"
62
    assert x.get("_common", "key3", fallback=None) is None
63
64
65
def test_read_dict_with_inheritance2():
66
    x = OpinionatedConfigParser(configuration_name="foo_bar_1",
67
                                default_section="_common")
68
    x.read_dict(TEST_DICT1)
69
    assert x.get("section1", "key1") == "value6"
70
    assert x.get("section1", "key2") == "value4"
71
    assert x.get("section1", "key3") == "value7"
72
    assert x.get("section1", "key4") == "value8"
73
    assert x.get("section2", "key1") == "value6"
74
    assert x.get("section2", "key3") == "value5"
75
    assert x.get("section1", "key4") == "value8"
76
    assert x.get("_common", "key3", fallback=None) is None
77