tests   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 48.72 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
dl 19
loc 39
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A init_result_dir() 19 19 4

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
3
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
4
TEST_RESULTS_DIR = os.path.join(os.path.dirname(__file__), 'results')
5
6
IMG_NAME = 'floor plan.png'
7
IMG_PATH = os.path.join(TEST_DATA_DIR, IMG_NAME)
8
9
IMG_NAME_JPEG = 'elevation.jpg'
10
IMG_PATH_JPEG = os.path.join(TEST_DATA_DIR, IMG_NAME_JPEG)
11
12
WTR_NAME = 'watermark.png'
13
WTR_PATH = os.path.join(TEST_DATA_DIR, WTR_NAME)
14
15
16 View Code Duplication
def init_result_dir(sub_folder):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
    """
18
    Initialize test result file destination directory.
19
20
    If the directory exists, delete the files it contains.
21
    Else, create the directory.
22
    """
23
    # Confirm 'results' folder exists
24
    if not os.path.isdir(TEST_RESULTS_DIR):
25
        os.mkdir(TEST_RESULTS_DIR)
26
27
    # Confirm the sub-folder exists and remove its contents, otherwise make the folder
28
    folder = os.path.join(TEST_RESULTS_DIR, sub_folder)
29
    if os.path.isdir(folder):
30
        for f in os.listdir(folder):
31
            os.remove(os.path.join(folder, f))
32
    else:
33
        os.mkdir(folder)
34
    return folder
35
36
37
__all__ = [
38
    'IMG_PATH', 'WTR_PATH', 'TEST_DATA_DIR', 'TEST_RESULTS_DIR', 'IMG_NAME_JPEG', 'IMG_PATH_JPEG', 'init_result_dir'
39
]
40