Passed
Pull Request — master (#3)
by Yang
04:58
created

Python.DICOM.test_DICOM.test_DICOM_update()   B

Complexity

Conditions 6

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
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.decompress import DICOM_decompress
0 ignored issues
show
introduced by
Unable to import 'DICOM.decompress'
Loading history...
7
from DICOM.anonymize import DICOM_anonymize
0 ignored issues
show
introduced by
Unable to import 'DICOM.anonymize'
Loading history...
8
from DICOM.elements import DICOM_elements
0 ignored issues
show
introduced by
Unable to import 'DICOM.elements'
Loading history...
9
from pydicom.data import get_testdata_files
10
11
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
12
13
14
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...
15
    filename = get_testdata_files("rtplan.dcm")[0]
16
    return filename
17
18
19
class UT_DICOMManipulation(unittest.TestCase):
0 ignored issues
show
Coding Style Naming introduced by
The name UT_DICOMManipulation does not conform to the class naming conventions ([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 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...
20
21
    @staticmethod
22
    def test_DICOM_decompress():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_decompress does not conform to the method 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 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...
23
24
        logger = logging.getLogger(__name__)
25
26
        # Get all test files with "JPEG" in them.
27
        file_names = get_testdata_files("[Jj][Pp][Ee][Gg]")
28
29
        logger.info("List of files to try to decompress:")
30
        logger.info(file_names)
31
32
        success_counter = 0
33
        fail_counter = 0
34
35
        for file in file_names:
36
            logger.info("Processing: " + file)
37
38
            decompressed_file = file+"DECOM"
39
40
            success, reason = DICOM_decompress.save_as(file, decompressed_file)
41
42
            logger.info(reason)
43
44
            if success:
45
                success_counter += 1
46
                os.remove(decompressed_file) # restore the test environment to its former state.
47
                logger.info("Successful.")
48
            else:
49
                fail_counter += 1
50
                logger.info("Failed. Reason:" + reason)
51
        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 (151/100).

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

Loading history...
52
        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 (150/100).

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

Loading history...
53
54
    @staticmethod
55
    def test_DICOM_RequireDecompression():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_RequireDecompression does not conform to the method 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 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...
56
        assert not (DICOM_decompress.check_decompression('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...
57
        assert not (DICOM_decompress.check_decompression('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...
58
        assert not (DICOM_decompress.check_decompression('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...
59
        assert (DICOM_decompress.check_decompression('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...
60
        assert (DICOM_decompress.check_decompression('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...
61
62
63
64
        def test_wrong_syntax(self):
0 ignored issues
show
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...
Unused Code introduced by
The variable test_wrong_syntax seems to be unused.
Loading history...
65
            self.assertRaises(ValueError, DICOM_decompress.check_decompression, 'FakeTest')
66
67
    @staticmethod
68
    def test_DICOM_anonymizer():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_anonymizer does not conform to the method 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 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...
69
        file_names = get_testdata_files("emri")
70
        for file_name in file_names:
71
            success = DICOM_anonymize.save(file_name, "CNBP0010001")
72
            assert success
73
        for file_name in file_names:
74
            success, value = DICOM_elements.retrieve(file_name, "PatientID")
75
            assert success
76
            assert (value == "CNBP0010001")
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
77
78
    @staticmethod
79
    def test_DICOM_retrieveMRN():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_retrieveMRN does not conform to the method 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 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...
80
        path = get_testdata_files("emri_small_big_endian")[0]
81
        success, MRN = DICOM_elements.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...
82
        assert success
83
        assert (MRN == 'CNBP0010001')
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
84
85
    @staticmethod
86
    def test_DICOM_update():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_update does not conform to the method 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 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...
87
        path = get_testdata_files("emri")
88
        for file in path:
89
            success, _ = DICOM_elements.update(file, "PatientBirthDate", "19950101", file)
90
            assert success
91
92
        for file in path:
93
            success, value = DICOM_elements.retrieve(file, "PatientBirthDate")
94
            assert success
95
            assert(value == "19950101")
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
96
97
    @staticmethod
98
    def test_DICOM_computerScanAge():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_computerScanAge does not conform to the method 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 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...
99
        logger = logging.getLogger("DICOM compute age")
100
        path = get_testdata_files("emri_small_RLE")[0]
101
        success, Age = DICOM_elements.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...
102
        assert success
103
        logger.info(Age.day)
104
105
    @staticmethod
106
    def test_DICOM_check_dependency():
0 ignored issues
show
Coding Style Naming introduced by
The name test_DICOM_check_dependency does not conform to the method 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 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...
107
        logger = logging.getLogger("Checking vital system path dependencies:")
108
        import subprocess
109
110
        try:
111
            # SUPER IMPORTANT! MAKE SURE DCMDJPEG is in the system path!
112
            subprocess.check_output(['dcmdjpeg'])
113
        # When dcmdjpeg has errors
114
        except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e 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...
115
            logger.info(e)
116
            ErrorMessage = "DCMDJPEG decompression call failed! Make sure DCMDJPEG is in your SYSTEMOS PATH. "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
Coding Style Naming introduced by
The name ErrorMessage 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...
117
            logger.info(ErrorMessage)
118
            raise ImportError
119
120
        try:
121
            # SUPER IMPORTANT! MAKE SURE DCMDJPEG is in the system path!
122
            subprocess.check_output(['dcm2niix'])
123
        # When dcmdjpeg has errors
124
        except Exception as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e 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...
125
            logger.info(e)
126
            ErrorMessage = "DCMDJPEG decompression call failed! Make sure DCMDJPEG is in your SYSTEMOS PATH. "
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
Coding Style Naming introduced by
The name ErrorMessage 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...
127
            logger.info(ErrorMessage)
128
            raise ImportError
129
130
        assert(True)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
131
132
if __name__ == '__main__':
133
    UT_DICOMManipulation.test_DICOM_check_dependency()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...