[med-svn] [Git][med-team/dcmstack][master] 6 commits: Add patch to move tests from using nose->pytest
Nilesh Patra (@nilesh)
gitlab at salsa.debian.org
Fri Nov 12 18:57:55 GMT 2021
Nilesh Patra pushed to branch master at Debian Med / dcmstack
Commits:
bb4d870d by Nilesh Patra at 2021-11-12T23:49:40+05:30
Add patch to move tests from using nose->pytest
- - - - -
a4e08c15 by Nilesh Patra at 2021-11-12T23:49:58+05:30
Add B-D on pytest instead of nose
- - - - -
9a6055a8 by Nilesh Patra at 2021-11-12T23:52:19+05:30
Fix autopkgtests
- - - - -
bc3f6de0 by Nilesh Patra at 2021-11-12T18:51:39+00:00
Improve autopkgtests: run in AUTOPKGTEST_TMP instead of source root to ensure they work
- - - - -
d4befee8 by Nilesh Patra at 2021-11-12T18:51:39+00:00
Avoid generating manpage during build, rather maintain them as maintainer manuals
- - - - -
91efec3a by Nilesh Patra at 2021-11-13T00:22:41+05:30
Upload to unstable
- - - - -
11 changed files:
- debian/changelog
- debian/control
- + debian/createmanpages
- + debian/man/dcmstack.1
- + debian/man/nitool.1
- debian/manpages
- + debian/patches/port-to-pytest.patch
- + debian/patches/series
- debian/rules
- debian/tests/control
- + debian/tests/run-unit-test
Changes:
=====================================
debian/changelog
=====================================
@@ -1,5 +1,6 @@
-dcmstack (0.8-3) UNRELEASED; urgency=medium
+dcmstack (0.8-3) unstable; urgency=medium
+ [ Andreas Tille ]
* Team upload.
* Standardize repository to Debian Med policy and remove debian/gbp.conf
* Move repository to Debian Med team Salsa space
@@ -15,9 +16,17 @@ dcmstack (0.8-3) UNRELEASED; urgency=medium
* Remove unnecessary 'Testsuite: autopkgtest' header.
* Set upstream metadata fields: Bug-Database, Bug-Submit, Repository,
Repository-Browse.
- TODO: https://github.com/moloney/dcmstack/issues/67
- -- Andreas Tille <tille at debian.org> Fri, 12 Nov 2021 11:40:49 +0100
+ [ Nilesh Patra ]
+ * Add patch to move tests from using nose->pytest
+ * Add B-D on pytest instead of nose
+ * Fix autopkgtests
+ * Improve autopkgtests: run in AUTOPKGTEST_TMP instead of
+ source root to ensure they work
+ * Avoid generating manpage during build, rather maintain them
+ as maintainer manuals
+
+ -- Nilesh Patra <nilesh at debian.org> Sat, 13 Nov 2021 00:22:04 +0530
dcmstack (0.8-2) unstable; urgency=medium
=====================================
debian/control
=====================================
@@ -6,15 +6,14 @@ Section: science
Priority: optional
Build-Depends: debhelper-compat (= 13),
dh-python,
- help2man,
python3-all,
python3-dicom,
python3-docutils,
python3-mock,
python3-nibabel,
- python3-nose,
python3-numpy,
python3-numpydoc,
+ python3-pytest,
python3-setuptools,
python3-sphinx
Standards-Version: 4.6.0
=====================================
debian/createmanpages
=====================================
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+set -e
+
+if [ ! -x /usr/bin/help2man ]; then
+ echo "E: Missing /usr/bin/help2man, please install it from the cognate package."
+ exit 1
+fi
+
+if [ ! -n "$NAME" ]; then
+ NAME=`grep "^Description:" debian/control | sed 's/^Description: *//' | head -n1`
+fi
+
+if [ ! -n "$VERSION" ]; then
+ VERSION=`dpkg-parsechangelog | awk '/^Version:/ {print $2}' | sed -e 's/^[0-9]*://' -e 's/-.*//' -e 's/[+~]dfsg$//'`
+fi
+
+if [ ! -n "$PROGNAME" ]; then
+ PROGNAME=`grep "^Package:" debian/control | sed 's/^Package: *//' | head -n1`
+fi
+
+MANDIR=debian/man
+
+HELPOPTION='--help'
+echo "PROGNAME: '$PROGNAME'"
+echo "NAME: '$NAME'"
+echo "VERSION: '$VERSION'"
+echo "MANDIR: '$MANDIR'"
+echo "HELPOPTION: '$HELPOPTION'"
+
+mkdir -p $MANDIR
+
+
+AUTHOR=".SH AUTHOR\n \
+This manpage was written by $DEBFULLNAME for the Debian distribution and\n \
+can be used for any other usage of the program.\
+"
+
+# If program name is different from package name or title should be
+# different from package short description change this here
+progname=dcmstack
+help2man --no-info --no-discard-stderr --help-option="$HELPOPTION" \
+ --name="$NAME" \
+ --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
+echo $AUTHOR >> $MANDIR/${progname}.1
+
+echo "$MANDIR/*.1" > debian/manpages
+
+progname=nitool
+help2man --no-info --no-discard-stderr --help-option="$HELPOPTION" \
+ --name="$NAME" \
+ --version-string="$VERSION" ${progname} > $MANDIR/${progname}.1
+echo $AUTHOR >> $MANDIR/${progname}.1
+
+echo "$MANDIR/*.1" > debian/manpages
+
+cat <<EOT
+Please enhance the help2man output in '$MANDIR/${progname}.1'.
+To inspect it, try 'nroff -man $MANDIR/${progname}.1'.
+If very unhappy, try passing the HELPOPTION as an environment variable.
+The following web page might be helpful in doing so:
+ http://liw.fi/manpages/
+EOT
+
=====================================
debian/man/dcmstack.1
=====================================
@@ -0,0 +1,139 @@
+.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
+.TH DCMSTACK "1" "November 2021" "dcmstack 0.8" "User Commands"
+.SH NAME
+dcmstack \- DICOM to NIfTI conversion - python3 package
+.SH DESCRIPTION
+usage: dcmstack [\-h] [\-\-force\-read] [\-\-file\-ext FILE_EXT] [\-\-allow\-dummies]
+.IP
+[\-\-dest\-dir DEST_DIR] [\-o OUTPUT_NAME]
+[\-\-output\-ext OUTPUT_EXT] [\-d] [\-\-embed\-meta] [\-g GROUP_BY]
+[\-\-voxel\-order VOXEL_ORDER] [\-t TIME_VAR]
+[\-\-vector\-var VECTOR_VAR] [\-\-time\-order TIME_ORDER]
+[\-\-vector\-order VECTOR_ORDER] [\-l]
+[\-\-disable\-translator DISABLE_TRANSLATOR] [\-\-extract\-private]
+[\-i INCLUDE_REGEX] [\-e EXCLUDE_REGEX] [\-\-default\-regexes] [\-v]
+[\-\-strict] [\-\-version]
+[src_dirs ...]
+.PP
+Stack DICOM files from each source directory into 2D to 5D volumes, optionally
+extracting meta data.
+.SS "positional arguments:"
+.TP
+src_dirs
+The source directories containing DICOM files.
+.SS "optional arguments:"
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+show this help message and exit
+.SS "Input options:"
+.TP
+\fB\-\-force\-read\fR
+Try reading all files as DICOM, even if they are
+missing the preamble.
+.TP
+\fB\-\-file\-ext\fR FILE_EXT
+Only try reading files with the given extension.
+Default: .dcm
+.TP
+\fB\-\-allow\-dummies\fR
+Allow DICOM files that are missing pixel data, filling
+that slice of the output nifti with the maximum
+representable value.
+.SS "Output options:"
+.TP
+\fB\-\-dest\-dir\fR DEST_DIR
+Destination directory, defaults to the source
+directory.
+.TP
+\fB\-o\fR OUTPUT_NAME, \fB\-\-output\-name\fR OUTPUT_NAME
+Python format string determining the output filenames
+based on DICOM tags.
+.TP
+\fB\-\-output\-ext\fR OUTPUT_EXT
+The extension for the output file type. Default:
+\&.nii.gz
+.TP
+\fB\-d\fR, \fB\-\-dump\-meta\fR
+Dump the extracted meta data into a JSON file with the
+same base name as the generated Nifti
+.TP
+\fB\-\-embed\-meta\fR
+Embed the extracted meta data into a Nifti header
+extension (in JSON format).
+.SS "Stacking Options:"
+.TP
+\fB\-g\fR GROUP_BY, \fB\-\-group\-by\fR GROUP_BY
+Comma separated list of meta data keys to group input
+files into stacks with.
+.TP
+\fB\-\-voxel\-order\fR VOXEL_ORDER
+Order the voxels so the spatial indices start from
+these directions in patient space. The directions in
+patient space should be given as a three character
+code: (l)eft, (r)ight, (a)nterior, (p)osterior,
+(s)uperior, (i)nferior. Passing an empty string will
+disable reorientation. Default: LAS
+.TP
+\fB\-t\fR TIME_VAR, \fB\-\-time\-var\fR TIME_VAR
+The DICOM element keyword to use for ordering the
+stack along the time dimension.
+.TP
+\fB\-\-vector\-var\fR VECTOR_VAR
+The DICOM element keyword to use for ordering the
+stack along the vector dimension.
+.TP
+\fB\-\-time\-order\fR TIME_ORDER
+Provide a text file with the desired order for the
+values (one per line) of the attribute used as the
+time variable. This option is rarely needed.
+.TP
+\fB\-\-vector\-order\fR VECTOR_ORDER
+Provide a text file with the desired order for the
+values (one per line) of the attribute used as the
+vector variable. This option is rarely needed.
+.SS "Meta Extraction and Filtering Options:"
+.TP
+\fB\-l\fR, \fB\-\-list\-translators\fR
+List enabled translators and exit
+.TP
+\fB\-\-disable\-translator\fR DISABLE_TRANSLATOR
+Disable the translators for the provided tags. Tags
+should be given in the format "0x0_0x0". More than one
+can be given in a comma separated list. If the word
+"all" is provided, all translators will be disabled.
+.TP
+\fB\-\-extract\-private\fR
+Extract meta data from private elements, even if there
+is no translator. If the value for the element
+contains non\-ascii bytes it will still be ignored. The
+extracted meta data may still be filtered out by the
+regular expressions.
+.TP
+\fB\-i\fR INCLUDE_REGEX, \fB\-\-include\-regex\fR INCLUDE_REGEX
+Include any meta data where the key matches the
+provided regular expression. This will override any
+exclude expressions. Applies to all meta data.
+.TP
+\fB\-e\fR EXCLUDE_REGEX, \fB\-\-exclude\-regex\fR EXCLUDE_REGEX
+Exclude any meta data where the key matches the
+provided regular expression. This will supplement the
+default exclude expressions. Applies to all meta data.
+.TP
+\fB\-\-default\-regexes\fR
+Print the list of default include and exclude regular
+expressions and exit.
+.SS "General Options:"
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Print additional information.
+.TP
+\fB\-\-strict\fR
+Fail on the first exception instead of showing a
+warning.
+.TP
+\fB\-\-version\fR
+Show the version and exit.
+.PP
+IT IS YOUR RESPONSIBILITY TO KNOW IF THERE IS PRIVATE HEALTH INFORMATION IN
+THE METADATA EXTRACTED BY THIS PROGRAM.
+.SH AUTHOR\n This manpage was written by Nilesh Patra for the Debian distribution and\n can be used for any other usage of the program.
=====================================
debian/man/nitool.1
=====================================
@@ -0,0 +1,37 @@
+.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
+.TH NITOOL "1" "November 2021" "nitool 0.8" "User Commands"
+.SH NAME
+nitool \- DICOM to NIfTI conversion - python3 package
+.SH DESCRIPTION
+usage: nitool [\-h] {split,merge,dump,embed,lookup,inject} ...
+.PP
+Work with extended Nifti files created by dcmstack
+.SS "optional arguments:"
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+show this help message and exit
+.SS "Subcommands:"
+.IP
+{split,merge,dump,embed,lookup,inject}
+.TP
+split
+Split src_nii file along a dimension. Defaults to the
+slice dimension if 3D, otherwise the last dimension.
+.TP
+merge
+Merge the provided Nifti files along a dimension.
+Defaults to slice, then time, and then vector.
+.TP
+dump
+Dump the JSON meta data extension from the provided
+Nifti.
+.TP
+embed
+Embed a JSON extension into the Nifti file.
+.TP
+lookup
+Lookup the value for the given meta data key.
+.TP
+inject
+Inject meta data into the JSON extension.
+.SH AUTHOR\n This manpage was written by Nilesh Patra for the Debian distribution and\n can be used for any other usage of the program.
=====================================
debian/manpages
=====================================
@@ -1,2 +1 @@
-build/man/dcmstack.1
-build/man/nitool.1
+debian/man/*.1
=====================================
debian/patches/port-to-pytest.patch
=====================================
@@ -0,0 +1,2087 @@
+Description: Move tests from using nose to pytest. nose has been deprecated for a long while
+Author: Nilesh Patra <nilesh at debian.org>
+Last-Update: 2021-11-12
+--- a/test/test_cli.py
++++ b/test/test_cli.py
+@@ -5,8 +5,6 @@
+
+ import numpy as np
+
+-from nose.tools import ok_, eq_
+-
+ from . import test_dir, src_dir
+
+ from dcmstack import dcmstack_cli, nitool_cli
+@@ -55,11 +53,11 @@
+ class TestDcmstackCli(CliTest):
+ def test_basic(self):
+ nii_paths = make_niftis(self.out_dir)
+- eq_(len(nii_paths), 1)
++ assert len(nii_paths) == 1
+
+ def test_embed(self):
+ nii_paths = make_niftis(self.out_dir, ['--embed'])
+- eq_(len(nii_paths), 1)
++ assert len(nii_paths) == 1
+
+
+ class TestNitoolCli(CliTest):
+@@ -70,11 +68,11 @@
+ with open(json_path) as fp:
+ meta = json.load(fp)
+ print(json.dumps(meta, indent=4))
+- ok_('dcmmeta_version' in meta)
+- ok_('dcmmeta_affine' in meta)
+- ok_('dcmmeta_reorient_transform' in meta)
+- eq_(meta['dcmmeta_shape'], [192, 192, 2, 2])
+- eq_(meta['dcmmeta_slice_dim'], 2)
+- eq_(meta['global']['const']['Rows'], 192)
+- eq_(meta['global']['const']['Columns'], 192)
+- ok_(np.allclose(meta['time']['samples']['EchoTime'], [20.0, 40.0]))
++ assert('dcmmeta_version' in meta)
++ assert('dcmmeta_affine' in meta)
++ assert('dcmmeta_reorient_transform' in meta)
++ assert meta['dcmmeta_shape'] == [192, 192, 2, 2]
++ assert meta['dcmmeta_slice_dim'] == 2
++ assert meta['global']['const']['Rows'] == 192
++ assert meta['global']['const']['Columns'] == 192
++ assert(np.allclose(meta['time']['samples']['EchoTime'], [20.0, 40.0]))
+--- a/test/test_dcmmeta.py
++++ b/test/test_dcmmeta.py
+@@ -5,7 +5,7 @@
+ from os import path
+ from glob import glob
+
+-from nose.tools import ok_, eq_, assert_raises
++import pytest
+ import numpy as np
+ import nibabel as nb
+ try:
+@@ -18,79 +18,66 @@
+ from dcmstack import dcmmeta
+
+ def test_is_constant():
+- ok_(dcmmeta.is_constant([0]))
+- ok_(dcmmeta.is_constant([0, 0]))
+- ok_(dcmmeta.is_constant([0, 0, 1, 1], period=2))
+- ok_(dcmmeta.is_constant([0, 0, 1, 1, 2, 2], period=2))
+- eq_(dcmmeta.is_constant([0, 1]), False)
+- eq_(dcmmeta.is_constant([0, 0, 1, 2], 2), False)
+- assert_raises(ValueError, dcmmeta.is_constant, [0, 0, 0], -1)
+- assert_raises(ValueError, dcmmeta.is_constant, [0, 0, 0], 1)
+- assert_raises(ValueError, dcmmeta.is_constant, [0, 0, 0], 2)
+- assert_raises(ValueError, dcmmeta.is_constant, [0, 0, 0], 4)
++ assert(dcmmeta.is_constant([0]))
++ assert(dcmmeta.is_constant([0, 0]))
++ assert(dcmmeta.is_constant([0, 0, 1, 1], period=2))
++ assert(dcmmeta.is_constant([0, 0, 1, 1, 2, 2], period=2))
++ assert dcmmeta.is_constant([0, 1]) == False
++ assert dcmmeta.is_constant([0, 0, 1, 2], 2) == False
++ with pytest.raises(ValueError):
++ dcmmeta.is_constant([0, 0, 0], -1)
++ dcmmeta.is_constant([0, 0, 0], 1)
++ dcmmeta.is_constant([0, 0, 0], 2)
++ dcmmeta.is_constant([0, 0, 0], 4)
+
+ def test_is_repeating():
+- ok_(dcmmeta.is_repeating([0, 1, 0, 1], 2))
+- ok_(dcmmeta.is_repeating([0, 1, 0, 1, 0, 1], 2))
+- eq_(dcmmeta.is_repeating([0, 1, 1, 2], 2), False)
+- assert_raises(ValueError, dcmmeta.is_repeating, [0, 1, 0, 1], -1)
+- assert_raises(ValueError, dcmmeta.is_repeating, [0, 1, 0, 1], 1)
+- assert_raises(ValueError, dcmmeta.is_repeating, [0, 1, 0, 1], 3)
+- assert_raises(ValueError, dcmmeta.is_repeating, [0, 1, 0, 1], 4)
+- assert_raises(ValueError, dcmmeta.is_repeating, [0, 1, 0, 1], 5)
++ assert(dcmmeta.is_repeating([0, 1, 0, 1], 2))
++ assert(dcmmeta.is_repeating([0, 1, 0, 1, 0, 1], 2))
++ assert dcmmeta.is_repeating([0, 1, 1, 2], 2) == False
++ with pytest.raises(ValueError):
++ dcmmeta.is_repeating([0, 1, 0, 1], -1)
++ dcmmeta.is_repeating([0, 1, 0, 1], 1)
++ dcmmeta.is_repeating([0, 1, 0, 1], 3)
++ dcmmeta.is_repeating([0, 1, 0, 1], 4)
++ dcmmeta.is_repeating([0, 1, 0, 1], 5)
+
+ def test_get_valid_classes():
+ ext = dcmmeta.DcmMetaExtension.make_empty((2, 2, 2), np.eye(4))
+- eq_(ext.get_valid_classes(), (('global', 'const'), ('global', 'slices')))
++ assert ext.get_valid_classes() == (('global', 'const'), ('global', 'slices'))
+
+ ext.shape = (2, 2, 2, 2)
+- eq_(ext.get_valid_classes(),
+- (('global', 'const'),
+- ('global', 'slices'),
+- ('time', 'samples'),
+- ('time', 'slices')
+- )
+- )
++ assert ext.get_valid_classes() == (('global', 'const'), ('global', 'slices'), ('time', 'samples'), ('time', 'slices'))
+
+ ext.shape = (2, 2, 2, 1, 2)
+- eq_(ext.get_valid_classes(),
+- (('global', 'const'),
+- ('global', 'slices'),
+- ('vector', 'samples'),
+- ('vector', 'slices')
+- )
+- )
++ assert ext.get_valid_classes() == (('global', 'const'), ('global', 'slices'), ('vector', 'samples'), ('vector', 'slices'))
+
+ ext.shape = (2, 2, 2, 2, 2)
+- eq_(ext.get_valid_classes(),
+- (('global', 'const'),
+- ('global', 'slices'),
+- ('time', 'samples'),
+- ('time', 'slices'),
+- ('vector', 'samples'),
+- ('vector', 'slices')
+- )
+- )
++ assert ext.get_valid_classes() == (('global', 'const'), \
++ ('global', 'slices'), \
++ ('time', 'samples'), \
++ ('time', 'slices'), \
++ ('vector', 'samples'), \
++ ('vector', 'slices'))
+
+ def test_get_mulitplicity_4d():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 7, 11),
+ np.eye(4),
+ np.eye(4),
+ 2)
+- eq_(ext.get_multiplicity(('global', 'const')), 1)
+- eq_(ext.get_multiplicity(('global', 'slices')), 7 * 11)
+- eq_(ext.get_multiplicity(('time', 'samples')), 11)
+- eq_(ext.get_multiplicity(('time', 'slices')), 7)
++ assert ext.get_multiplicity(('global', 'const')) == 1
++ assert ext.get_multiplicity(('global', 'slices')) == 7 * 11
++ assert ext.get_multiplicity(('time', 'samples')) == 11
++ assert ext.get_multiplicity(('time', 'slices')) == 7
+
+ def test_get_mulitplicity_4d_vec():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 7, 1, 11),
+ np.eye(4),
+ np.eye(4),
+ 2)
+- eq_(ext.get_multiplicity(('global', 'const')), 1)
+- eq_(ext.get_multiplicity(('global', 'slices')), 7 * 11)
+- eq_(ext.get_multiplicity(('vector', 'samples')), 11)
+- eq_(ext.get_multiplicity(('vector', 'slices')), 7)
++ assert ext.get_multiplicity(('global', 'const')) == 1
++ assert ext.get_multiplicity(('global', 'slices')) == 7 * 11
++ assert ext.get_multiplicity(('vector', 'samples')) == 11
++ assert ext.get_multiplicity(('vector', 'slices')) == 7
+
+ def test_get_mulitplicity_5d():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 7, 11, 13),
+@@ -98,12 +85,12 @@
+ np.eye(4),
+ 2
+ )
+- eq_(ext.get_multiplicity(('global', 'const')), 1)
+- eq_(ext.get_multiplicity(('global', 'slices')), 7 * 11 * 13)
+- eq_(ext.get_multiplicity(('time', 'samples')), 11 * 13)
+- eq_(ext.get_multiplicity(('time', 'slices')), 7)
+- eq_(ext.get_multiplicity(('vector', 'samples')), 13)
+- eq_(ext.get_multiplicity(('vector', 'slices')), 7 * 11)
++ assert ext.get_multiplicity(('global', 'const')) == 1
++ assert ext.get_multiplicity(('global', 'slices')) == 7 * 11 * 13
++ assert ext.get_multiplicity(('time', 'samples')) == 11 * 13
++ assert ext.get_multiplicity(('time', 'slices')) == 7
++ assert ext.get_multiplicity(('vector', 'samples')) == 13
++ assert ext.get_multiplicity(('vector', 'slices')) == 7 * 11
+
+ class TestCheckValid(object):
+ def setUp(self):
+@@ -112,6 +99,9 @@
+ np.eye(4),
+ 2)
+
++ def setup_method(self, setUp):
++ self.setUp()
++
+ def test_empty(self):
+ self.ext.check_valid()
+
+@@ -119,75 +109,93 @@
+ self.ext.get_class_dict(('global', 'const'))['ConstTest'] = 2
+ self.ext.check_valid()
+ del self.ext._content['global']['const']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_global_slices(self):
+ cls_dict = self.ext.get_class_dict(('global', 'slices'))
+ cls_dict['SliceTest'] = [0] * 23
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['SliceTest'] = [0] * 24
+ self.ext.check_valid()
+ del self.ext._content['global']['slices']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_time_samples(self):
+ cls_dict = self.ext.get_class_dict(('time', 'samples'))
+ cls_dict['TimeSampleTest'] = [0] * 2
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['TimeSampleTest'] = [0] * 3
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['TimeSampleTest'] = [0] * 12
+ self.ext.check_valid()
+ del self.ext._content['time']['samples']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_time_slices(self):
+ cls_dict = self.ext.get_class_dict(('time', 'slices'))
+ cls_dict['TimeSliceTest'] = [0]
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['TimeSliceTest'] = [0] * 2
+ self.ext.check_valid()
+ del self.ext._content['time']['slices']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_vector_samples(self):
+ cls_dict = self.ext.get_class_dict(('vector', 'samples'))
+ cls_dict['VectorSampleTest'] = [0] * 3
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['VectorSampleTest'] = [0] * 4
+ self.ext.check_valid()
+ del self.ext._content['vector']['samples']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_vector_slices(self):
+ cls_dict = self.ext.get_class_dict(('vector', 'slices'))
+ cls_dict['VectorSliceTest'] = [0] * 5
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ cls_dict['VectorSliceTest'] = [0] * 6
+ self.ext.check_valid()
+ del self.ext._content['vector']['slices']
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_invalid_affine(self):
+ self.ext._content['dcmmeta_affine'] = np.eye(3).tolist()
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_invalid_slice_dim(self):
+ self.ext._content['dcmmeta_slice_dim'] = 3
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ self.ext._content['dcmmeta_slice_dim'] = -1
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_invalid_shape(self):
+ self.ext._content['dcmmeta_shape'] = [2, 2]
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+ self.ext._content['dcmmeta_shape'] = [2, 2, 1, 1, 1, 2]
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_multiple_classes(self):
+ self.ext.get_class_dict(('global', 'const'))['Test'] = 0
+ self.ext.get_class_dict(('time', 'samples'))['Test'] = [0] * 3
+- assert_raises(dcmmeta.InvalidExtensionError, self.ext.check_valid)
++ with pytest.raises(dcmmeta.InvalidExtensionError):
++ self.ext.check_valid()
+
+ def test_dcmmeta_affine():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2),
+@@ -195,63 +203,51 @@
+ np.eye(4),
+ 2
+ )
+- ok_(np.allclose(ext.affine, np.diag([1, 2, 3, 4])))
+- assert_raises(ValueError,
+- setattr,
+- ext,
+- 'affine',
+- np.eye(3)
+- )
++ assert(np.allclose(ext.affine, np.diag([1, 2, 3, 4])))
++ with pytest.raises(ValueError):
++ setattr(ext, 'affine', np.eye(3))
+ ext.affine = np.eye(4)
+- ok_(np.allclose(ext.affine, np.eye(4)))
++ assert(np.allclose(ext.affine, np.eye(4)))
+
+ def test_dcmmeta_slice_dim():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2), np.eye(4))
+- eq_(ext.slice_dim, None)
+- assert_raises(ValueError,
+- setattr,
+- ext,
+- 'slice_dim',
+- 3
+- )
++ assert ext.slice_dim == None
++ with pytest.raises(ValueError):
++ setattr(ext, 'slice_dim', 3)
+ ext.slice_dim = 2
+- eq_(ext.slice_dim, 2)
++ assert ext.slice_dim == 2
+
+ def test_dcmmeta_shape():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2), np.eye(4))
+- eq_(ext.shape, (64, 64, 2))
+- assert_raises(ValueError,
+- setattr,
+- ext,
+- 'shape',
+- (64, 64)
+- )
++ assert ext.shape == (64, 64, 2)
++ with pytest.raises(ValueError):
++ setattr(ext, 'shape', (64, 64))
+ ext.shape = (128, 128, 64)
+- eq_(ext.shape, (128, 128, 64))
++ assert ext.shape == (128, 128, 64)
+
+ def test_dcmmeta_version():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2), np.eye(4))
+- eq_(ext.version, dcmmeta._meta_version)
++ assert ext.version == dcmmeta._meta_version
+ ext.version = 1.0
+- eq_(ext.version, 1.0)
++ assert ext.version == 1.0
+
+ def test_dcmmeta_slice_norm():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2),
+ np.eye(4),
+ np.eye(4),
+ 2)
+- ok_(np.allclose(ext.slice_normal, [0, 0, 1]))
++ assert(np.allclose(ext.slice_normal, [0, 0, 1]))
+ ext.slice_dim = 1
+- ok_(np.allclose(ext.slice_normal, [0, 1, 0]))
++ assert(np.allclose(ext.slice_normal, [0, 1, 0]))
+
+ def test_dcmmeta_n_slices():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 2),
+ np.eye(4),
+ np.eye(4),
+ 2)
+- eq_(ext.n_slices, 2)
++ assert ext.n_slices == 2
+ ext.slice_dim = 1
+- eq_(ext.n_slices, 64)
++ assert ext.n_slices == 64
+
+ class TestGetKeysClassesValues(object):
+ def setUp(self):
+@@ -267,36 +263,35 @@
+ self.ext.get_class_dict(classes)[key] = \
+ ([0] * self.ext.get_multiplicity(classes))
+
++ def setup_method(self, setUp):
++ self.setUp()
+
+ def test_get_keys(self):
+- eq_(set(self.keys), set(self.ext.get_keys()))
++ assert set(self.keys) == set(self.ext.get_keys())
+
+ def test_get_classification(self):
+- eq_(self.ext.get_classification('foo'), None)
++ assert self.ext.get_classification('foo') == None
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+- eq_(self.ext.get_classification(key), classes)
++ assert self.ext.get_classification(key) == classes
+
+ def test_get_class_dict(self):
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+- ok_(key in self.ext.get_class_dict(classes))
++ assert(key in self.ext.get_class_dict(classes))
+
+ def test_get_values(self):
+- eq_(self.ext.get_values('foo'), None)
++ assert self.ext.get_values('foo') == None
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+- eq_(self.ext.get_values(key),
+- [0] * self.ext.get_multiplicity(classes)
+- )
++ assert self.ext.get_values(key) == [0] * self.ext.get_multiplicity(classes)
++
+
+ def test_get_vals_and_class(self):
+- eq_(self.ext.get_values_and_class('foo'), (None, None))
++ assert self.ext.get_values_and_class('foo') == (None, None)
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+- eq_(self.ext.get_values_and_class(key),
+- ([0] * self.ext.get_multiplicity(classes), classes)
+- )
++ assert(self.ext.get_values_and_class(key) == ([0] * self.ext.get_multiplicity(classes), classes))
+
+ class TestFiltering(object):
+ def setUp(self):
+@@ -313,23 +308,26 @@
+ self.ext.get_class_dict(classes)[prefix + 'foobaz'] = \
+ ([0] * self.ext.get_multiplicity(classes))
+
++ def setup_method(self, setUp):
++ self.setUp()
++
+ def test_filter_all(self):
+ self.ext.filter_meta(lambda key, val: 'foo' in key)
+- eq_(len(self.ext.get_keys()), 0)
++ assert len(self.ext.get_keys()) == 0
+
+ def test_filter_some(self):
+ self.ext.filter_meta(lambda key, val: key.endswith('baz'))
+ keys = self.ext.get_keys()
+ for classes in self.ext.get_valid_classes():
+ prefix = '%s_%s_test_' % classes
+- ok_(prefix + 'foo' in keys)
+- ok_(not prefix + 'foobaz' in keys)
++ assert(prefix + 'foo' in keys)
++ assert(not prefix + 'foobaz' in keys)
+
+ def test_clear_slices(self):
+ self.ext.clear_slice_meta()
+ for base_cls, sub_cls in self.ext.get_valid_classes():
+ if sub_cls == 'slices':
+- eq_(len(self.ext.get_class_dict((base_cls, sub_cls))), 0)
++ assert len(self.ext.get_class_dict((base_cls, sub_cls))) == 0
+
+ class TestSimplify(object):
+ def setUp(self):
+@@ -338,6 +336,8 @@
+ np.eye(4),
+ 2
+ )
++ def setup_method(self, setUp):
++ self.setUp()
+
+ def test_simplify_global_slices(self):
+ glob_slc = self.ext.get_class_dict(('global', 'slices'))
+@@ -356,20 +356,20 @@
+ glob_slc['Test5'] += [idx2 for idx2 in range(3)]
+ self.ext.check_valid()
+
+- eq_(self.ext._simplify('Test1'), True)
+- eq_(self.ext.get_classification('Test1'), ('global', 'const'))
++ assert self.ext._simplify('Test1') == True
++ assert self.ext.get_classification('Test1') == ('global', 'const')
+
+- eq_(self.ext._simplify('Test2'), True)
+- eq_(self.ext.get_classification('Test2'), ('vector', 'samples'))
++ assert self.ext._simplify('Test2') == True
++ assert self.ext.get_classification('Test2'), ('vector', 'samples')
+
+- eq_(self.ext._simplify('Test3'), True)
+- eq_(self.ext.get_classification('Test3'), ('time', 'samples'))
++ assert self.ext._simplify('Test3') == True
++ assert self.ext.get_classification('Test3') == ('time', 'samples')
+
+- eq_(self.ext._simplify('Test4'), True)
+- eq_(self.ext.get_classification('Test4'), ('vector', 'slices'))
++ assert self.ext._simplify('Test4') == True
++ assert self.ext.get_classification('Test4'), ('vector', 'slices')
+
+- eq_(self.ext._simplify('Test5'), True)
+- eq_(self.ext.get_classification('Test5'), ('time', 'slices'))
++ assert self.ext._simplify('Test5') == True
++ assert self.ext.get_classification('Test5'), ('time', 'slices')
+
+ def test_simplify_vector_slices(self):
+ vec_slc = self.ext.get_class_dict(('vector', 'slices'))
+@@ -383,22 +383,22 @@
+ vec_slc['Test3'] += [slc_idx]
+ self.ext.check_valid()
+
+- eq_(self.ext._simplify('Test1'), True)
+- eq_(self.ext.get_classification('Test1'), ('global', 'const'))
++ assert self.ext._simplify('Test1') == True
++ assert self.ext.get_classification('Test1') == ('global', 'const')
+
+- eq_(self.ext._simplify('Test2'), True)
+- eq_(self.ext.get_classification('Test2'), ('time', 'samples'))
++ assert self.ext._simplify('Test2') == True
++ assert self.ext.get_classification('Test2') == ('time', 'samples')
+
+- eq_(self.ext._simplify('Test3'), True)
+- eq_(self.ext.get_classification('Test3'), ('time', 'slices'))
++ assert self.ext._simplify('Test3') == True
++ assert self.ext.get_classification('Test3') == ('time', 'slices')
+
+ def test_simplify_time_slices(self):
+ time_slc = self.ext.get_class_dict(('time', 'slices'))
+ time_slc['Test1'] = [0] * 3
+ self.ext.check_valid()
+
+- eq_(self.ext._simplify('Test1'), True)
+- eq_(self.ext.get_classification('Test1'), ('global', 'const'))
++ assert self.ext._simplify('Test1') == True
++ assert self.ext.get_classification('Test1') == ('global', 'const')
+
+ def test_simplify_time_samples(self):
+ time_smp = self.ext.get_class_dict(('time', 'samples'))
+@@ -408,20 +408,19 @@
+ time_smp['Test2'] += [vec_idx] * 5
+ self.ext.check_valid()
+
+- eq_(self.ext._simplify('Test1'), True)
+- eq_(self.ext.get_values_and_class('Test1'),
+- (0, ('global', 'const')))
++ assert self.ext._simplify('Test1') == True
++ assert self.ext.get_values_and_class('Test1') == (0, ('global', 'const'))
+
+- eq_(self.ext._simplify('Test2'), True)
+- eq_(self.ext.get_classification('Test2'), ('vector', 'samples'))
++ assert self.ext._simplify('Test2') == True
++ assert self.ext.get_classification('Test2') == ('vector', 'samples')
+
+ def test_simplify_vector_samples(self):
+ vector_smp = self.ext.get_class_dict(('vector', 'samples'))
+ vector_smp['Test1'] = [0] * 7
+ self.ext.check_valid()
+
+- eq_(self.ext._simplify('Test1'), True)
+- eq_(self.ext.get_classification('Test1'), ('global', 'const'))
++ assert self.ext._simplify('Test1') == True
++ assert self.ext.get_classification('Test1') == ('global', 'const')
+
+ def test_simp_sngl_slc_5d():
+ ext = dcmmeta.DcmMetaExtension.make_empty((64, 64, 1, 3, 5),
+@@ -432,9 +431,7 @@
+ glob_slc = ext.get_class_dict(('global', 'slices'))
+ glob_slc['test1'] = list(range(15))
+ ext._simplify('test1')
+- eq_(ext.get_values_and_class('test1'),
+- (list(range(15)), ('time','samples'))
+- )
++ assert ext.get_values_and_class('test1') == (list(range(15)), ('time','samples'))
+
+ class TestGetSubset(object):
+ def setUp(self):
+@@ -450,6 +447,9 @@
+ mult = self.ext.get_multiplicity(classes)
+ self.ext.get_class_dict(classes)[key] = list(range(mult))
+
++ def setup_method(self, setUp):
++ self.setUp()
++
+ def test_slice_subset(self):
+ for slc_idx in range(self.ext.n_slices):
+ sub = self.ext.get_subset(2, slc_idx)
+@@ -458,20 +458,15 @@
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+ if classes == ('time', 'slices'):
+- eq_(sub.get_values_and_class(key),
+- (slc_idx, ('global', 'const'))
+- )
++ assert sub.get_values_and_class(key) ==(slc_idx, ('global', 'const'))
++
+ elif classes == ('vector', 'slices'):
+- eq_(sub.get_values_and_class(key),
+- ((list(range(slc_idx, (3 * 5), 3)) * 7), ('time', 'samples'))
+- )
++ assert sub.get_values_and_class(key) == ((list(range(slc_idx, (3 * 5), 3)) * 7), ('time', 'samples'))
++
+ elif classes == ('global', 'slices'):
+- eq_(sub.get_values_and_class(key),
+- (list(range(slc_idx, (3 * 5 * 7), 3)), ('time', 'samples')))
++ assert sub.get_values_and_class(key) == (list(range(slc_idx, (3 * 5 * 7), 3)), ('time', 'samples'))
+ else:
+- eq_(sub.get_values_and_class(key),
+- self.ext.get_values_and_class(key)
+- )
++ assert sub.get_values_and_class(key) == self.ext.get_values_and_class(key)
+
+ def test_slice_subset_simplify(self):
+ vals = []
+@@ -497,10 +492,8 @@
+
+ sub = self.ext.get_subset(2, 1)
+ sub.check_valid()
+- eq_(sub.get_values_and_class('vec_slc_to_const'),
+- (1, ('global', 'const')))
+- eq_(sub.get_values_and_class('glb_slc_to_const'),
+- (1, ('global', 'const')))
++ assert sub.get_values_and_class('vec_slc_to_const') == (1, ('global', 'const'))
++ assert sub.get_values_and_class('glb_slc_to_const') == (1, ('global', 'const'))
+
+ def test_time_sample_subset(self):
+ for time_idx in range(5):
+@@ -509,37 +502,28 @@
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+ if classes[0] == 'time':
+- ok_(not classes in sub.get_valid_classes())
++ assert(not classes in sub.get_valid_classes())
+ if classes[1] == 'samples':
+- eq_(sub.get_values_and_class(key),
+- (list(range(time_idx, 5 * 7, 5)), ('vector', 'samples'))
+- )
++ assert sub.get_values_and_class(key) == (list(range(time_idx, 5 * 7, 5)), ('vector', 'samples'))
+ elif classes[1] == 'slices':
+- eq_(sub.get_values_and_class(key),
+- (self.ext.get_values(key), ('vector', 'slices')))
++ assert sub.get_values_and_class(key) == (self.ext.get_values(key), ('vector', 'slices'))
+ elif classes[0] == 'vector':
+ if classes[1] == 'samples':
+- eq_(sub.get_values_and_class(key),
+- self.ext.get_values_and_class(key)
+- )
++ assert sub.get_values_and_class(key) == self.ext.get_values_and_class(key)
+ elif classes[1] == 'slices':
+ start = time_idx * 3
+ end = start + 3
+- eq_(sub.get_values_and_class(key),
+- (list(range(start, end)), ('vector', 'slices')))
++ assert sub.get_values_and_class(key) == (list(range(start, end)), ('vector', 'slices'))
+ else:
+ if classes[1] == 'const':
+- eq_(sub.get_values_and_class(key),
+- self.ext.get_values_and_class(key)
+- )
++ assert sub.get_values_and_class(key) == self.ext.get_values_and_class(key)
+ elif classes[1] == 'slices':
+ vals = []
+ for vec_idx in range(7):
+ start = (vec_idx * (3 * 5)) + (time_idx * 3)
+ end = start + 3
+ vals += list(range(start, end))
+- eq_(sub.get_values_and_class(key),
+- (vals, ('global', 'slices')))
++ assert sub.get_values_and_class(key) == (vals, ('global', 'slices'))
+
+ def test_time_sample_subset_simplify(self):
+ #Test for simplification of time samples that become constant
+@@ -553,8 +537,7 @@
+ for time_idx in range(5):
+ sub = self.ext.get_subset(3, time_idx)
+ sub.check_valid()
+- eq_(sub.get_values_and_class('time_smp_to_const'),
+- (time_idx, ('global', 'const')))
++ assert sub.get_values_and_class('time_smp_to_const') == (time_idx, ('global', 'const'))
+
+ #Test for simplification of vector slices that become constant
+ vals = []
+@@ -581,10 +564,8 @@
+
+ sub = self.ext.get_subset(3, 1)
+ sub.check_valid()
+- eq_(sub.get_values_and_class('vec_slc_to_const'),
+- (1, ('global', 'const')))
+- eq_(sub.get_values_and_class('glb_slc_to_const'),
+- (1, ('global', 'const')))
++ assert sub.get_values_and_class('vec_slc_to_const') == (1, ('global', 'const'))
++ assert sub.get_values_and_class('glb_slc_to_const') == (1, ('global', 'const'))
+
+ #Test simplification of global slices that become vector slices or
+ #samples
+@@ -603,11 +584,9 @@
+ sub = self.ext.get_subset(3, time_idx)
+ sub.check_valid()
+ if time_idx == 1:
+- eq_(sub.get_values_and_class('glb_slc_to_vec'),
+- (list(range(3)), ('vector', 'slices')))
++ assert sub.get_values_and_class('glb_slc_to_vec') == (list(range(3)), ('vector', 'slices'))
+ else:
+- eq_(sub.get_values_and_class('glb_slc_to_vec'),
+- (list(range(7)), ('vector', 'samples')))
++ assert sub.get_values_and_class('glb_slc_to_vec') == (list(range(7)), ('vector', 'samples'))
+
+ def test_vector_sample_subset(self):
+ for vector_idx in range(7):
+@@ -616,35 +595,25 @@
+ for classes in self.ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+ if classes[0] == 'vector':
+- ok_(not classes in sub.get_valid_classes())
++ assert(not classes in sub.get_valid_classes())
+ if classes[1] == 'samples':
+- eq_(sub.get_values_and_class(key),
+- (vector_idx, ('global', 'const'))
+- )
++ assert sub.get_values_and_class(key) == (vector_idx, ('global', 'const'))
+ elif classes[1] == 'slices':
+- eq_(sub.get_values_and_class(key),
+- (list(range(3 * 5)), ('global', 'slices'))
+- )
++ assert sub.get_values_and_class(key) == (list(range(3 * 5)), ('global', 'slices'))
+ elif classes[0] == 'time':
+ if classes[1] == 'samples': #Could be const
+ start = vector_idx * 5
+ end = start + 5
+- eq_(sub.get_values_and_class(key),
+- (list(range(start, end)), classes)
+- )
++ assert sub.get_values_and_class(key) == (list(range(start, end)), classes)
+ elif classes[1] == 'slices':
+- eq_(sub.get_values_and_class(key),
+- self.ext.get_values_and_class(key))
++ assert sub.get_values_and_class(key) == self.ext.get_values_and_class(key)
+ else:
+ if classes[1] == 'const':
+- eq_(sub.get_values_and_class(key),
+- self.ext.get_values_and_class(key)
+- )
++ assert sub.get_values_and_class(key) == self.ext.get_values_and_class(key)
+ elif classes[1] == 'slices': #Could be const or time samples or time slices
+ start = vector_idx * (3 * 5)
+ end = start + (3 * 5)
+- eq_(sub.get_values_and_class(key),
+- (list(range(start, end)), classes))
++ assert sub.get_values_and_class(key) == (list(range(start, end)), classes)
+
+ def test_vector_sample_subset_simplify(self):
+
+@@ -659,8 +628,7 @@
+ self.ext.get_class_dict(('time', 'samples'))['time_smp_to_const'] = \
+ vals
+ sub = self.ext.get_subset(4, 1)
+- eq_(sub.get_values_and_class('time_smp_to_const'),
+- (1, ('global', 'const')))
++ assert sub.get_values_and_class('time_smp_to_const') == (1, ('global', 'const'))
+
+ #Test for simplification of global slices that become constant, time
+ #samples, or time slices
+@@ -681,14 +649,11 @@
+ sub = self.ext.get_subset(4, vector_idx)
+ sub.check_valid()
+ if vector_idx == 1:
+- eq_(sub.get_values_and_class('glb_slc'),
+- (1, ('global', 'const')))
++ assert sub.get_values_and_class('glb_slc') == (1, ('global', 'const'))
+ elif vector_idx == 2:
+- eq_(sub.get_values_and_class('glb_slc'),
+- (list(range(3)), ('time', 'slices')))
++ assert sub.get_values_and_class('glb_slc') == (list(range(3)), ('time', 'slices'))
+ else:
+- eq_(sub.get_values_and_class('glb_slc'),
+- (list(range(5)), ('time', 'samples')))
++ assert sub.get_values_and_class('glb_slc') == (list(range(5)), ('time', 'samples'))
+
+ class TestChangeClass(object):
+ def setUp(self):
+@@ -707,80 +672,55 @@
+ vals = list(range(mult))
+ self.ext.get_class_dict(classes)[key] = vals
+
++ def setup_method(self, setUp):
++ self.setUp()
++
+ def test_change_none(self):
+- eq_(self.ext._get_changed_class('None_test', ('global', 'const')),
+- None)
+- eq_(self.ext._get_changed_class('None_test', ('global', 'slices')),
+- [None] * (3 * 5 * 7))
+- eq_(self.ext._get_changed_class('None_test', ('time', 'samples')),
+- [None] * (5 * 7))
+- eq_(self.ext._get_changed_class('None_test', ('time', 'slices')),
+- [None] * 3)
+- eq_(self.ext._get_changed_class('None_test', ('vector', 'samples')),
+- [None] * 7)
+- eq_(self.ext._get_changed_class('None_test', ('vector', 'slices')),
+- [None] * (3 * 5))
++ assert self.ext._get_changed_class('None_test', ('global', 'const')) == None
++ assert self.ext._get_changed_class('None_test', ('global', 'slices')) == [None] * (3 * 5 * 7)
++ assert self.ext._get_changed_class('None_test', ('time', 'samples')) ==[None] * (5 * 7)
++ assert self.ext._get_changed_class('None_test', ('time', 'slices')) == [None] * 3
++ assert self.ext._get_changed_class('None_test', ('vector', 'samples')) == [None] * 7
++ assert self.ext._get_changed_class('None_test', ('vector', 'slices')) == [None] * (3 * 5)
+
+ def test_change_global_const(self):
+- eq_(self.ext._get_changed_class('global_const_test',
+- ('global', 'slices')),
+- [0] * (3 * 5 * 7))
+- eq_(self.ext._get_changed_class('global_const_test',
+- ('time', 'samples')),
+- [0] * (5 * 7))
+- eq_(self.ext._get_changed_class('global_const_test',
+- ('time', 'slices')),
+- [0] * 3)
+- eq_(self.ext._get_changed_class('global_const_test',
+- ('vector', 'samples')),
+- [0] * 7)
+- eq_(self.ext._get_changed_class('global_const_test',
+- ('vector', 'slices')),
+- [0] * (3 * 5))
++ assert self.ext._get_changed_class('global_const_test', ('global', 'slices')) == [0] * (3 * 5 * 7)
++ assert self.ext._get_changed_class('global_const_test', ('time', 'samples')) == [0] * (5 * 7)
++ assert self.ext._get_changed_class('global_const_test', ('time', 'slices')) == [0] * 3
++ assert self.ext._get_changed_class('global_const_test', ('vector', 'samples')) == [0] * 7
++ assert self.ext._get_changed_class('global_const_test', ('vector', 'slices')) == [0] * (3 * 5)
+
+ def test_change_vector_samples(self):
+ vals = []
+ for vector_idx in range(7):
+ vals += [vector_idx] * 15
+- eq_(self.ext._get_changed_class('vector_samples_test',
+- ('global', 'slices')),
+- vals)
++ assert self.ext._get_changed_class('vector_samples_test', ('global', 'slices')) == vals
+ vals = []
+ for vector_idx in range(7):
+ vals += [vector_idx] * 5
+- eq_(self.ext._get_changed_class('vector_samples_test',
+- ('time', 'samples')),
+- vals)
++ assert self.ext._get_changed_class('vector_samples_test', ('time', 'samples')) == vals
+
+ def test_change_time_samples(self):
+ vals = []
+ for time_idx in range(5 * 7):
+ vals += [time_idx] * 3
+- eq_(self.ext._get_changed_class('time_samples_test',
+- ('global', 'slices')),
+- vals)
++ assert self.ext._get_changed_class('time_samples_test', ('global', 'slices')) == vals
+
+ def test_time_slices(self):
+ vals = []
+ for time_idx in range(5 * 7):
+ vals += list(range(3))
+- eq_(self.ext._get_changed_class('time_slices_test',
+- ('global', 'slices')),
+- vals)
++ assert self.ext._get_changed_class('time_slices_test', ('global', 'slices')) == vals
+ vals = []
+ for time_idx in range(5):
+ vals += list(range(3))
+- eq_(self.ext._get_changed_class('time_slices_test',
+- ('vector', 'slices')),
+- vals)
++ assert self.ext._get_changed_class('time_slices_test', ('vector', 'slices')) == vals
+
+ def test_vector_slices(self):
+ vals = []
+ for vector_idx in range(7):
+ vals += list(range(15))
+- eq_(self.ext._get_changed_class('vector_slices_test',
+- ('global', 'slices')),
+- vals)
++ assert self.ext._get_changed_class('vector_slices_test', ('global', 'slices')) == vals
+
+
+ def test_from_sequence_2d_to_3d():
+@@ -799,12 +739,9 @@
+ ext2.get_class_dict(('global', 'const'))['var'] = 2
+
+ merged = dcmmeta.DcmMetaExtension.from_sequence([ext1, ext2], 2)
+- eq_(merged.get_values_and_class('const'),
+- (1, ('global', 'const')))
+- eq_(merged.get_values_and_class('var'),
+- ([1, 2], ('global', 'slices')))
+- eq_(merged.get_values_and_class('missing'),
+- ([1, None], ('global', 'slices')))
++ assert merged.get_values_and_class('const') == (1, ('global', 'const'))
++ assert merged.get_values_and_class('var') == ([1, 2], ('global', 'slices'))
++ assert merged.get_values_and_class('missing') == ([1, None], ('global', 'slices'))
+
+ def test_from_sequence_3d_to_4d():
+ for dim_name, dim in (('time', 3), ('vector', 4)):
+@@ -828,18 +765,12 @@
+ ext2.get_class_dict(('global', 'slices'))['global_slices_var'] = [1, 2]
+
+ merged = dcmmeta.DcmMetaExtension.from_sequence([ext1, ext2], dim)
+- eq_(merged.get_values_and_class('global_const_const'),
+- (1, ('global', 'const')))
+- eq_(merged.get_values_and_class('global_const_var'),
+- ([1, 2], (dim_name, 'samples')))
+- eq_(merged.get_values_and_class('global_const_missing'),
+- ([1, None], (dim_name, 'samples')))
+- eq_(merged.get_values_and_class('global_slices_const'),
+- ([0, 1], (dim_name, 'slices')))
+- eq_(merged.get_values_and_class('global_slices_var'),
+- ([0, 1, 1, 2], ('global', 'slices')))
+- eq_(merged.get_values_and_class('global_slices_missing'),
+- ([0, 1, None, None], ('global', 'slices')))
++ assert merged.get_values_and_class('global_const_const'), (1, ('global', 'const'))
++ assert merged.get_values_and_class('global_const_var') == ([1, 2], (dim_name, 'samples'))
++ assert merged.get_values_and_class('global_const_missing') == ([1, None], (dim_name, 'samples'))
++ assert merged.get_values_and_class('global_slices_const') == ([0, 1], (dim_name, 'slices'))
++ assert merged.get_values_and_class('global_slices_var') == ([0, 1, 1, 2], ('global', 'slices'))
++ assert merged.get_values_and_class('global_slices_missing') == ([0, 1, None, None], ('global', 'slices'))
+
+ def test_from_sequence_4d_time_to_5d():
+ ext1 = dcmmeta.DcmMetaExtension.make_empty((2, 2, 2, 2),
+@@ -873,30 +804,18 @@
+ ext2.get_class_dict(('time', 'slices'))['time_slices_var'] = [1, 2]
+
+ merged = dcmmeta.DcmMetaExtension.from_sequence([ext1, ext2], 4)
+- eq_(merged.get_values_and_class('global_const_const'),
+- (1, ('global', 'const')))
+- eq_(merged.get_values_and_class('global_const_var'),
+- ([1, 2], ('vector', 'samples')))
+- eq_(merged.get_values_and_class('global_const_missing'),
+- ([1, None], ('vector', 'samples')))
+- eq_(merged.get_values_and_class('global_slices_const'),
+- ([0, 1, 2, 3], ('vector', 'slices')))
+- eq_(merged.get_values_and_class('global_slices_var'),
+- ([0, 1, 2, 3, 1, 2, 3, 4], ('global', 'slices')))
+- eq_(merged.get_values_and_class('global_slices_missing'),
+- ([0, 1, 2, 3, None, None, None, None], ('global', 'slices')))
+- eq_(merged.get_values_and_class('time_samples_const'),
+- ([0, 1, 0, 1], ('time', 'samples')))
+- eq_(merged.get_values_and_class('time_samples_var'),
+- ([0, 1, 1, 2], ('time', 'samples')))
+- eq_(merged.get_values_and_class('time_samples_missing'),
+- ([0, 1, None, None], ('time', 'samples')))
+- eq_(merged.get_values_and_class('time_slices_const'),
+- ([0, 1], ('time', 'slices')))
+- eq_(merged.get_values_and_class('time_slices_var'),
+- ([0, 1, 0, 1, 1, 2, 1, 2], ('global', 'slices')))
+- eq_(merged.get_values_and_class('time_slices_missing'),
+- ([0, 1, 0, 1, None, None, None, None], ('global', 'slices')))
++ assert merged.get_values_and_class('global_const_const') == (1, ('global', 'const'))
++ assert merged.get_values_and_class('global_const_var') == ([1, 2], ('vector', 'samples'))
++ assert merged.get_values_and_class('global_const_missing') == ([1, None], ('vector', 'samples'))
++ assert merged.get_values_and_class('global_slices_const') == ([0, 1, 2, 3], ('vector', 'slices'))
++ assert merged.get_values_and_class('global_slices_var') == ([0, 1, 2, 3, 1, 2, 3, 4], ('global', 'slices'))
++ assert merged.get_values_and_class('global_slices_missing') == ([0, 1, 2, 3, None, None, None, None], ('global', 'slices'))
++ assert merged.get_values_and_class('time_samples_const') == ([0, 1, 0, 1], ('time', 'samples'))
++ assert merged.get_values_and_class('time_samples_var') == ([0, 1, 1, 2], ('time', 'samples'))
++ assert merged.get_values_and_class('time_samples_missing') == ([0, 1, None, None], ('time', 'samples'))
++ assert merged.get_values_and_class('time_slices_const') == ([0, 1], ('time', 'slices'))
++ assert merged.get_values_and_class('time_slices_var') == ([0, 1, 0, 1, 1, 2, 1, 2], ('global', 'slices'))
++ assert merged.get_values_and_class('time_slices_missing') == ([0, 1, 0, 1, None, None, None, None], ('global', 'slices'))
+
+ def test_from_sequence_no_slc():
+ ext1 = dcmmeta.DcmMetaExtension.make_empty((2, 2, 2), np.eye(4))
+@@ -905,19 +824,18 @@
+
+ def test_nifti_wrapper_init():
+ nii = nb.Nifti1Image(np.zeros((5, 5, 5)), np.eye(4))
+- assert_raises(dcmmeta.MissingExtensionError,
+- dcmmeta.NiftiWrapper,
+- nii)
++ with pytest.raises(dcmmeta.MissingExtensionError):
++ dcmmeta.NiftiWrapper(nii)
+ hdr = nii.header
+ ext = dcmmeta.DcmMetaExtension.make_empty((5, 5, 5), np.eye(4))
+ hdr.extensions.append(ext)
+ nw = dcmmeta.NiftiWrapper(nii)
+- eq_(nw.meta_ext, ext)
++ assert nw.meta_ext == ext
+
+ nii2 = nb.Nifti1Image(np.zeros((5, 5, 5)), np.eye(4))
+ nw2 = dcmmeta.NiftiWrapper(nii, True)
+ ext2 = nw2.meta_ext
+- eq_(ext, ext2)
++ assert ext == ext2
+
+ class TestMetaValid(object):
+ def setUp(self):
+@@ -926,7 +844,10 @@
+ hdr.set_dim_info(None, None, 2)
+ self.nw = dcmmeta.NiftiWrapper(nii, True)
+ for classes in self.nw.meta_ext.get_valid_classes():
+- ok_(self.nw.meta_valid(classes))
++ assert(self.nw.meta_valid(classes))
++
++ def setup_method(self, setUp):
++ self.setUp()
+
+ def test_time_samples_changed(self):
+ self.nw.meta_ext.shape = (5, 5, 5, 3, 9)
+@@ -934,9 +855,9 @@
+ if classes in (('time', 'samples'),
+ ('vector', 'slices'),
+ ('global', 'slices')):
+- eq_(self.nw.meta_valid(classes), False)
++ assert self.nw.meta_valid(classes) == False
+ else:
+- ok_(self.nw.meta_valid(classes))
++ assert(self.nw.meta_valid(classes))
+
+ def test_vector_samples_changed(self):
+ self.nw.meta_ext.shape = (5, 5, 5, 7, 3)
+@@ -944,17 +865,17 @@
+ if classes in (('time', 'samples'),
+ ('vector', 'samples'),
+ ('global', 'slices')):
+- eq_(self.nw.meta_valid(classes), False)
++ assert self.nw.meta_valid(classes) == False
+ else:
+- ok_(self.nw.meta_valid(classes))
++ assert(self.nw.meta_valid(classes))
+
+ def test_slice_dim_changed(self):
+ self.nw.meta_ext.slice_dim = 0
+ for classes in self.nw.meta_ext.get_valid_classes():
+ if classes[1] == 'slices':
+- eq_(self.nw.meta_valid(classes), False)
++ assert self.nw.meta_valid(classes) == False
+ else:
+- ok_(self.nw.meta_valid(classes))
++ assert(self.nw.meta_valid(classes))
+
+ def test_slice_dir_changed(self):
+ aff = self.nw.nii_img.affine
+@@ -966,9 +887,9 @@
+
+ for classes in self.nw.meta_ext.get_valid_classes():
+ if classes[1] == 'slices':
+- eq_(self.nw.meta_valid(classes), False)
++ assert self.nw.meta_valid(classes) == False
+ else:
+- ok_(self.nw.meta_valid(classes))
++ assert(self.nw.meta_valid(classes))
+
+ class TestGetMeta(object):
+ def setUp(self):
+@@ -987,89 +908,67 @@
+ vals = list(range(mult))
+ self.nw.meta_ext.get_class_dict(classes)[key] = vals
+
+- def test_invalid_index(self):
+- assert_raises(IndexError,
+- self.nw.get_meta('time_samples_test'),
+- (0, 0, 0, 0))
+- assert_raises(IndexError,
+- self.nw.get_meta('time_samples_test'),
+- (0, 0, 0, 0, 0, 0))
+- assert_raises(IndexError,
+- self.nw.get_meta('time_samples_test'),
+- (6, 0, 0, 0, 0))
+- assert_raises(IndexError,
+- self.nw.get_meta('time_samples_test'),
+- (-1, 0, 0, 0, 0))
++ def setup_method(self, setUp):
++ self.setUp()
+
+ def test_get_item(self):
+ for classes in self.nw.meta_ext.get_valid_classes():
+ key = '%s_%s_test' % classes
+ if classes == ('global', 'const'):
+- eq_(self.nw[key], 0)
++ assert self.nw[key] == 0
+ else:
+- assert_raises(KeyError,
+- self.nw.__getitem__,
+- key)
++ with pytest.raises(KeyError):
++ self.nw.__getitem__(key)
+
+ def test_get_const(self):
+- eq_(self.nw.get_meta('global_const_test'), 0)
+- eq_(self.nw.get_meta('global_const_test', (0, 0, 0, 0, 0)), 0)
+- eq_(self.nw.get_meta('global_const_test', (0, 0, 3, 4, 5)), 0)
++ assert self.nw.get_meta('global_const_test') == 0
++ assert self.nw.get_meta('global_const_test', (0, 0, 0, 0, 0)) == 0
++ assert self.nw.get_meta('global_const_test', (0, 0, 3, 4, 5)) == 0
+
+ def test_get_global_slices(self):
+- eq_(self.nw.get_meta('global_slices_test'), None)
+- eq_(self.nw.get_meta('global_slices_test', None, 0), 0)
++ assert self.nw.get_meta('global_slices_test') == None
++ assert self.nw.get_meta('global_slices_test', None, 0) == 0
+ for vector_idx in range(9):
+ for time_idx in range(7):
+ for slice_idx in range(5):
+ idx = (0, 0, slice_idx, time_idx, vector_idx)
+- eq_(self.nw.get_meta('global_slices_test', idx),
+- slice_idx + (time_idx * 5) + (vector_idx * 7 * 5)
+- )
++ assert self.nw.get_meta('global_slices_test', idx) == slice_idx + (time_idx * 5) + (vector_idx * 7 * 5)
+
+ def test_get_vector_slices(self):
+- eq_(self.nw.get_meta('vector_slices_test'), None)
+- eq_(self.nw.get_meta('vector_slices_test', None, 0), 0)
++ assert self.nw.get_meta('vector_slices_test') == None
++ assert self.nw.get_meta('vector_slices_test', None, 0) == 0
+ for vector_idx in range(9):
+ for time_idx in range(7):
+ for slice_idx in range(5):
+ idx = (0, 0, slice_idx, time_idx, vector_idx)
+- eq_(self.nw.get_meta('vector_slices_test', idx),
+- slice_idx + (time_idx * 5)
+- )
++ assert self.nw.get_meta('vector_slices_test', idx) == slice_idx + (time_idx * 5)
+
+ def test_get_time_slices(self):
+- eq_(self.nw.get_meta('time_slices_test'), None)
+- eq_(self.nw.get_meta('time_slices_test', None, 0), 0)
++ assert self.nw.get_meta('time_slices_test') == None
++ assert self.nw.get_meta('time_slices_test', None, 0) == 0
+ for vector_idx in range(9):
+ for time_idx in range(7):
+ for slice_idx in range(5):
+ idx = (0, 0, slice_idx, time_idx, vector_idx)
+- eq_(self.nw.get_meta('time_slices_test', idx),
+- slice_idx
+- )
++ assert self.nw.get_meta('time_slices_test', idx) == slice_idx
+
+ def test_get_vector_samples(self):
+- eq_(self.nw.get_meta('vector_samples_test'), None)
+- eq_(self.nw.get_meta('vector_samples_test', None, 0), 0)
++ assert self.nw.get_meta('vector_samples_test') == None
++ assert self.nw.get_meta('vector_samples_test', None, 0) == 0
+ for vector_idx in range(9):
+ for time_idx in range(7):
+ for slice_idx in range(5):
+ idx = (0, 0, slice_idx, time_idx, vector_idx)
+- eq_(self.nw.get_meta('vector_samples_test', idx),
+- vector_idx
+- )
++ assert self.nw.get_meta('vector_samples_test', idx) == vector_idx
+
+ def get_time_samples(self):
+- eq_(self.nw.get_meta('time_samples_test'), None)
+- eq_(self.nw.get_meta('time_samples_test', None, 0), 0)
++ assert self.nw.get_meta('time_samples_test') == None
++ assert self.nw.get_meta('time_samples_test', None, 0) == 0
+ for vector_idx in range(9):
+ for time_idx in range(7):
+ for slice_idx in range(5):
+ idx = (0, 0, slice_idx, time_idx, vector_idx)
+- eq_(self.nw.get_meta('time_samples_test', idx),
+- time_idx + (vector_idx * 7)
+- )
++ assert self.nw.get_meta('time_samples_test', idx) == time_idx + (vector_idx * 7)
+
+ class TestSplit(object):
+ def setUp(self):
+@@ -1089,10 +988,13 @@
+ vals = list(range(mult))
+ self.nw.meta_ext.get_class_dict(classes)[key] = vals
+
++ def setup_method(self, setUp):
++ self.setUp()
++
+ def test_split_slice(self):
+ for split_idx, nw_split in enumerate(self.nw.split(2)):
+- eq_(nw_split.nii_img.shape, (3, 3, 1, 5, 7))
+- ok_(np.allclose(nw_split.nii_img.affine,
++ assert nw_split.nii_img.shape == (3, 3, 1, 5, 7)
++ assert(np.allclose(nw_split.nii_img.affine,
+ np.c_[[1.1, 0.0, 0.0, 0.0],
+ [0.0, 1.1, 0.0, 0.0],
+ [0.0, 0.0, 1.1, 0.0],
+@@ -1100,25 +1002,25 @@
+ ]
+ )
+ )
+- ok_(np.all(nw_split.nii_img.get_data() ==
++ assert(np.all(nw_split.nii_img.get_data() ==
+ self.arr[:, :, split_idx:split_idx+1, :, :])
+ )
+
+ def test_split_time(self):
+ for split_idx, nw_split in enumerate(self.nw.split(3)):
+- eq_(nw_split.nii_img.shape, (3, 3, 3, 1, 7))
+- ok_(np.allclose(nw_split.nii_img.affine,
++ assert nw_split.nii_img.shape == (3, 3, 3, 1, 7)
++ assert(np.allclose(nw_split.nii_img.affine,
+ np.diag([1.1, 1.1, 1.1, 1.0])))
+- ok_(np.all(nw_split.nii_img.get_data() ==
++ assert(np.all(nw_split.nii_img.get_data() ==
+ self.arr[:, :, :, split_idx:split_idx+1, :])
+ )
+
+ def test_split_vector(self):
+ for split_idx, nw_split in enumerate(self.nw.split(4)):
+- eq_(nw_split.nii_img.shape, (3, 3, 3, 5))
+- ok_(np.allclose(nw_split.nii_img.affine,
++ assert nw_split.nii_img.shape == (3, 3, 3, 5)
++ assert(np.allclose(nw_split.nii_img.affine,
+ np.diag([1.1, 1.1, 1.1, 1.0])))
+- ok_(np.all(nw_split.nii_img.get_data() ==
++ assert(np.all(nw_split.nii_img.get_data() ==
+ self.arr[:, :, :, :, split_idx])
+ )
+
+@@ -1128,7 +1030,7 @@
+ nw = dcmmeta.NiftiWrapper(nii, True)
+
+ for split_idx, nw_split in enumerate(nw.split(2)):
+- eq_(nw_split.nii_img.shape, (3, 3, 1))
++ assert nw_split.nii_img.shape == (3, 3, 1)
+
+
+ def test_from_dicom():
+@@ -1142,15 +1044,13 @@
+ meta = {'EchoTime': 40}
+ nw = dcmmeta.NiftiWrapper.from_dicom(src_dcm, meta)
+ hdr = nw.nii_img.header
+- eq_(nw.nii_img.shape, (192, 192, 1))
+- ok_(np.allclose(np.dot(np.diag([-1., -1., 1., 1.]), src_dw.get_affine()),
++ assert nw.nii_img.shape == (192, 192, 1)
++ assert(np.allclose(np.dot(np.diag([-1., -1., 1., 1.]), src_dw.get_affine()),
+ nw.nii_img.affine)
+ )
+- eq_(hdr.get_xyzt_units(), ('mm', 'sec'))
+- eq_(hdr.get_dim_info(), (0, 1, 2))
+- eq_(nw.meta_ext.get_values_and_class('EchoTime'),
+- (40, ('global', 'const'))
+- )
++ assert hdr.get_xyzt_units() == ('mm', 'sec')
++ assert hdr.get_dim_info() == (0, 1, 2)
++ assert nw.meta_ext.get_values_and_class('EchoTime') == (40, ('global', 'const'))
+
+ def test_from_2d_slice_to_3d():
+ slice_nws = []
+@@ -1168,22 +1068,18 @@
+ slice_nws.append(nw)
+
+ merged = dcmmeta.NiftiWrapper.from_sequence(slice_nws, 2)
+- eq_(merged.nii_img.shape, (4, 4, 3))
+- ok_(np.allclose(merged.nii_img.affine,
++ assert merged.nii_img.shape == (4, 4, 3)
++ assert(np.allclose(merged.nii_img.affine,
+ np.diag((1.1, 1.1, 0.5, 1.0)))
+ )
+- eq_(merged.meta_ext.get_values_and_class('EchoTime'),
+- (40, ('global', 'const'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('SliceLocation'),
+- (list(range(3)), ('global', 'slices'))
+- )
++ assert merged.meta_ext.get_values_and_class('EchoTime') == (40, ('global', 'const'))
++ assert merged.meta_ext.get_values_and_class('SliceLocation') == (list(range(3)), ('global', 'slices'))
+ merged_hdr = merged.nii_img.header
+- eq_(merged_hdr.get_dim_info(), (0, 1, 2))
+- eq_(merged_hdr.get_xyzt_units(), ('mm', 'sec'))
++ assert merged_hdr.get_dim_info() == (0, 1, 2)
++ assert merged_hdr.get_xyzt_units() == ('mm', 'sec')
+ merged_data = merged.nii_img.get_data()
+ for idx in range(3):
+- ok_(np.all(merged_data[:, :, idx] ==
++ assert(np.all(merged_data[:, :, idx] ==
+ np.arange(idx * (4 * 4), (idx + 1) * (4 * 4)).reshape(4, 4))
+ )
+
+@@ -1207,28 +1103,20 @@
+ time_nws.append(nw)
+
+ merged = dcmmeta.NiftiWrapper.from_sequence(time_nws, 3)
+- eq_(merged.nii_img.shape, (4, 4, 4, 3))
+- ok_(np.allclose(merged.nii_img.affine,
++ assert merged.nii_img.shape == (4, 4, 4, 3)
++ assert(np.allclose(merged.nii_img.affine,
+ np.diag((1.1, 1.1, 1.1, 1.0)))
+ )
+- eq_(merged.meta_ext.get_values_and_class('PatientID'),
+- ('Test', ('global', 'const'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('EchoTime'),
+- ([0, 1, 2], ('time', 'samples'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('SliceLocation'),
+- (list(range(4)), ('time', 'slices'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('AcquisitionTime'),
+- (list(range(4 * 3)), ('global', 'slices'))
+- )
++ assert merged.meta_ext.get_values_and_class('PatientID') == ('Test', ('global', 'const'))
++ assert merged.meta_ext.get_values_and_class('EchoTime') == ([0, 1, 2], ('time', 'samples'))
++ assert merged.meta_ext.get_values_and_class('SliceLocation') == (list(range(4)), ('time', 'slices'))
++ assert merged.meta_ext.get_values_and_class('AcquisitionTime') == (list(range(4 * 3)), ('global', 'slices'))
+ merged_hdr = merged.nii_img.header
+- eq_(merged_hdr.get_dim_info(), (0, 1, 2))
+- eq_(merged_hdr.get_xyzt_units(), ('mm', 'sec'))
++ assert merged_hdr.get_dim_info() == (0, 1, 2)
++ assert merged_hdr.get_xyzt_units() == ('mm', 'sec')
+ merged_data = merged.nii_img.get_data()
+ for idx in range(3):
+- ok_(np.all(merged_data[:, :, :, idx] ==
++ assert(np.all(merged_data[:, :, :, idx] ==
+ np.arange(idx * (4 * 4 * 4),
+ (idx + 1) * (4 * 4 * 4)).reshape(4, 4, 4))
+ )
+@@ -1253,28 +1141,20 @@
+ vector_nws.append(nw)
+
+ merged = dcmmeta.NiftiWrapper.from_sequence(vector_nws, 4)
+- eq_(merged.nii_img.shape, (4, 4, 4, 1, 3))
+- ok_(np.allclose(merged.nii_img.affine,
++ assert merged.nii_img.shape == (4, 4, 4, 1, 3)
++ assert(np.allclose(merged.nii_img.affine,
+ np.diag((1.1, 1.1, 1.1, 1.0)))
+ )
+- eq_(merged.meta_ext.get_values_and_class('PatientID'),
+- ('Test', ('global', 'const'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('EchoTime'),
+- ([0, 1, 2], ('vector', 'samples'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('SliceLocation'),
+- (list(range(4)), ('vector', 'slices'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('AcquisitionTime'),
+- (list(range(4 * 3)), ('global', 'slices'))
+- )
++ assert merged.meta_ext.get_values_and_class('PatientID') == ('Test', ('global', 'const'))
++ assert merged.meta_ext.get_values_and_class('EchoTime') == ([0, 1, 2], ('vector', 'samples'))
++ assert merged.meta_ext.get_values_and_class('SliceLocation') == (list(range(4)), ('vector', 'slices'))
++ assert merged.meta_ext.get_values_and_class('AcquisitionTime') == (list(range(4 * 3)), ('global', 'slices'))
+ merged_hdr = merged.nii_img.header
+- eq_(merged_hdr.get_dim_info(), (0, 1, 2))
+- eq_(merged_hdr.get_xyzt_units(), ('mm', 'sec'))
++ assert merged_hdr.get_dim_info() == (0, 1, 2)
++ assert merged_hdr.get_xyzt_units(), ('mm', 'sec')
+ merged_data = merged.nii_img.get_data()
+ for idx in range(3):
+- ok_(np.all(merged_data[:, :, :, 0, idx] ==
++ assert(np.all(merged_data[:, :, :, 0, idx] ==
+ np.arange(idx * (4 * 4 * 4),
+ (idx + 1) * (4 * 4 * 4)).reshape(4, 4, 4))
+ )
+@@ -1300,8 +1180,8 @@
+
+ merged = dcmmeta.NiftiWrapper.from_sequence(time_nws)
+ merged_hdr = merged.nii_img.header
+- eq_(merged_hdr.get_dim_info(), (None, None, 2))
+- eq_(merged_hdr.get_xyzt_units(), ('mm', 'unknown'))
++ assert merged_hdr.get_dim_info() == (None, None, 2)
++ assert merged_hdr.get_xyzt_units(), ('mm', 'unknown')
+
+ def test_merge_with_slc_and_without():
+ #Test merging two data sets where one has per slice meta and other does not
+@@ -1325,18 +1205,12 @@
+ input_nws.append(nw)
+
+ merged = dcmmeta.NiftiWrapper.from_sequence(input_nws)
+- eq_(merged.nii_img.shape, (4, 4, 4, 3))
+- ok_(np.allclose(merged.nii_img.affine,
++ assert merged.nii_img.shape == (4, 4, 4, 3)
++ assert(np.allclose(merged.nii_img.affine,
+ np.diag((1.1, 1.1, 1.1, 1.0)))
+ )
+- eq_(merged.meta_ext.get_values_and_class('PatientID'),
+- ('Test', ('global', 'const'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('EchoTime'),
+- ([0, 1, 2], ('time', 'samples'))
+- )
+- eq_(merged.meta_ext.get_values_and_class('SliceLocation'),
+- (list(range(4)) + ([None] * 8), ('global', 'slices'))
+- )
++ assert merged.meta_ext.get_values_and_class('PatientID') == ('Test', ('global', 'const'))
++ assert merged.meta_ext.get_values_and_class('EchoTime') == ([0, 1, 2], ('time', 'samples'))
++ assert merged.meta_ext.get_values_and_class('SliceLocation') == (list(range(4)) + ([None] * 8), ('global', 'slices'))
+ merged_hdr = merged.nii_img.header
+- eq_(merged_hdr.get_xyzt_units(), ('mm', 'sec'))
+\ No newline at end of file
++ assert merged_hdr.get_xyzt_units() == ('mm', 'sec')
+--- a/test/test_dcmstack.py
++++ b/test/test_dcmstack.py
+@@ -11,7 +11,7 @@
+ from os import path
+
+ import numpy as np
+-from nose.tools import ok_, eq_, assert_raises
++import pytest
+
+ from . import test_dir, src_dir
+
+@@ -70,53 +70,33 @@
+ def test_key_regex_filter():
+ filt = dcmstack.make_key_regex_filter(['test', 'another'],
+ ['2', 'another test'])
+- ok_(filt('test', 1))
+- ok_(filt('test another', 1))
+- ok_(filt('another tes', 1))
+- ok_(not filt('test2', 1))
+- ok_(not filt('2 another', 1))
+- ok_(not filt('another test', 1))
++ assert(filt('test', 1))
++ assert(filt('test another', 1))
++ assert(filt('another tes', 1))
++ assert(not filt('test2', 1))
++ assert(not filt('2 another', 1))
++ assert(not filt('another test', 1))
+
+ class TestReorderVoxels(object):
+- def setUp(self):
++ def setup_method(self, method):
+ self.vox_array = np.arange(16).reshape((2, 2, 2, 2))
+ self.affine = np.eye(4)
+
+ def test_invalid_vox_order(self):
+- assert_raises(ValueError,
+- dcmstack.reorder_voxels,
+- self.vox_array,
+- self.affine,
+- 'lra',
+- )
+- assert_raises(ValueError,
+- dcmstack.reorder_voxels,
+- self.vox_array,
+- self.affine,
+- 'rpil',
+- )
+- assert_raises(ValueError,
+- dcmstack.reorder_voxels,
+- self.vox_array,
+- self.affine,
+- 'lrz',
+- )
++ with pytest.raises(ValueError):
++ dcmstack.reorder_voxels(self.vox_array, self.affine, 'lra')
++ with pytest.raises(ValueError):
++ dcmstack.reorder_voxels(self.vox_array, self.affine, 'rpil')
++ with pytest.raises(ValueError):
++ dcmstack.reorder_voxels(self.vox_array, self.affine, 'lrz')
+
+ def test_invalid_vox_array(self):
+- assert_raises(ValueError,
+- dcmstack.reorder_voxels,
+- np.eye(2),
+- self.affine,
+- 'rpi',
+- )
++ with pytest.raises(ValueError):
++ dcmstack.reorder_voxels(np.eye(2), self.affine, 'rpi')
+
+ def test_invalid_affine(self):
+- assert_raises(ValueError,
+- dcmstack.reorder_voxels,
+- self.vox_array,
+- np.eye(3),
+- 'rpi',
+- )
++ with pytest.raises(ValueError):
++ dcmstack.reorder_voxels(self.vox_array, np.eye(3), 'rpi')
+
+ def test_no_op(self):
+ vox_order = ''.join(aff2axcodes(self.affine))
+@@ -126,11 +106,11 @@
+ ornt_trans) = dcmstack.reorder_voxels(self.vox_array,
+ self.affine,
+ vox_order)
+- ok_((vox_array == self.vox_array).all())
+- ok_((affine == self.affine).all())
+- ok_((aff_trans == np.eye(4)).all())
+- ok_(np.allclose(ornt_trans, [[0, 1], [1, 1], [2, 1]]))
+- eq_(np.may_share_memory(affine, self.affine), False)
++ assert((vox_array == self.vox_array).all())
++ assert((affine == self.affine).all())
++ assert((aff_trans == np.eye(4)).all())
++ assert(np.allclose(ornt_trans, [[0, 1], [1, 1], [2, 1]]))
++ assert np.may_share_memory(affine, self.affine) == False
+
+ def test_reorder(self):
+ (vox_array,
+@@ -139,7 +119,7 @@
+ ornt_trans) = dcmstack.reorder_voxels(self.vox_array,
+ self.affine,
+ 'PRS')
+- ok_(np.all(vox_array == np.array([[[[4, 5],
++ assert(np.all(vox_array == np.array([[[[4, 5],
+ [6, 7]],
+ [[12, 13],
+ [14,15]]
+@@ -153,7 +133,7 @@
+ )
+ )
+ )
+- ok_(np.allclose(affine,
++ assert(np.allclose(affine,
+ np.array([[0,1,0,0],
+ [-1,0,0,1],
+ [0,0,1,0],
+@@ -170,7 +150,7 @@
+ ornt_trans) = dcmstack.reorder_voxels(self.vox_array,
+ self.affine,
+ 'PLS')
+- ok_(np.allclose(affine,
++ assert(np.allclose(affine,
+ np.array([[0,-1,0,1],
+ [-1,0,0,3],
+ [0,0,1,0],
+@@ -179,50 +159,46 @@
+ )
+
+ def test_dcm_time_to_sec():
+- eq_(dcmstack.dcm_time_to_sec('100235.123456'), 36155.123456)
+- eq_(dcmstack.dcm_time_to_sec('100235'), 36155)
+- eq_(dcmstack.dcm_time_to_sec('1002'), 36120)
+- eq_(dcmstack.dcm_time_to_sec('10'), 36000)
++ assert dcmstack.dcm_time_to_sec('100235.123456') == 36155.123456
++ assert dcmstack.dcm_time_to_sec('100235') == 36155
++ assert dcmstack.dcm_time_to_sec('1002') == 36120
++ assert dcmstack.dcm_time_to_sec('10') == 36000
+
+ #Allow older NEMA style values
+- eq_(dcmstack.dcm_time_to_sec('10:02:35.123456'), 36155.123456)
+- eq_(dcmstack.dcm_time_to_sec('10:02:35'), 36155)
+- eq_(dcmstack.dcm_time_to_sec('10:02'), 36120)
+- eq_(dcmstack.dcm_time_to_sec('10'), 36000)
++ assert dcmstack.dcm_time_to_sec('10:02:35.123456') == 36155.123456
++ assert dcmstack.dcm_time_to_sec('10:02:35') == 36155
++ assert dcmstack.dcm_time_to_sec('10:02') == 36120
++ assert dcmstack.dcm_time_to_sec('10') == 36000
+
+ class TestDicomOrdering(object):
+- def setUp(self):
++ def setup_method(self, method):
+ self.ds = {'EchoTime' : 2}
+
+ def test_missing_key(self):
+ ordering = dcmstack.DicomOrdering('blah')
+- eq_(ordering.get_ordinate(self.ds), None)
++ assert ordering.get_ordinate(self.ds) == None
+
+ def test_non_abs(self):
+ ordering = dcmstack.DicomOrdering('EchoTime')
+- eq_(ordering.get_ordinate(self.ds), self.ds['EchoTime'])
++ assert ordering.get_ordinate(self.ds) == self.ds['EchoTime']
+
+ def test_abs(self):
+ abs_order = [1,2,3]
+ ordering = dcmstack.DicomOrdering('EchoTime', abs_ordering=abs_order)
+- eq_(ordering.get_ordinate(self.ds),
+- abs_order.index(self.ds['EchoTime']))
++ assert ordering.get_ordinate(self.ds) == abs_order.index(self.ds['EchoTime'])
+
+ def test_abs_as_str(self):
+ abs_order = ['1','2','3']
+ ordering = dcmstack.DicomOrdering('EchoTime',
+ abs_ordering=abs_order,
+ abs_as_str=True)
+- eq_(ordering.get_ordinate(self.ds),
+- abs_order.index(str(self.ds['EchoTime'])))
++ assert ordering.get_ordinate(self.ds) == abs_order.index(str(self.ds['EchoTime']))
+
+ def test_abs_missing(self):
+ abs_order = [1,3]
+ ordering = dcmstack.DicomOrdering('EchoTime', abs_ordering=abs_order)
+- assert_raises(ValueError,
+- ordering.get_ordinate,
+- self.ds
+- )
++ with pytest.raises(ValueError):
++ ordering.get_ordinate(self.ds)
+
+ def test_image_collision():
+ dcm_path = path.join(test_dir,
+@@ -233,12 +209,11 @@
+ dcm = pydicom.read_file(dcm_path)
+ stack = dcmstack.DicomStack('EchoTime')
+ stack.add_dcm(dcm)
+- assert_raises(dcmstack.ImageCollisionError,
+- stack.add_dcm,
+- dcm)
++ with pytest.raises(dcmstack.ImageCollisionError):
++ stack.add_dcm(dcm)
+
+ class TestIncongruentImage(object):
+- def setUp(self):
++ def setup_method(self, method):
+ dcm_path = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -251,9 +226,8 @@
+ self.dcm = pydicom.read_file(dcm_path)
+
+ def _chk_raises(self):
+- assert_raises(dcmstack.IncongruentImageError,
+- self.stack.add_dcm,
+- self.dcm)
++ with pytest.raises(dcmstack.IncongruentImageError):
++ self.stack.add_dcm(self.dcm)
+
+ def test_rows(self):
+ self.dcm.Rows += 1
+@@ -289,7 +263,7 @@
+
+
+ class TestInvalidStack(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -304,14 +278,14 @@
+ ]
+
+ def _chk(self):
+- assert_raises(dcmstack.InvalidStackError,
+- self.stack.get_shape)
+- assert_raises(dcmstack.InvalidStackError,
+- self.stack.get_affine)
+- assert_raises(dcmstack.InvalidStackError,
+- self.stack.get_data)
+- assert_raises(dcmstack.InvalidStackError,
+- self.stack.to_nifti)
++ with pytest.raises(dcmstack.InvalidStackError):
++ self.stack.get_shape()
++ with pytest.raises(dcmstack.InvalidStackError):
++ self.stack.get_affine()
++ with pytest.raises(dcmstack.InvalidStackError):
++ self.stack.get_data()
++ with pytest.raises(dcmstack.InvalidStackError):
++ self.stack.to_nifti()
+
+ def test_empty(self):
+ self.stack = dcmstack.DicomStack()
+@@ -350,7 +324,7 @@
+ self._chk()
+
+ class TestGetShape(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -367,14 +341,14 @@
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(self.inputs[0])
+ shape = stack.shape
+- eq_(shape, (192, 192, 1))
++ assert shape == (192, 192, 1)
+
+ def test_three_dim(self):
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(self.inputs[0])
+ stack.add_dcm(self.inputs[1])
+ shape = stack.shape
+- eq_(shape, (192, 192, 2))
++ assert shape == (192, 192, 2)
+
+ def test_four_dim(self):
+ stack = dcmstack.DicomStack(time_order='EchoTime')
+@@ -383,7 +357,7 @@
+ stack.add_dcm(self.inputs[2])
+ stack.add_dcm(self.inputs[3])
+ shape = stack.shape
+- eq_(shape, (192, 192, 2, 2))
++ assert shape == (192, 192, 2, 2)
+
+ def test_five_dim(self):
+ stack = dcmstack.DicomStack(vector_order='EchoTime')
+@@ -392,7 +366,7 @@
+ stack.add_dcm(self.inputs[2])
+ stack.add_dcm(self.inputs[3])
+ shape = stack.shape
+- eq_(shape, (192, 192, 2, 1, 2))
++ assert shape == (192, 192, 2, 1, 2)
+
+ def test_allow_dummy(self):
+ del self.inputs[0].Rows
+@@ -401,10 +375,10 @@
+ stack.add_dcm(self.inputs[0])
+ stack.add_dcm(self.inputs[1])
+ shape = stack.shape
+- eq_(shape, (192, 192, 2))
++ assert shape == (192, 192, 2)
+
+ class TestGuessDim(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -436,7 +410,7 @@
+ for idx, in_dcm in enumerate(self.inputs):
+ setattr(in_dcm, key, self._get_vr_ord(key, idx))
+ stack.add_dcm(in_dcm)
+- eq_(stack.shape, (192, 192, 2, 2))
++ assert stack.shape == (192, 192, 2, 2)
+ for in_dcm in self.inputs:
+ delattr(in_dcm, key)
+
+@@ -451,10 +425,10 @@
+ dcmstack.DicomStack.sort_guesses[-1],
+ self._get_vr_ord(key, idx) )
+ stack.add_dcm(in_dcm)
+- eq_(stack.shape, (192, 192, 2, 2))
++ assert stack.shape == (192, 192, 2, 2)
+
+ class TestGetData(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -471,18 +445,18 @@
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(self.inputs[0])
+ data = stack.get_data()
+- eq_(data.shape, stack.shape)
+- eq_(sha256(data).hexdigest(),
+- '15cfa107ca73810a1c97f1c1872a7a4a05808ba6147e039cef3f63fa08735f5d')
++ assert data.shape == stack.shape
++ assert sha256(data).hexdigest() == \
++ '15cfa107ca73810a1c97f1c1872a7a4a05808ba6147e039cef3f63fa08735f5d'
+
+ def test_three_dim(self):
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(self.inputs[0])
+ stack.add_dcm(self.inputs[1])
+ data = stack.get_data()
+- eq_(data.shape, stack.shape)
+- eq_(sha256(data).hexdigest(),
+- 'ab5225fdbedceeea3442b2c9387e1abcbf398c71f525e0017251849c3cfbf49c')
++ assert data.shape == stack.shape
++ assert sha256(data).hexdigest() == \
++ 'ab5225fdbedceeea3442b2c9387e1abcbf398c71f525e0017251849c3cfbf49c'
+
+ def test_four_dim(self):
+ stack = dcmstack.DicomStack(time_order='EchoTime')
+@@ -491,9 +465,9 @@
+ stack.add_dcm(self.inputs[2])
+ stack.add_dcm(self.inputs[3])
+ data = stack.get_data()
+- eq_(data.shape, stack.shape)
+- eq_(sha256(data).hexdigest(),
+- 'bb3639a6ece13dc9a11d65f1b09ab3ccaed63b22dcf0f96fb5d3dd8805cc7b8a')
++ assert data.shape == stack.shape
++ assert sha256(data).hexdigest() == \
++ 'bb3639a6ece13dc9a11d65f1b09ab3ccaed63b22dcf0f96fb5d3dd8805cc7b8a'
+
+ def test_five_dim(self):
+ stack = dcmstack.DicomStack(vector_order='EchoTime')
+@@ -502,9 +476,9 @@
+ stack.add_dcm(self.inputs[2])
+ stack.add_dcm(self.inputs[3])
+ data = stack.get_data()
+- eq_(data.shape, stack.shape)
+- eq_(sha256(data).hexdigest(),
+- 'bb3639a6ece13dc9a11d65f1b09ab3ccaed63b22dcf0f96fb5d3dd8805cc7b8a')
++ assert data.shape == stack.shape
++ assert sha256(data).hexdigest() == \
++ 'bb3639a6ece13dc9a11d65f1b09ab3ccaed63b22dcf0f96fb5d3dd8805cc7b8a'
+
+ def test_allow_dummy(self):
+ del self.inputs[0].Rows
+@@ -513,13 +487,13 @@
+ stack.add_dcm(self.inputs[0])
+ stack.add_dcm(self.inputs[1])
+ data = stack.get_data()
+- eq_(data.shape, stack.shape)
+- ok_(np.all(data[:, :, -1] == np.iinfo(np.int16).max))
+- eq_(sha256(data).hexdigest(),
+- '7d85fbcb60a5021a45df3975613dcb7ac731830e0a268590cc798dc39897c04b')
++ assert data.shape == stack.shape
++ assert(np.all(data[:, :, -1] == np.iinfo(np.int16).max))
++ assert sha256(data).hexdigest() == \
++ '7d85fbcb60a5021a45df3975613dcb7ac731830e0a268590cc798dc39897c04b'
+
+ class TestGetAffine(object):
+- def setUp(self):
++ def setup_method(self, method):
+ self.data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -535,7 +509,7 @@
+ stack.add_dcm(self.inputs[0])
+ affine = stack.affine
+ ref = np.load(path.join(self.data_dir, 'single_slice_aff.npy'))
+- ok_(np.allclose(affine, ref))
++ assert(np.allclose(affine, ref))
+
+ def test_three_dim(self):
+ stack = dcmstack.DicomStack()
+@@ -543,7 +517,7 @@
+ stack.add_dcm(self.inputs[1])
+ affine = stack.affine
+ ref = np.load(path.join(self.data_dir, 'single_vol_aff.npy'))
+- ok_(np.allclose(affine, ref))
++ assert(np.allclose(affine, ref))
+
+ class TestToNifti(object):
+
+@@ -586,7 +560,7 @@
+ 'srow_z',
+ ]
+
+- def setUp(self):
++ def setup_method(self, method):
+ self.data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -648,7 +622,7 @@
+
+ for key in self.close_keys:
+ print("Testing key %s" % key)
+- ok_(np.allclose(hdr[key], ref_hdr[key]))
++ assert(np.allclose(hdr[key], ref_hdr[key]))
+
+ def test_single_slice(self):
+ for tst in ('single_slice', 'single_slice_meta'):
+@@ -683,11 +657,11 @@
+ stack.add_dcm(self.inputs[1])
+ nii = stack.to_nifti()
+ data = nii.get_data()
+- ok_(np.all(data[:, :, 0] == np.iinfo(np.int16).max))
++ assert(np.all(data[:, :, 0] == np.iinfo(np.int16).max))
+
+
+ class TestParseAndGroup(object):
+- def setUp(self):
++ def setup_method(self, method):
+ self.data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -702,18 +676,18 @@
+
+ def test_default(self):
+ res = dcmstack.parse_and_group(self.in_paths)
+- eq_(len(res), 1)
++ assert len(res) == 1
+ ds = pydicom.read_file(self.in_paths[0])
+ group_key = list(res.keys())[0]
+ for attr_idx, attr in enumerate(dcmstack.default_group_keys):
+ if attr in dcmstack.default_close_keys:
+- ok_(np.allclose(group_key[attr_idx], getattr(ds, attr)))
++ assert(np.allclose(group_key[attr_idx], getattr(ds, attr)))
+ else:
+- eq_(group_key[attr_idx], getattr(ds, attr))
++ assert group_key[attr_idx] == getattr(ds, attr)
+
+
+ class TestParseAndStack(object):
+- def setUp(self):
++ def setup_method(self, method):
+ self.data_dir = path.join(test_dir,
+ 'data',
+ 'dcmstack',
+@@ -728,18 +702,18 @@
+
+ def test_default(self):
+ res = dcmstack.parse_and_stack(self.in_paths)
+- eq_(len(res), 1)
++ assert len(res) == 1
+ ds = pydicom.read_file(self.in_paths[0])
+ group_key = list(res.keys())[0]
+ for attr_idx, attr in enumerate(dcmstack.default_group_keys):
+ if attr in dcmstack.default_close_keys:
+- ok_(np.allclose(group_key[attr_idx], getattr(ds, attr)))
++ assert(np.allclose(group_key[attr_idx], getattr(ds, attr)))
+ else:
+- eq_(group_key[attr_idx], getattr(ds, attr))
++ assert group_key[attr_idx] == getattr(ds, attr)
+ stack = list(res.values())[0]
+- ok_(isinstance(stack, dcmstack.DicomStack))
++ assert(isinstance(stack, dcmstack.DicomStack))
+ stack_data = stack.get_data()
+- eq_(stack_data.ndim, 4)
++ assert stack_data.ndim == 4
+
+
+ def test_fsl_hack():
+@@ -747,8 +721,8 @@
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(ds)
+ data = stack.get_data()
+- eq_(np.max(data), (2**14 - 1))
+- eq_(data.dtype, np.int16)
++ assert np.max(data) == (2**14 - 1)
++ assert data.dtype == np.int16
+
+
+ def test_pix_overflow():
+@@ -756,5 +730,5 @@
+ stack = dcmstack.DicomStack()
+ stack.add_dcm(ds)
+ data = stack.get_data()
+- eq_(np.max(data), (2**16 - 1))
+- eq_(data.dtype, np.uint16)
++ assert np.max(data) == (2**16 - 1)
++ assert data.dtype == np.uint16
+--- a/test/test_extract.py
++++ b/test/test_extract.py
+@@ -4,7 +4,7 @@
+ import sys, warnings
+ from os import path
+
+-from nose.tools import ok_, eq_, assert_raises
++import pytest
+ from nibabel.nicom import csareader
+ try:
+ import pydicom
+@@ -18,65 +18,61 @@
+ from dcmstack import extract
+
+ class TestCsa(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_fn = path.join(test_dir, 'data', 'extract', 'csa_test.dcm')
+ self.data = pydicom.read_file(data_fn)
+
+- def tearDown(self):
++ def teardown_method(self, method):
+ del self.data
+
+ def test_simplify(self):
+- eq_(extract.simplify_csa_dict(None), None)
++ assert extract.simplify_csa_dict(None) == None
+ csa_dict = csareader.read(self.data[pydicom.tag.Tag(0x29, 0x1010)].value)
+ simp_dict = extract.simplify_csa_dict(csa_dict)
+ for tag in csa_dict['tags']:
+ items = csa_dict['tags'][tag]['items']
+ if len(items) == 0:
+- ok_(not tag in simp_dict)
++ assert(not tag in simp_dict)
+ elif len(items) == 1:
+- eq_(simp_dict[tag], items[0])
++ assert simp_dict[tag] == items[0]
+ else:
+- eq_(simp_dict[tag], items)
++ assert simp_dict[tag] == items
+
+ def test_csa_image_trans(self):
+ csa_dict = extract.csa_series_trans_func(self.data[(0x29, 0x1010)])
+- eq_(csa_dict["EchoLinePosition"], 64)
++ assert csa_dict["EchoLinePosition"] == 64
+
+ def test_parse_phx_line(self):
+- ok_(extract._parse_phoenix_line("") is None)
+- ok_(extract._parse_phoenix_line("#test = 2") is None)
++ assert(extract._parse_phoenix_line("") is None)
++ assert(extract._parse_phoenix_line("#test = 2") is None)
+
+- eq_(extract._parse_phoenix_line('test = "" 2 ""'), ('test', ' 2 '))
+- eq_(extract._parse_phoenix_line('test = "" #2 ""'), ('test', ' #2 '))
+- eq_(extract._parse_phoenix_line('test = "" 2 ""#='),
+- ('test', ' 2 '))
+- eq_(extract._parse_phoenix_line("test = 2#"), ('test', 2))
+- eq_(extract._parse_phoenix_line("test = 0x2"), ('test', 2))
+- eq_(extract._parse_phoenix_line("test = 2."), ('test', 2.0))
+-
+- assert_raises(extract.PhoenixParseError,
+- extract._parse_phoenix_line,
+- 'test = blah')
+- assert_raises(extract.PhoenixParseError,
+- extract._parse_phoenix_line,
+- '==')
+- assert_raises(extract.PhoenixParseError,
+- extract._parse_phoenix_line,
+- 'test')
+- assert_raises(extract.PhoenixParseError,
+- extract._parse_phoenix_line,
+- 'test = "" 2 ""3')
++ assert extract._parse_phoenix_line('test = "" 2 ""') == ('test', ' 2 ')
++ assert extract._parse_phoenix_line('test = "" #2 ""'), ('test', ' #2 ')
++ assert extract._parse_phoenix_line('test = "" 2 ""#=') == ('test', ' 2 ')
++ assert extract._parse_phoenix_line("test = 2#") == ('test', 2)
++ assert extract._parse_phoenix_line("test = 0x2") == ('test', 2)
++ assert extract._parse_phoenix_line("test = 2.") == ('test', 2.0)
++
++
++ with pytest.raises(extract.PhoenixParseError):
++ extract._parse_phoenix_line('test = blah')
++ with pytest.raises(extract.PhoenixParseError):
++ extract._parse_phoenix_line('==')
++ with pytest.raises(extract.PhoenixParseError):
++ extract._parse_phoenix_line('test')
++ with pytest.raises(extract.PhoenixParseError):
++ extract._parse_phoenix_line('test = "" 2 ""3')
+
+ def test_csa_series_trans(self):
+ csa_dict = extract.csa_series_trans_func(self.data[(0x29, 0x1020)])
+- eq_(csa_dict['MrPhoenixProtocol.sEFISPEC.bEFIDataValid'], 1)
++ assert csa_dict['MrPhoenixProtocol.sEFISPEC.bEFIDataValid'] == 1
+
+ class TestMetaExtractor(object):
+- def setUp(self):
++ def setup_method(self, method):
+ data_fn = path.join(test_dir, 'data', 'extract', 'csa_test.dcm')
+ self.data = pydicom.read_file(data_fn)
+
+- def tearDown(self):
++ def teardown_method(self,method):
+ del self.data
+
+ def test_get_elem_key(self):
+@@ -84,9 +80,9 @@
+ extractor = extract.MetaExtractor(ignore_rules=ignore_rules)
+ for elem in self.data:
+ key = extractor._get_elem_key(elem)
+- ok_(key.strip() != '')
+- ok_(key[0].isalpha())
+- ok_(key[-1].isalnum())
++ assert(key.strip() != '')
++ assert(key[0].isalpha())
++ assert(key[-1].isalnum())
+
+ def test_get_elem_value(self):
+ ignore_rules = (extract.ignore_pixel_data,)
+@@ -94,17 +90,18 @@
+ for elem in self.data:
+ value = extractor._get_elem_value(elem)
+ if elem.VM > 1:
+- ok_(isinstance(value, list))
++ assert(isinstance(value, list))
+ if elem.VR in list(extract.unpack_vr_map) + ['DS', 'IS']:
+ if elem.VM == 1:
+- ok_(not isinstance(value, str))
++ assert(not isinstance(value, str))
+ else:
+- ok_(not any(isinstance(val, str) for val in value))
++ assert(not any(isinstance(val, str) for val in value))
+
+ def test_dup_trans(self):
+ translators = [extract.csa_image_trans, extract.csa_image_trans]
+ extractor = extract.MetaExtractor(translators=translators)
+- assert_raises(ValueError, extractor, self.data)
++ with pytest.raises(ValueError):
++ extractor(self.data)
+
+ def test_reloc_private(self):
+ extractor = extract.MetaExtractor()
+@@ -112,11 +109,11 @@
+ self.data[(0x29, 0x1010)].tag = pydicom.tag.Tag((0x29, 0x2010))
+ self.data[(0x29, 0x1020)].tag = pydicom.tag.Tag((0x29, 0x2020))
+ meta_dict = extractor(self.data)
+- eq_(meta_dict["CsaImage.EchoLinePosition"], 64)
+- ok_(meta_dict['CsaSeries.MrPhoenixProtocol.sEFISPEC.bEFIDataValid'], 1)
++ assert meta_dict["CsaImage.EchoLinePosition"] == 64
++ assert(meta_dict['CsaSeries.MrPhoenixProtocol.sEFISPEC.bEFIDataValid'], 1)
+
+ def test_non_reloc_private(self):
+ extractor = extract.MetaExtractor()
+ meta_dict = extractor(self.data)
+- eq_(meta_dict["CsaImage.EchoLinePosition"], 64)
+- ok_(meta_dict['CsaSeries.MrPhoenixProtocol.sEFISPEC.bEFIDataValid'], 1)
+\ No newline at end of file
++ assert meta_dict["CsaImage.EchoLinePosition"] == 64
++ assert(meta_dict['CsaSeries.MrPhoenixProtocol.sEFISPEC.bEFIDataValid'], 1)
+--- a/setup.py
++++ b/setup.py
+@@ -26,5 +26,5 @@
+ 'nitool = dcmstack.nitool_cli:main',
+ ],
+ },
+- test_suite = 'nose.collector'
++ test_suite = 'pytest'
+ )
+--- a/src/dcmstack/info.py
++++ b/src/dcmstack/info.py
+@@ -34,7 +34,7 @@
+
+ # Extra requirements for building documentation and testing
+ extras_requires = {'doc': ["sphinx", "numpydoc"],
+- 'test': ["nose"],
++ 'test': ["pytest"],
+ }
+
+
=====================================
debian/patches/series
=====================================
@@ -0,0 +1 @@
+port-to-pytest.patch
=====================================
debian/rules
=====================================
@@ -2,9 +2,6 @@
export DH_VERBOSE = 1
export PYBUILD_NAME = dcmstack
-export PYBUILD_AFTER_INSTALL=mkdir -p build/man ; \
- PYTHONPATH={build_dir} help2man --no-discard-stderr --no-info -o build/man/dcmstack.1 --name "DICOM to NIfTI converter" debian/python3-dcmstack/usr/bin/dcmstack ; \
- PYTHONPATH={build_dir} help2man --no-discard-stderr --no-info -o build/man/nitool.1 --name "meta data manipulation tool for dcmstack-enhanced NIfTI images" debian/python3-dcmstack/usr/bin/nitool
# one ring to rule them all ...
%:
=====================================
debian/tests/control
=====================================
@@ -1,2 +1,3 @@
-Test-Command: python3 -m nose .
-Depends: @, @builddeps@
+Tests: run-unit-test
+Depends: @, python3-all, python3-pytest
+Restrictions: allow-stderr
=====================================
debian/tests/run-unit-test
=====================================
@@ -0,0 +1,21 @@
+#!/bin/bash
+set -e
+
+pkg=dcmstack
+CUR_DIR=`pwd`
+
+export LC_ALL=C.UTF-8
+if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
+ AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
+ trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
+fi
+
+cp -a ${CUR_DIR}/test $AUTOPKGTEST_TMP
+cd $AUTOPKGTEST_TMP
+
+for py in $(py3versions -s 2> /dev/null)
+do echo "Testing with $py in $(pwd):"
+ $py -m pytest -v
+done
+
+echo "PASS"
View it on GitLab: https://salsa.debian.org/med-team/dcmstack/-/compare/66ed553937049d22dc490cbb7d91454f790166e1...91efec3ad95b9a8c118ac280911bd3b3b2b80e98
--
View it on GitLab: https://salsa.debian.org/med-team/dcmstack/-/compare/66ed553937049d22dc490cbb7d91454f790166e1...91efec3ad95b9a8c118ac280911bd3b3b2b80e98
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20211112/714e409f/attachment-0001.htm>
More information about the debian-med-commit
mailing list