| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 55.56 % |
| Changes | 0 | ||
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(): |
|
|
|
|||
| 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(): |
|
| 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 |