Skip to content

Commit

Permalink
Merge pull request #29 from ZviBaratz/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
ZviBaratz committed Jun 19, 2021
2 parents b866261 + fbfb18b commit a7f60d1
Show file tree
Hide file tree
Showing 98 changed files with 1,235 additions and 338 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
sudo apt install -y libmagic1
- name: Install libmagic (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install libmagic
run: brew install libmagic
- name: Install dependencies
run: |
python -m site
Expand All @@ -42,7 +41,7 @@ jobs:
run: python -m tox
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
if: "contains(env.USING_COVERAGE, matrix.python-version) && matrix.os == 'ubuntu-latest'"
if: "contains(env.USING_COVERAGE, matrix.python-version)"
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![PyPI version](https://img.shields.io/pypi/v/dicom_parser.svg)](https://pypi.python.org/pypi/pylabber/)
[![PyPI status](https://img.shields.io/pypi/status/dicom_parser.svg)](https://pypi.python.org/pypi/pylabber/)
[![GitHub Actions](https://github.com/ZviBaratz/dicom_parser/actions/workflows/tests.yml/badge.svg)](https://github.com/ZviBaratz/dicom_parser/actions/workflows/tests.yml)
[![codecov.io](https://codecov.io/gh/ZviBaratz/dicom_parser/coverage.svg?branch=master)](https://codecov.io/github/ZviBaratzabbingProject/dicom_parser?branch=master)
[![codecov.io](https://codecov.io/gh/ZviBaratz/dicom_parser/coverage.svg?branch=master)](https://codecov.io/github/ZviBaratz/dicom_parser?branch=master)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/ZviBaratz/dicom_parser.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/ZviBaratz/dicom_parser/context:python)
[![Documentation Status](https://readthedocs.org/projects/dicom-parser/badge/?version=latest)](http://dicom-parser.readthedocs.io/?badge=latest)

Expand Down
37 changes: 27 additions & 10 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
Release Notes
=============

1.0.2
1.1.0
-----
* Added *pyproject.toml* and *setup.cfg* files and created *src/* directory
* to conform with newer Python packaging standards.
* Updated project structure and packaging to conform with PEP517_ and
PEP518_.
* Migrated CI to `GitHub Actions`_.
* Fixed *dcm* generation by mime-type bug (`#30
<https://github.com/ZviBaratz/dicom_parser/issues/30>`_) for nested directories.
* Improved tests and increased coverage.

1.0.1
-----
Expand Down Expand Up @@ -120,12 +124,25 @@ First release!
:class:`~dicom_parser.utils.siemens.csa.header.CsaHeader` class.


.. _CSA Headers: https://nipy.org/nibabel/dicom/siemens_csa.html
.. _dcm2niix: https://github.com/rordenlab/dcm2niix
.. _django_dicom: https://github.com/TheLabbingProject/django_dicom
.. _isort: https://pycqa.github.io/isort/
.. _NIfTI: https://nifti.nimh.nih.gov/
.. _pydicom: https://github.com/pydicom/pydicom
.. _Siemens mosaic: https://nipy.org/nibabel/dicom/dicom_mosaic.html
.. _CSA Headers:
https://nipy.org/nibabel/dicom/siemens_csa.html
.. _dcm2niix:
https://github.com/rordenlab/dcm2niix
.. _django_dicom:
https://github.com/TheLabbingProject/django_dicom
.. _GitHub Actions:
https://github.com/ZviBaratz/dicom_parser/actions/workflows/tests.yml
.. _isort:
https://pycqa.github.io/isort/
.. _NIfTI:
https://nifti.nimh.nih.gov/
.. _PEP517:
https://www.python.org/dev/peps/pep-0517/
.. _PEP518:
https://www.python.org/dev/peps/pep-0518/
.. _pydicom:
https://github.com/pydicom/pydicom
.. _Siemens mosaic:
https://nipy.org/nibabel/dicom/dicom_mosaic.html
.. _value-representation (VR):
http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ exclude = '''
line-length = 79

[tool.coverage.run]
source = ["src/"]
source = ["dicom_parser"]
branch = true
omit = ["*tests*", ".tox/**", "venv/**", "setup.py"]
command_line = "-m pytest tests/"
omit = ["*tests*", "venv/**", "setup.py"]
command_line = "-m pytest tests"

[tool.coverage.paths]
source = ["src"]

[build-system]
requires = ["setuptools>=42", "wheel"]
Expand Down
12 changes: 7 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = dicom_parser
version = 1.0.2
version = 1.1.0
author = Zvi Baratz
author_email = z.baratz@gmail.com
description = DICOM files parser meant to facilitate data access.
Expand Down Expand Up @@ -48,8 +48,9 @@ all =
flake8~=3.7
ipython
isort~=5.8
pickle5~=0.0;python_version<="3.7"
pytest~=6.2
python-magic~=0.4
python-magic~=0.4;platform_system!="Windows"
sphinx~=4.0
sphinx-rtd-theme~=0.5
tox~=3.23
Expand All @@ -62,14 +63,15 @@ dev =
ipython
isort~=5.8
pytest~=6.2
python-magic~=0.4
python-magic~=0.4;platform_system!="Windows"
sphinx~=4.0
sphinx-rtd-theme~=0.5
tox~=3.23
test =
coverage[toml]~=5.5
pickle5~=0.0;python_version<="3.7"
pytest~=6.2
python-magic~=0.4
python-magic~=0.4;platform_system!="Windows"
tox~=3.23
dist =
build
Expand All @@ -78,7 +80,7 @@ docs =
sphinx~=4.0
sphinx-rtd-theme~=0.5
magic =
python-magic~=0.4
python-magic~=0.4;platform_system!="Windows"

[options.packages.find]
where = src
Expand Down
15 changes: 1 addition & 14 deletions src/dicom_parser/data_element.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Definition of the :class:`DataElement` class.
"""

import re
from typing import Any

Expand All @@ -19,11 +18,10 @@ class DataElement:
:mod:`~dicom_parser.data_elements`.
.. _pydicom: https://github.com/pydicom/pydicom
"""

VALUE_REPRESENTATION: ValueRepresentation = None
PRIVATE_ELEMENT_DESCRIPTION_PATTERN = r"\[(.*)\]|Private Creator"
PRIVATE_ELEMENT_DESCRIPTION_PATTERN: str = r"\[(.*)\]|Private Creator"

def __init__(self, raw: PydicomDataElement):
"""
Expand All @@ -34,7 +32,6 @@ def __init__(self, raw: PydicomDataElement):
raw : PydicomDataElement
pydicom's data element
"""

self.raw: PydicomDataElement = raw
self.tag: tuple = parse_tag(self.raw.tag)
self.keyword: str = self.parse_keyword()
Expand All @@ -53,7 +50,6 @@ def __repr__(self) -> str:
str
This instance's string representation
"""

return self.__str__()

def __str__(self) -> str:
Expand All @@ -65,7 +61,6 @@ def __str__(self) -> str:
str
This instance's string representation
"""

return self.to_series().to_string()

def get_private_element_keyword(self) -> str:
Expand All @@ -77,7 +72,6 @@ def get_private_element_keyword(self) -> str:
str
Private data element keyword
"""

pattern = self.PRIVATE_ELEMENT_DESCRIPTION_PATTERN
description = self.raw.description()
private_element_description = re.findall(pattern, description)
Expand All @@ -97,7 +91,6 @@ def parse_keyword(self) -> str:
str
This instance's keyword
"""

if self.raw.keyword == "":
return self.get_private_element_keyword()
return self.raw.keyword
Expand All @@ -117,7 +110,6 @@ def parse_value(self, value: Any) -> Any:
Any
This instance's parsed value
"""

if isinstance(value, bytes):
try:
return value.decode("utf-8").strip()
Expand All @@ -134,7 +126,6 @@ def parse_values(self) -> Any:
Any
This instance's parsed value or values
"""

if self.value_multiplicity > 1:
return tuple(self.parse_value(value) for value in self.raw.value)
return self.parse_value(self.raw.value)
Expand All @@ -148,7 +139,6 @@ def to_dict(self) -> dict:
dict
This instance as a dictionary
"""

return {
"tag": self.tag,
"keyword": self.keyword,
Expand All @@ -166,7 +156,6 @@ def to_series(self) -> pd.Series:
pd.Series
This instance as a :class:`Series`
"""

d = self.to_dict()
return pd.Series(d)

Expand Down Expand Up @@ -195,7 +184,6 @@ def is_private(self) -> bool:
bool
Whether this data element is private or not
"""

# TODO: This should probably be changed to simply check if the tag's
# group number is odd.
pattern = self.PRIVATE_ELEMENT_DESCRIPTION_PATTERN
Expand All @@ -212,5 +200,4 @@ def is_public(self) -> bool:
bool
Whether this data element is public or not
"""

return not self.is_private
2 changes: 0 additions & 2 deletions src/dicom_parser/data_elements/age_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`AgeString` class, representing a single "AS" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down Expand Up @@ -30,7 +29,6 @@ def parse_value(self, value: str) -> float:
float
Age in years
"""

try:
duration = float(value[:-1])
units = value[-1]
Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/application_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`ApplicationEntity` class, representing a single "AE"
data element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/attribute_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`AttributeTag` class, representing a single "AT" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
4 changes: 0 additions & 4 deletions src/dicom_parser/data_elements/code_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`CodeString` class, representing a single "CS" data
element.
"""

import warnings
from enum import Enum

Expand Down Expand Up @@ -44,7 +43,6 @@ def warn_invalid_code_string_value(
enum : enum.Enum
An Enum representing the element's valid values
"""

field_name = enum.__name__
value = exception.args[0]
warning = f"'{value}' is not a valid {field_name} value!"
Expand All @@ -68,7 +66,6 @@ def parse_with_enum(self, value: str, enum: Enum) -> str:
str
Parsed "CS" data element value
"""

try:
return enum[value].value
except KeyError as exception:
Expand All @@ -90,7 +87,6 @@ def parse_value(self, value: str) -> str:
str
Parsed "CS" data element value
"""

enum = self.TAG_TO_ENUM.get(self.tag)
if enum:
return self.parse_with_enum(value, enum)
Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def parse_value(self, value: str) -> datetime.date:
ValueError
Failure to parse date from raw value
"""

try:
return datetime.strptime(value, "%Y%m%d").date()
except ValueError:
Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`DateTime` class, representing a single "DT" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
2 changes: 0 additions & 2 deletions src/dicom_parser/data_elements/decimal_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`DecimalString` class, representing a single "DS" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down Expand Up @@ -30,7 +29,6 @@ def parse_value(self, value: str) -> float:
float
Parsed decimal
"""

try:
return float(value)
except (TypeError, ValueError):
Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/floating_point_double.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`FloatingPointDouble` class, representing a single
"FD" data element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/floating_point_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`FloatingPointSingle` class, representing a single
"FL" data element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
2 changes: 0 additions & 2 deletions src/dicom_parser/data_elements/integer_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`IntegerString` class, representing a single "IS" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down Expand Up @@ -30,7 +29,6 @@ def parse_value(self, value: str) -> int:
int
Parsed integer
"""

try:
return int(value)
except (TypeError, ValueError):
Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/long_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`LongString` class, representing a single "LO" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down
1 change: 0 additions & 1 deletion src/dicom_parser/data_elements/long_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the :class:`LongText` class, representing a single "LT" data
element.
"""

from dicom_parser.data_element import DataElement
from dicom_parser.utils.value_representation import ValueRepresentation

Expand Down

0 comments on commit a7f60d1

Please sign in to comment.