Skip to content

Commit

Permalink
added cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBiggs committed May 15, 2020
1 parent 060065c commit 833900a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Binary file added box-with-overlapping-patient-and-target.dcm
Binary file not shown.
12 changes: 10 additions & 2 deletions pymedphys/_dicom/structure/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ def create_new_contour_sequence(
def merge_contours( # pylint:disable = inconsistent-return-statements
roi_contour_sequence, inplace=False
):
contour_sequence = roi_contour_sequence.ContourSequence
try:
contour_sequence = roi_contour_sequence.ContourSequence
except AttributeError:
print(roi_contour_sequence)
raise

contours_by_z, image_sequence_by_z = extract_contours_and_image_sequences(
contour_sequence
)
Expand All @@ -197,5 +202,8 @@ def merge_contours( # pylint:disable = inconsistent-return-statements

def merge_contours_cli(args):
dicom_dataset = pydicom.read_file(args.input_file, force=True)
merge_contours(dicom_dataset.ROIContourSequence, inplace=True)

for roi_contour_sequence in dicom_dataset.ROIContourSequence:
merge_contours(roi_contour_sequence, inplace=True)

pydicom.write_file(args.output_file, dicom_dataset)
17 changes: 17 additions & 0 deletions tests/dicom/test_structure_dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pathlib
import subprocess
import tempfile

import pydicom

import pymedphys
Expand All @@ -36,3 +40,16 @@ def test_structure_dedupe():
pymedphys.dicom.merge_contours(item, inplace=True)

assert str(input_dcm) == str(baseline_dcm)

with tempfile.TemporaryDirectory() as temp_dir:
output_filename = str(pathlib.Path(temp_dir).joinpath("temp.dcm"))

command = "pymedphys dicom merge-contours".split() + [
str(input_path),
output_filename,
]
subprocess.check_call(command)

cli_dcm = pydicom.read_file(output_filename, force=True)

assert str(cli_dcm) == str(baseline_dcm)

0 comments on commit 833900a

Please sign in to comment.