Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Pytest deprecations #1730

Merged
merged 4 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/merge-typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install typing dependencies
run: |
python -m pip install -U pip
python -m pip install -U mypy
python -m pip install mypy==0.971
python -m pip install -U types-requests types-pkg_resources types-setuptools
- name: Run typing check with mypy
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-type-spell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install typing dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -U mypy
python -m pip install mypy==0.971
python -m pip install -U types-requests types-pkg_resources types-setuptools

- name: Run typing check with mypy
Expand Down
6 changes: 6 additions & 0 deletions doc/release_notes/v2.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changes
-------
* Removed support for Python 3.6 (EOL since December 2021)


Enhancements
------------
* Added attribute :attr:`~pydicom.valuerep.PersonName.alphabetic` (:pr:`1634`)
Expand Down Expand Up @@ -33,3 +34,8 @@ Fixes
syntax using VR ``OW`` (:issue:`1680`)
* Fixed crash if reading regular dataset that has the SOP Class of a DICOMDIR
(:issue:`1702`)

Pydicom Internals
-----------------
* In test suites, renamed 'setup' and 'teardown' methods, deprecated starting
in pytest 7.2
2 changes: 1 addition & 1 deletion pydicom/tests/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ambiguous_scheme():


class TestCode:
def setup(self):
def setup_method(self):
self._value = "373098007"
self._meaning = "Mean Value of population"
self._scheme_designator = "SCT"
Expand Down
4 changes: 2 additions & 2 deletions pydicom/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
class TestDebug:
"""Tests for config.debug()."""

def setup(self):
def setup_method(self):
self.logger = logging.getLogger("pydicom")

def teardown(self):
def teardown_method(self):
# Reset to just NullHandler
self.logger.handlers = [self.logger.handlers[0]]

Expand Down
4 changes: 2 additions & 2 deletions pydicom/tests/test_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ def test_get_palette_files(self):
class TestExternalDataSource:
"""Tests for the external data sources."""

def setup(self):
def setup_method(self):
self.dpath = external_data_sources()["pydicom-data"].data_path

# Backup the 693_UNCI.dcm file
p = self.dpath / "693_UNCI.dcm"
shutil.copy(p, self.dpath / "PYTEST_BACKUP")

def teardown(self):
def teardown_method(self):
# Restore the backed-up file
p = self.dpath / "693_UNCI.dcm"
shutil.copy(self.dpath / "PYTEST_BACKUP", p)
Expand Down
10 changes: 5 additions & 5 deletions pydicom/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __repr__(self):
class TestDataset:
"""Tests for dataset.Dataset."""

def setup(self):
def setup_method(self):
self.ds = Dataset()
self.ds.TreatmentMachineName = "unit001"

Expand Down Expand Up @@ -1700,7 +1700,7 @@ def test_setitem_invalid_key(self):
class TestDatasetElements:
"""Test valid assignments of data elements"""

def setup(self):
def setup_method(self):
self.ds = Dataset()
self.sub_ds1 = Dataset()
self.sub_ds2 = Dataset()
Expand Down Expand Up @@ -1810,7 +1810,7 @@ def test_validate_and_correct_file_meta(self):


class TestFileDataset:
def setup(self):
def setup_method(self):
self.test_file = get_testdata_file('CT_small.dcm')

def test_pickle_raw_data(self):
Expand Down Expand Up @@ -1975,7 +1975,7 @@ def test_deepcopy_without_filename(self):
class TestDatasetOverlayArray:
"""Tests for Dataset.overlay_array()."""

def setup(self):
def setup_method(self):
"""Setup the test datasets and the environment."""
self.original_handlers = pydicom.config.overlay_data_handlers
pydicom.config.overlay_data_handlers = [NP_HANDLER]
Expand Down Expand Up @@ -2007,7 +2007,7 @@ def get_overlay_array(self, ds, group):

self.dummy = DummyHandler()

def teardown(self):
def teardown_method(self):
"""Restore the environment."""
pydicom.config.overlay_data_handlers = self.original_handlers
mrbean-bremen marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
6 changes: 3 additions & 3 deletions pydicom/tests/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class TestEncoder:
"""Non-encoding tests for encoders.Encoder"""
def setup(self):
def setup_method(self):
self.enc = Encoder(UID('1.2.3'))

def test_init(self):
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_missing_one_dependency(self):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy not available")
class TestEncoder_Encode:
"""Tests for Encoder.encode() and related methods."""
def setup(self):
def setup_method(self):
self.enc = RLELosslessEncoder
self.ds = get_testdata_file("CT_small.dcm", read=True)
self.ds_enc = get_testdata_file("MR_small_RLE.dcm", read=True)
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_dataset_missing_elem_raises(self):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy not available")
class TestEncoder_Preprocess:
"""Tests for Encoder._preprocess()."""
def setup(self):
def setup_method(self):
self.e = Encoder(JPEG2000Lossless)
self.ds = ds = Dataset()
ds.Rows = 1
Expand Down
2 changes: 1 addition & 1 deletion pydicom/tests/test_encoders_pydicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_encode(self, src, output):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy not available")
class TestEncodeFrame:
"""Tests for rle_handler._encode_frame."""
def setup(self):
def setup_method(self):
"""Setup the tests."""
# Create a dataset skeleton for use in the cycle tests
ds = Dataset()
Expand Down
8 changes: 4 additions & 4 deletions pydicom/tests/test_filereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def test_empty_pn(self):


class TestIncorrectVR:
def setup(self):
def setup_method(self):
self.ds_explicit = BytesIO(
b"\x08\x00\x05\x00CS\x0a\x00ISO_IR 100" # SpecificCharacterSet
b"\x08\x00\x20\x00DA\x08\x0020000101" # StudyDate
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def test_fail_decode_msg(self, vr_bytes, str_output):


class TestReadDataElement:
def setup(self):
def setup_method(self):
ds = Dataset()
ds.DoubleFloatPixelData = (
b"\x00\x01\x02\x03\x04\x05\x06\x07"
Expand Down Expand Up @@ -1474,11 +1474,11 @@ class TestDeferredRead:
"""

# Copy one of test files and use temporarily, then later remove.
def setup(self):
def setup_method(self):
self.testfile_name = ct_name + ".tmp"
shutil.copyfile(ct_name, self.testfile_name)

def teardown(self):
def teardown_method(self):
if os.path.exists(self.testfile_name):
os.remove(self.testfile_name)

Expand Down
8 changes: 4 additions & 4 deletions pydicom/tests/test_fileset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,10 +2153,10 @@ def test_load_dicomdir_no_uid(self, dicomdir):
@pytest.mark.filterwarnings("ignore:The 'DicomDir'")
class TestFileSet_Modify:
"""Tests for a modified File-set."""
def setup(self):
def setup_method(self):
self.fn = FileSet.__len__

def teardown(self):
def teardown_method(self):
FileSet.__len__ = self.fn

def test_write_dicomdir_fs_changes(self, dicomdir_copy):
Expand Down Expand Up @@ -2472,10 +2472,10 @@ def test_write_undefined_length(self, dicomdir_copy):
@pytest.mark.filterwarnings("ignore:The 'DicomDir'")
class TestFileSet_Copy:
"""Tests for copying a File-set."""
def setup(self):
def setup_method(self):
self.orig = FileSet.__len__

def teardown(self):
def teardown_method(self):
FileSet.__len__ = self.orig

def test_copy(self, dicomdir, tdir):
Expand Down
20 changes: 10 additions & 10 deletions pydicom/tests/test_filewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def as_assertable(dataset):


class TestWriteFile:
def setup(self):
def setup_method(self):
self.file_out = TemporaryFile('w+b')

def teardown(self):
def teardown_method(self):
self.file_out.close()

def compare(self, in_filename):
Expand Down Expand Up @@ -308,11 +308,11 @@ def test_write_encapsulated_mismatch_encoding(self):
class TestScratchWriteDateTime(TestWriteFile):
"""Write and reread simple or multi-value DA/DT/TM data elements"""

def setup(self):
def setup_method(self):
config.datetime_conversion = True
self.file_out = TemporaryFile('w+b')

def teardown(self):
def teardown_method(self):
config.datetime_conversion = False
self.file_out.close()

Expand Down Expand Up @@ -349,7 +349,7 @@ def test_multivalue_DA(self):
class TestWriteDataElement:
"""Attempt to write data elements has the expected behaviour"""

def setup(self):
def setup_method(self):
# Create a dummy (in memory) file to write to
self.f1 = DicomBytesIO()
self.f1.is_little_endian = True
Expand Down Expand Up @@ -1147,7 +1147,7 @@ def test_empty_value(self):
class TestWriteAmbiguousVR:
"""Attempt to write data elements with ambiguous VR."""

def setup(self):
def setup_method(self):
# Create a dummy (in memory) file to write to
self.fp = DicomBytesIO()
self.fp.is_implicit_VR = False
Expand Down Expand Up @@ -1207,7 +1207,7 @@ def test_write_explicit_vr_big_endian(self):
class TestScratchWrite:
"""Simple dataset from scratch, written in all endian/VR combinations"""

def setup(self):
def setup_method(self):
# Create simple dataset for all tests
ds = Dataset()
ds.PatientName = "Name^Patient"
Expand Down Expand Up @@ -1866,7 +1866,7 @@ def test_filelike_position(self):
class TestWriteNonStandard:
"""Unit tests for writing datasets not to the DICOM standard."""

def setup(self):
def setup_method(self):
"""Create an empty file-like for use in testing."""
self.fp = DicomBytesIO()
self.fp.is_little_endian = True
Expand Down Expand Up @@ -2206,7 +2206,7 @@ def test_read_write_identical(self):
class TestWriteFileMetaInfoNonStandard:
"""Unit tests for writing File Meta Info not to the DICOM standard."""

def setup(self):
def setup_method(self):
"""Create an empty file-like for use in testing."""
self.fp = DicomBytesIO()

Expand Down Expand Up @@ -2626,7 +2626,7 @@ def test_format_dt(self):
class TestWriteUndefinedLengthPixelData:
"""Test write_data_element() for pixel data with undefined length."""

def setup(self):
def setup_method(self):
self.fp = DicomBytesIO()

def test_little_endian_correct_data(self):
Expand Down
16 changes: 8 additions & 8 deletions pydicom/tests/test_gdcm_pixel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@


class TestGDCM_JPEG_LS_no_gdcm:
def setup(self):
def setup_method(self):
self.unicode_filename = os.path.join(
tempfile.gettempdir(), "ДИКОМ.dcm")
shutil.copyfile(jpeg_ls_lossless_name, self.unicode_filename)
Expand All @@ -108,7 +108,7 @@ def setup(self):
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = []

def teardown(self):
def teardown_method(self):
pydicom.config.pixel_data_handlers = self.original_handlers
os.remove(self.unicode_filename)

Expand All @@ -122,7 +122,7 @@ def test_emri_JPEG_LS_PixelArray(self):


class TestGDCM_JPEG2000_no_gdcm:
def setup(self):
def setup_method(self):
self.jpeg_2k = dcmread(jpeg2000_name)
self.jpeg_2k_lossless = dcmread(jpeg2000_lossless_name)
self.mr_small = dcmread(mr_name)
Expand All @@ -132,7 +132,7 @@ def setup(self):
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = []

def teardown(self):
def teardown_method(self):
pydicom.config.pixel_data_handlers = self.original_handlers

def test_JPEG2000(self):
Expand Down Expand Up @@ -160,13 +160,13 @@ def test_jpeg2000_lossy(self):


class TestGDCM_JPEGlossy_no_gdcm:
def setup(self):
def setup_method(self):
self.jpeg_lossy = dcmread(jpeg_lossy_name)
self.color_3d_jpeg = dcmread(color_3d_jpeg_baseline)
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = []

def teardown(self):
def teardown_method(self):
pydicom.config.pixel_data_handlers = self.original_handlers

def test_JPEGlossy(self):
Expand All @@ -185,12 +185,12 @@ def test_JPEGBaseline_color_3D_pixel_array(self):


class TestGDCM_JPEGlossless_no_gdcm:
def setup(self):
def setup_method(self):
self.jpeg_lossless = dcmread(jpeg_lossless_name)
self.original_handlers = pydicom.config.pixel_data_handlers
pydicom.config.pixel_data_handlers = []

def teardown(self):
def teardown_method(self):
pydicom.config.pixel_data_handlers = self.original_handlers

def testJPEGlossless(self):
Expand Down
8 changes: 4 additions & 4 deletions pydicom/tests/test_handler_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_reshape_pixel_array_raises(self):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy is not available")
class TestNumpy_PixelDtype:
"""Tests for util.pixel_dtype."""
def setup(self):
def setup_method(self):
"""Setup the test dataset."""
self.ds = Dataset()
self.ds.file_meta = FileMetaDataset()
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_byte_swapping(self):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy is not available")
class TestNumpy_ReshapePixelArray:
"""Tests for util.reshape_pixel_array."""
def setup(self):
def setup_method(self):
"""Setup the test dataset."""
self.ds = Dataset()
self.ds.file_meta = FileMetaDataset()
Expand Down Expand Up @@ -940,12 +940,12 @@ def test_lutdata_ow(self):
@pytest.mark.skipif(not HAVE_NP, reason="Numpy is not available")
class TestNumpy_PaletteColor:
"""Tests for util.apply_color_lut()."""
def setup(self):
def setup_method(self):
"""Setup the tests"""
self.o_palette = get_palette_files('pet.dcm')[0]
self.n_palette = get_palette_files('pet.dcm')[0][:-3] + 'tmp'

def teardown(self):
def teardown_method(self):
"""Teardown the tests"""
if os.path.exists(self.n_palette):
os.rename(self.n_palette, self.o_palette)
Expand Down