Passed
Push — master ( 895128...fcc2df )
by Fabien
01:21
created

test_envtpl   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 55.56 %

Importance

Changes 0
Metric Value
wmc 5
eloc 28
dl 20
loc 36
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A test_envtpl() 10 10 3
A test_envtpl2() 10 10 2

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
import os
2
import pytest
3
from opinionated_configparser import render_string
4
from opinionated_configparser import OpinionatedConfigParser
5
6
7
TEST_DICT1 = {
8
    "section1": {
9
        "key1": "value1{{ENV_VAR}}",
10
    }
11
}
12
13
14 View Code Duplication
def test_envtpl():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    if "ENV_VAR" in os.environ:
16
        del os.environ["ENV_VAR"]
17
    x = OpinionatedConfigParser(use_envtpl=True)
18
    x.read_dict(TEST_DICT1)
19
    try:
20
        render_string("foo")
21
    except Exception:
22
        pytest.skip("envtpl support missing => skipping")
23
    assert x.get("section1", "key1") == "value1"
24
25
26 View Code Duplication
def test_envtpl2():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
    os.environ["ENV_VAR"] = "foo"
28
    x = OpinionatedConfigParser(use_envtpl=True)
29
    x.read_dict(TEST_DICT1)
30
    try:
31
        render_string("foo")
32
    except Exception:
33
        pytest.skip("envtpl support missing => skipping")
34
    assert x.get("section1", "key1") == "value1foo"
35
    del os.environ["ENV_VAR"]
36