From 523e8ed0bf2a72337f2714814032478f9898b93d Mon Sep 17 00:00:00 2001 From: Kai Schlamp Date: Sat, 12 Oct 2024 22:33:04 +0000 Subject: [PATCH] Support for pydicom v3 --- pynetdicom/dsutils.py | 14 ++++----- pynetdicom/events.py | 3 -- pynetdicom/tests/test_assoc.py | 51 +++++++++++++++++++------------- pynetdicom/tests/test_dsutils.py | 8 ++--- pyproject.toml | 2 +- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/pynetdicom/dsutils.py b/pynetdicom/dsutils.py index eff927a52..e19b03256 100644 --- a/pynetdicom/dsutils.py +++ b/pynetdicom/dsutils.py @@ -61,10 +61,6 @@ def create_file_meta( file_meta.ImplementationClassUID = implementation_uid file_meta.ImplementationVersionName = implementation_version - # File Meta Information is always encoded as Explicit VR Little Endian - file_meta.is_little_endian = True - file_meta.is_implicit_VR = False - return file_meta @@ -268,11 +264,13 @@ def pretty_element(elem: DataElement) -> str: value = "\\".join([str(ii) for ii in elem.value]) value = f"[{value}]" elif elem.VR == "SQ": - # Sequence elements - if elem.VM == 1: - value = f"(Sequence with {len(elem.value)} item)" + # Sequence elements always have a VM of 1 + assert elem.VM == 1 + length = len(elem.value) + if length == 1: + value = f"(Sequence with {length} item)" else: - value = f"(Sequence with {len(elem.value)} items)" + value = f"(Sequence with {length} items)" except Exception: value = "(pynetdicom failed to beautify value)" diff --git a/pynetdicom/events.py b/pynetdicom/events.py index 778fe5a25..4832c7a95 100644 --- a/pynetdicom/events.py +++ b/pynetdicom/events.py @@ -868,9 +868,6 @@ def _get_dataset(self, attr: str, exc_msg: str) -> Dataset: t_syntax.is_deflated, ) - ds.is_little_endian = t_syntax.is_little_endian - ds.is_implicit_VR = t_syntax.is_implicit_VR - # Store the decoded dataset in case its accessed again self._decoded = ds else: diff --git a/pynetdicom/tests/test_assoc.py b/pynetdicom/tests/test_assoc.py index c5aecace0..f32b2bc5c 100644 --- a/pynetdicom/tests/test_assoc.py +++ b/pynetdicom/tests/test_assoc.py @@ -1882,42 +1882,51 @@ def handle_store(event): assert ds.is_little_endian assert not ds.is_implicit_VR assert ds.file_meta.TransferSyntaxUID == ExplicitVRLittleEndian - ds.is_implicit_VR = True - with caplog.at_level(logging.WARNING, logger="pynetdicom"): - status = assoc.send_c_store(ds) - assert status.Status == 0x0000 + is_implicit_vr_warning = ( + "'FileDataset.is_implicit_VR' will be removed in v4.0, set the " + "Transfer Syntax UID or use the 'implicit_vr' argument with " + r"FileDataset.save_as\(\) or dcmwrite\(\) instead" + ) + + is_little_endian_warning = ( + "'FileDataset.is_little_endian' will be removed in v4.0, set the " + "Transfer Syntax UID or use the 'little_endian' argument with " + r"FileDataset.save_as\(\) or dcmwrite\(\) instead" + ) + + with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning): + ds.is_implicit_VR = True + + status = assoc.send_c_store(ds) + assert status.Status == 0x0000 + + with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning): ds.is_implicit_VR = False + with pytest.warns(DeprecationWarning, match=is_little_endian_warning): ds.is_little_endian = False - status = assoc.send_c_store(ds) - assert status.Status == 0x0000 - ds.is_implicit_VR = False - ds.is_little_endian = True + status = assoc.send_c_store(ds) + assert status.Status == 0x0000 + + with pytest.warns(DeprecationWarning, match=is_implicit_vr_warning): + ds.is_implicit_VR = False + with pytest.warns(DeprecationWarning, match=is_little_endian_warning): + ds.is_little_endian = True ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian - msg = ( + + encoding_mismatch_msg = ( "'dataset' is encoded as explicit VR little endian but the file " r"meta has a \(0002,0010\) Transfer Syntax UID of 'Implicit VR " "Little Endian' - please set an appropriate Transfer Syntax" ) - with pytest.raises(AttributeError, match=msg): + with pytest.raises(AttributeError, match=encoding_mismatch_msg): status = assoc.send_c_store(ds) assoc.release() assert assoc.is_released scp.shutdown() - assert ( - "'dataset' is encoded as implicit VR little endian but the file " - "meta has a (0002,0010) Transfer Syntax UID of 'Explicit VR " - "Little Endian' - using 'Implicit VR Little Endian' instead" - ) in caplog.text - assert ( - "'dataset' is encoded as explicit VR big endian but the file " - "meta has a (0002,0010) Transfer Syntax UID of 'Explicit VR " - "Little Endian' - using 'Explicit VR Big Endian' instead" - ) in caplog.text - # Regression tests def test_no_send_mismatch(self): """Test sending a dataset with mismatched transfer syntax (206).""" diff --git a/pynetdicom/tests/test_dsutils.py b/pynetdicom/tests/test_dsutils.py index d8351fe28..8a3b09358 100644 --- a/pynetdicom/tests/test_dsutils.py +++ b/pynetdicom/tests/test_dsutils.py @@ -422,7 +422,7 @@ def test_seq_empty(self): ds = Dataset() ds.EventCodeSequence = [] assert ( - "(0008,2135) SQ (Sequence with 0 items) # 0" + "(0008,2135) SQ (Sequence with 0 items) # 1" " EventCodeSequence" ) == pretty_element(ds["EventCodeSequence"]) @@ -440,7 +440,7 @@ def test_seq_vm_multi(self): ds = Dataset() ds.EventCodeSequence = [Dataset(), Dataset()] assert ( - "(0008,2135) SQ (Sequence with 2 items) # 2" + "(0008,2135) SQ (Sequence with 2 items) # 1" " EventCodeSequence" ) == pretty_element(ds["EventCodeSequence"]) @@ -570,7 +570,7 @@ def test_sequence_empty(self): """Test using a dataset with an empty sequence.""" ref = [ "(0010,0010) PN [Citizen^Jan] # 1 PatientName", - "(0014,2002) SQ (Sequence with 0 items) # 0 EvaluatorSequence", + "(0014,2002) SQ (Sequence with 0 items) # 1 EvaluatorSequence", "(7FE0,0010) OB (no value available) # 0 PixelData", ] ds = Dataset() @@ -608,7 +608,7 @@ def test_sequence_multi(self): """Test using a dataset with a sequence with multiple items.""" ref = [ "(0010,0010) PN [Citizen^Jan] # 1 PatientName", - "(0014,2002) SQ (Sequence with 3 items) # 3 EvaluatorSequence", + "(0014,2002) SQ (Sequence with 3 items) # 1 EvaluatorSequence", " (Sequence item #1)", " (0010,0020) LO (no value available) # 0 PatientID", " (0010,0030) DA [20011201] # 1 PatientBirthDate", diff --git a/pyproject.toml b/pyproject.toml index 797fe8ec0..d06de01e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ name = "pynetdicom" readme = "README.rst" version = "2.2.0.dev0" requires-python = ">=3.10" -dependencies = ["pydicom >=2.4, <3"] +dependencies = ["pydicom >=3, <4"] [project.urls] documentation = "https://pydicom.github.io/pynetdicom"