Skip to content

Commit

Permalink
Flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erikogabrielsson committed Aug 3, 2023
1 parent bf5e05c commit 87fc760
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 28 deletions.
6 changes: 4 additions & 2 deletions src/highdicom/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,10 @@ def from_dataset(cls, dataset: Dataset) -> 'SpecimenDescription':
for ds in desc.SpecimenTypeCodeSequence
]
if hasattr(desc, 'SpecimenLocalizationContentItemSequence'):
if desc.SpecimenLocalizationContentItemSequence[0].ValueType == ValueTypeValues.TEXT.value:
if (
desc.SpecimenLocalizationContentItemSequence[0].ValueType ==
ValueTypeValues.TEXT.value
):
content_item_type = TextContentItem
else:
content_item_type = NumContentItem
Expand All @@ -1565,7 +1568,6 @@ def from_dataset(cls, dataset: Dataset) -> 'SpecimenDescription':
for ds in desc.SpecimenLocalizationContentItemSequence
]


return desc


Expand Down
1 change: 0 additions & 1 deletion src/highdicom/sr/value_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ def value(self) -> datetime.time:
) from exception
return value.replace()


@classmethod
def from_dataset(
cls,
Expand Down
98 changes: 77 additions & 21 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,10 @@ def test_construction_processing(self):
assert processing_type_item.relationship_type is None

processing_step_description_item = seq[2]
assert processing_step_description_item.name == codes.DCM.ProcessingStepDescription
assert (
processing_step_description_item.name ==
codes.DCM.ProcessingStepDescription
)
assert processing_step_description_item.value == description
assert processing_step_description_item.relationship_type is None

Expand All @@ -705,8 +708,16 @@ def test_construction_processing_optionals(self):
issuer_of_specimen_id = IssuerOfIdentifier("issuer id")
fixative = CodedConcept("fixative", "test", "test fixative")
embedding_medium = CodedConcept("embedding", "test", "test embedding")
specimen_container = CodedConcept("specimen container", "test", "test specimen container")
specimen_type = CodedConcept("specimen type", "test", "test specimen type")
specimen_container = CodedConcept(
"specimen container",
"test",
"test specimen container"
)
specimen_type = CodedConcept(
"specimen type",
"test",
"test specimen type"
)

instance = SpecimenPreparationStep(
specimen_id=specimen_id,
Expand All @@ -729,27 +740,42 @@ def test_construction_processing_optionals(self):
assert specimen_id_item.relationship_type is None

issuer_of_specimen_id_item = seq[1]
assert issuer_of_specimen_id_item.name == codes.DCM.IssuerOfSpecimenIdentifier
assert issuer_of_specimen_id_item.value == issuer_of_specimen_id.LocalNamespaceEntityID
assert (
issuer_of_specimen_id_item.name ==
codes.DCM.IssuerOfSpecimenIdentifier
)
assert (
issuer_of_specimen_id_item.value ==
issuer_of_specimen_id.LocalNamespaceEntityID
)
assert issuer_of_specimen_id_item.relationship_type is None

processing_type_item = seq[2]
assert processing_type_item.name == codes.DCM.ProcessingType
assert (
processing_type_item.name == codes.DCM.ProcessingType
)
assert processing_type_item.value == processing_type
assert processing_type_item.relationship_type is None

processing_datetime_item = seq[3]
assert processing_datetime_item.name == codes.DCM.DatetimeOfProcessing
assert (
processing_datetime_item.name == codes.DCM.DatetimeOfProcessing
)
assert processing_datetime_item.value == processing_datetime
assert processing_datetime_item.relationship_type is None

processing_description_item = seq[4]
assert processing_description_item.name == codes.DCM.ProcessingStepDescription
assert (
processing_description_item.name ==
codes.DCM.ProcessingStepDescription
)
assert processing_description_item.value == processing_description
assert processing_description_item.relationship_type is None

collection_step_item = seq[5]
assert collection_step_item.name == codes.SCT.SpecimenCollection
assert (
collection_step_item.name == codes.SCT.SpecimenCollection
)
assert collection_step_item.value == procedure
assert collection_step_item.relationship_type is None

Expand Down Expand Up @@ -813,8 +839,16 @@ def test_construction_processing_from_dataset_optionals(self):
issuer_of_specimen_id = IssuerOfIdentifier("issuer id")
fixative = CodedConcept("fixative", "test", "test fixative")
embedding_medium = CodedConcept("embedding", "test", "test embedding")
specimen_container = CodedConcept("specimen container", "test", "test specimen container")
specimen_type = CodedConcept("specimen type", "test", "test specimen type")
specimen_container = CodedConcept(
"specimen container",
"test",
"test specimen container"
)
specimen_type = CodedConcept(
"specimen type",
"test",
"test specimen type"
)
dataset = Dataset()
dataset.SpecimenPreparationStepContentItemSequence = [
TextContentItem(
Expand Down Expand Up @@ -870,7 +904,10 @@ def test_construction_processing_from_dataset_optionals(self):
assert isinstance(processing_procedure, SpecimenCollection)
assert processing_procedure.procedure == procedure
assert instance.processing_datetime == processing_datetime
assert instance.issuer_of_specimen_id == issuer_of_specimen_id.LocalNamespaceEntityID
assert (
instance.issuer_of_specimen_id ==
issuer_of_specimen_id.LocalNamespaceEntityID
)
assert instance.specimen_container == specimen_container
assert instance.specimen_type == specimen_type

Expand Down Expand Up @@ -1281,8 +1318,8 @@ def test_construction_different_first_values(self):
blue_lut=b_lut,
)

class TestSpecimenDescription(TestCase):

class TestSpecimenDescription(TestCase):
def test_construction(self):
specimen_id = 'specimen 1'
specimen_uid = UID()
Expand All @@ -1304,7 +1341,11 @@ def test_construction_optionals(self):
specimen_id = 'specimen 1'
specimen_uid = UID()
specimen_location = "specimen location"
specimen_type = CodedConcept("specimen type", "test", "test specimen type")
specimen_type = CodedConcept(
"specimen type",
"test",
"test specimen type"
)
specimen_short_description = "specimen short description"
specimen_detailed_description = "specimen detailed description"
issuer_of_specimen_id = IssuerOfIdentifier("issuer id")
Expand All @@ -1328,9 +1369,16 @@ def test_construction_optionals(self):
assert instance.specimen_location == specimen_location
assert instance.specimen_type == specimen_type
assert instance.specimen_short_description == specimen_short_description
assert instance.specimen_detailed_description == specimen_detailed_description
assert instance.issuer_of_specimen_id == issuer_of_specimen_id
assert instance.primary_anatomic_structures == primary_anatomic_structures
assert (
instance.specimen_detailed_description ==
specimen_detailed_description
)
assert (
instance.issuer_of_specimen_id == issuer_of_specimen_id
)
assert (
instance.primary_anatomic_structures == primary_anatomic_structures
)

def test_construction_with_preparation_steps(self):
parent_specimen_id = 'surgical specimen'
Expand Down Expand Up @@ -1394,7 +1442,11 @@ def test_construction_from_dataset_with_optionals(self):
SpecimenCollection(procedure=codes.SCT.Biopsy)
)
]
specimen_type = CodedConcept("specimen type", "test", "test specimen type")
specimen_type = CodedConcept(
"specimen type",
"test",
"test specimen type"
)
specimen_short_description = "specimen short description"
specimen_detailed_description = "specimen detailed description"
issuer_of_specimen_id = IssuerOfIdentifier("issuer id")
Expand Down Expand Up @@ -1426,7 +1478,11 @@ def test_construction_from_dataset_with_optionals(self):
assert instance.specimen_preparation_steps == specimen_preparation_steps
assert instance.specimen_type == specimen_type
assert instance.specimen_short_description == specimen_short_description
assert instance.specimen_detailed_description == specimen_detailed_description
assert (
instance.specimen_detailed_description ==
specimen_detailed_description
)
assert instance.issuer_of_specimen_id == issuer_of_specimen_id
assert instance.primary_anatomic_structures == primary_anatomic_structures

assert (
instance.primary_anatomic_structures == primary_anatomic_structures
)
10 changes: 6 additions & 4 deletions tests/test_valuetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from highdicom.sr.coding import CodedConcept
from highdicom.sr.enum import ValueTypeValues
from highdicom.sr.value_types import DateContentItem, DateTimeContentItem, TimeContentItem
from highdicom.sr.value_types import (
DateContentItem,
DateTimeContentItem,
TimeContentItem
)
from tests.utils import write_and_read_dataset


Expand Down Expand Up @@ -39,7 +43,6 @@ def test_construct_from_datetime(self, datetime_value: DT):
assert isinstance(item.value, datetime.datetime)
assert item.value.isoformat() == datetime_value.isoformat()


@pytest.mark.parametrize("datetime_value", test_datetime_values)
def test_from_dataset(self, datetime_value: DT):
name = codes.DCM.DatetimeOfProcessing
Expand Down Expand Up @@ -77,7 +80,6 @@ def test_construct_from_date(self):
assert isinstance(item.value, datetime.date)
assert item.value.isoformat() == date_value.isoformat()


def test_from_dataset(self):
date_value = DA("20230623")
name = codes.DCM.AcquisitionDate
Expand All @@ -97,6 +99,7 @@ def test_from_dataset(self):
assert isinstance(item.value, datetime.date)
assert item.value.isoformat() == date_value.isoformat()


class TestTimeContentItem:
test_time_values = [
TM("11"),
Expand All @@ -121,7 +124,6 @@ def test_construct_from_time(self, time_value: TM):
assert isinstance(item.value, datetime.time)
assert item.value.isoformat() == time_value.isoformat()


@pytest.mark.parametrize("time_value", test_time_values)
def test_from_dataset(self, time_value: TM):
name = codes.DCM.AcquisitionDate
Expand Down

0 comments on commit 87fc760

Please sign in to comment.