Passed
Pull Request — master (#2)
by Yang
02:09
created

test_DICOM_RequireDecompression()   B

Complexity

Conditions 6

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 8.6666
c 0
b 0
f 0
cc 6
nop 0
1
import os
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM does not conform to the module naming conventions ((([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import sys
3
import logging
4
import unittest
5
6
from DICOM.validate import DICOM_validator
0 ignored issues
show
introduced by
Unable to import 'DICOM.validate'
Loading history...
7
from DICOM.decompress import DICOM_RequireDecompression, DICOM_decompress
0 ignored issues
show
introduced by
Unable to import 'DICOM.decompress'
Loading history...
8
from DICOM.anonymize import DICOM_anonymizer
0 ignored issues
show
introduced by
Unable to import 'DICOM.anonymize'
Loading history...
9
from DICOM.elements import DICOM_retrieveElements, DICOM_updateElement, DICOM_retrieveMRN, DICOM_computeScanAge
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
introduced by
Unable to import 'DICOM.elements'
Loading history...
10
from pydicom.data import get_testdata_files
11
12
13
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
14
15
def get_test_DICOM_path():
0 ignored issues
show
Coding Style Naming introduced by
The name get_test_DICOM_path does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
16
    filename = get_testdata_files("rtplan.dcm")[0]
17
    return filename
18
19
def test_DICOM_decompress():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_decompress does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
20
21
    logger = logging.getLogger(__name__)
22
23
    # Get all test files with "JPEG" in them.
24
    file_names = get_testdata_files("[Jj][Pp][Ee][Gg]")
25
26
    logger.info("List of files to try to decompress:")
27
    logger.info(file_names)
28
29
    success_counter = 0
30
    fail_counter = 0
31
32
    for file in file_names:
33
        logger.info("Processing: " + file)
34
35
        decompressed_file = file+"DECOM"
36
37
        success, reason = DICOM_decompress(file, decompressed_file)
38
39
        logger.info(reason)
40
41
        if success:
42
            success_counter += 1
43
            os.remove(decompressed_file) # restore the test environment to its former state.
44
            logger.info("Successful.")
45
        else:
46
            fail_counter += 1
47
            logger.info("Failed. Reason:" + reason)
48
    assert success_counter == 7 # within the test data folder, there should be SEVEN files with JPEG in their name that CAN be successfully loaded.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (147/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
49
    assert fail_counter == 4 # within the test data folder, there should be FOUR files with JPEG in their name that CANNOT be successfully loaded.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (146/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
50
51
def test_DICOM_validator():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_validator does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
52
53
    file_name = get_test_DICOM_path()
54
    success, data = DICOM_validator(file_name)
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
55
    assert success
56
57
    file_name = get_testdata_files("README.txt")[0]
58
    success, data = DICOM_validator(file_name)
59
    assert not success
60
61
def test_DICOM_RequireDecompression():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_RequireDecompression does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
62
    assert not (DICOM_RequireDecompression('1.2.840.10008.1.2'))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
63
    assert not (DICOM_RequireDecompression('1.2.840.10008.1.2.1'))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
64
    assert not (DICOM_RequireDecompression('1.2.840.10008.1.2.2'))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
65
    assert (DICOM_RequireDecompression('1.2.840.10008.1.2.4'))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
66
    assert (DICOM_RequireDecompression('1.2.840.10008.1.2.4.57'))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
67
68
69
class MyTestCase(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
70
    def test_wrong_syntax(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
71
        self.assertRaises(ValueError, DICOM_RequireDecompression, 'FakeTest')
72
73
74
def test_DICOM_anonymizer():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_anonymizer does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
75
    file_names = get_testdata_files("emri")
76
    for file_name in file_names:
77
        success = DICOM_anonymizer(file_name, "CNBP0010001")
78
        assert success
79
    for file_name in file_names:
80
        success, value = DICOM_retrieveElements(file_name, "PatientID")
81
        assert success
82
        assert (value == "CNBP0010001")
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
83
84
85
def test_DICOM_retrieveMRN():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_retrieveMRN does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
86
    path = get_testdata_files("emri_small_big_endian")[0]
87
    success, MRN = DICOM_retrieveMRN(path)
0 ignored issues
show
Coding Style Naming introduced by
The name MRN does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
88
    assert success
89
    assert (MRN == 'CNBP0010001')
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
90
91
92
def test_DICOM_update():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_update does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
93
    path = get_testdata_files("emri")
94
    for file in path:
95
        success, _ = DICOM_updateElement(file, "PatientBirthDate", "19950101", file)
96
        assert success
97
98
    for file in path:
99
        success, value = DICOM_retrieveElements(file, "PatientBirthDate")
100
        assert success
101
        assert(value == "19950101")
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
102
103
def test_DICOM_computerScanAge():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_computerScanAge does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
104
    logger = logging.getLogger("DICOM compute age")
105
    path = get_testdata_files("emri_small_RLE")[0]
106
    success, Age = DICOM_computeScanAge(path)
0 ignored issues
show
Coding Style Naming introduced by
The name Age does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
107
    assert success
108
    logger.info(Age.day)
109
110
111
if __name__ == '__main__':
112
    test_DICOM_decompress()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...