<s> """<STR_LIT>""" <EOL> import os <EOL> from os . path import join as pjoin , dirname <EOL> from . . externals . six import BytesIO <EOL> from . . testing import suppress_warnings <EOL> import numpy as np <EOL> with suppress_warnings ( ) : <EOL> from . . import dft <EOL> from . . import nifti1 <EOL> from nose import SkipTest <EOL> from nose . tools import ( assert_true , assert_false , assert_equal , assert_raises ) <EOL> from . . optpkg import optional_package <EOL> from nibabel . pydicom_compat import have_dicom <EOL> PImage , have_pil , _ = optional_package ( '<STR_LIT>' ) <EOL> pil_test = np . testing . dec . skipif ( not have_pil , '<STR_LIT>' ) <EOL> data_dir = pjoin ( dirname ( __file__ ) , '<STR_LIT:data>' ) <EOL> def setup_module ( ) : <EOL> if os . name == '<STR_LIT>' : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> if not have_dicom : <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> def test_init ( ) : <EOL> dft . clear_cache ( ) <EOL> dft . update_cache ( data_dir ) <EOL> def test_study ( ) : <EOL> studies = dft . get_studies ( data_dir ) <EOL> assert_equal ( len ( studies ) , <NUM_LIT:1> ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . uid , <EOL> '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . date , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . time , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . comments , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . patient_name , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . patient_id , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . patient_birth_date , '<STR_LIT>' ) <EOL> assert_equal ( studies [ <NUM_LIT:0> ] . patient_sex , '<STR_LIT:F>' ) <EOL> def test_series ( ) : <EOL> studies = dft . get_studies ( data_dir ) <EOL> assert_equal ( len ( studies [ <NUM_LIT:0> ] . series ) , <NUM_LIT:1> ) <EOL> ser = studies [ <NUM_LIT:0> ] . series [ <NUM_LIT:0> ] <EOL> assert_equal ( ser . uid , <EOL> '<STR_LIT>' ) <EOL> assert_equal ( ser . number , '<STR_LIT>' ) <EOL> assert_equal ( ser . description , '<STR_LIT>' ) <EOL> assert_equal ( ser . rows , <NUM_LIT> ) <EOL> assert_equal ( ser . columns , <NUM_LIT> ) <EOL> assert_equal ( ser . bits_allocated , <NUM_LIT:16> ) <EOL> assert_equal ( ser . bits_stored , <NUM_LIT:12> ) <EOL> def test_storage_instances ( ) : <EOL> studies = dft . get_studies ( data_dir ) <EOL> sis = studies [ <NUM_LIT:0> ] . series [ <NUM_LIT:0> ] . storage_instances <EOL> assert_equal ( len ( sis ) , <NUM_LIT:2> ) <EOL> assert_equal ( sis [ <NUM_LIT:0> ] . instance_number , <NUM_LIT:1> ) <EOL> assert_equal ( sis [ <NUM_LIT:1> ] . instance_number , <NUM_LIT:2> ) <EOL> assert_equal ( sis [ <NUM_LIT:0> ] . uid , <EOL> '<STR_LIT>' ) <EOL> assert_equal ( sis [ <NUM_LIT:1> ] . uid , <EOL> '<STR_LIT>' ) <EOL> def test_storage_instance ( ) : <EOL> pass <EOL> @ pil_test <EOL> def test_png ( ) : <EOL> studies = dft . get_studies ( data_dir ) <EOL> data = studies [ <NUM_LIT:0> ] . series [ <NUM_LIT:0> ] . as_png ( ) <EOL> im = PImage . open ( BytesIO ( data ) ) <EOL> assert_equal ( im . size , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> def test_nifti ( ) : <EOL> studies = dft . get_studies ( data_dir ) <EOL> data = studies [ <NUM_LIT:0> ] . series [ <NUM_LIT:0> ] . as_nifti ( ) <EOL> assert_equal ( len ( data ) , <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:2> ) <EOL> h = nifti1 . Nifti1Header ( data [ : <NUM_LIT> ] ) <EOL> assert_equal ( h . get_data_shape ( ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2> ) ) </s>
