<s> import os <EOL> import numpy as np <EOL> from numpy . testing import assert_raises , assert_equal , assert_allclose <EOL> from skimage . io import use_plugin <EOL> from skimage import data_dir <EOL> from skimage . io . collection import MultiImage , ImageCollection <EOL> import six <EOL> class TestMultiImage ( ) : <EOL> def setUp ( self ) : <EOL> use_plugin ( '<STR_LIT>' ) <EOL> paths = [ os . path . join ( data_dir , '<STR_LIT>' ) , <EOL> os . path . join ( data_dir , '<STR_LIT>' ) ] <EOL> self . imgs = [ MultiImage ( paths [ <NUM_LIT:0> ] ) , <EOL> MultiImage ( paths [ <NUM_LIT:0> ] , conserve_memory = False ) , <EOL> MultiImage ( paths [ <NUM_LIT:1> ] ) , <EOL> MultiImage ( paths [ <NUM_LIT:1> ] , conserve_memory = False ) , <EOL> ImageCollection ( paths [ <NUM_LIT:0> ] ) , <EOL> ImageCollection ( paths [ <NUM_LIT:1> ] , conserve_memory = False ) , <EOL> ImageCollection ( '<STR_LIT>' % ( paths [ <NUM_LIT:0> ] , paths [ <NUM_LIT:1> ] ) ) ] <EOL> def test_shapes ( self ) : <EOL> img = self . imgs [ - <NUM_LIT:1> ] <EOL> imgs = img [ : ] <EOL> assert imgs [ <NUM_LIT:0> ] . shape == imgs [ <NUM_LIT:1> ] . shape <EOL> assert imgs [ <NUM_LIT:0> ] . shape == ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:3> ) <EOL> def test_len ( self ) : <EOL> assert len ( self . imgs [ <NUM_LIT:0> ] ) == len ( self . imgs [ <NUM_LIT:1> ] ) == <NUM_LIT:2> <EOL> assert len ( self . imgs [ <NUM_LIT:2> ] ) == len ( self . imgs [ <NUM_LIT:3> ] ) == <NUM_LIT> <EOL> assert len ( self . imgs [ <NUM_LIT:4> ] ) == <NUM_LIT:2> <EOL> assert len ( self . imgs [ <NUM_LIT:5> ] ) == <NUM_LIT> <EOL> assert len ( self . imgs [ <NUM_LIT:6> ] ) == <NUM_LIT> , len ( self . imgs [ <NUM_LIT:6> ] ) <EOL> def test_slicing ( self ) : <EOL> img = self . imgs [ - <NUM_LIT:1> ] <EOL> assert type ( img [ : ] ) is ImageCollection <EOL> assert len ( img [ : ] ) == <NUM_LIT> , len ( img [ : ] ) <EOL> assert len ( img [ : <NUM_LIT:1> ] ) == <NUM_LIT:1> <EOL> assert len ( img [ <NUM_LIT:1> : ] ) == <NUM_LIT> <EOL> assert_allclose ( img [ <NUM_LIT:0> ] , img [ : <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_allclose ( img [ <NUM_LIT:1> ] , img [ <NUM_LIT:1> : ] [ <NUM_LIT:0> ] ) <EOL> assert_allclose ( img [ - <NUM_LIT:1> ] , img [ : : - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert_allclose ( img [ <NUM_LIT:0> ] , img [ : : - <NUM_LIT:1> ] [ - <NUM_LIT:1> ] ) <EOL> def test_getitem ( self ) : <EOL> for img in self . imgs : <EOL> num = len ( img ) <EOL> for i in range ( - num , num ) : <EOL> assert type ( img [ i ] ) is np . ndarray <EOL> assert_allclose ( img [ <NUM_LIT:0> ] , img [ - num ] ) <EOL> assert_raises ( AssertionError , <EOL> assert_allclose , <EOL> img [ <NUM_LIT:0> ] , img [ <NUM_LIT:1> ] ) <EOL> def return_img ( n ) : <EOL> return img [ n ] <EOL> assert_raises ( IndexError , return_img , num ) <EOL> assert_raises ( IndexError , return_img , - num - <NUM_LIT:1> ) <EOL> def test_files_property ( self ) : <EOL> for img in self . imgs : <EOL> if isinstance ( img , ImageCollection ) : <EOL> continue <EOL> assert isinstance ( img . filename , six . string_types ) <EOL> def set_filename ( f ) : <EOL> img . filename = f <EOL> assert_raises ( AttributeError , set_filename , '<STR_LIT>' ) <EOL> def test_conserve_memory_property ( self ) : <EOL> for img in self . imgs : <EOL> assert isinstance ( img . conserve_memory , bool ) <EOL> def set_mem ( val ) : <EOL> img . conserve_memory = val <EOL> assert_raises ( AttributeError , set_mem , True ) <EOL> def test_concatenate ( self ) : <EOL> for img in self . imgs : <EOL> if img [ <NUM_LIT:0> ] . shape != img [ - <NUM_LIT:1> ] . shape : <EOL> assert_raises ( ValueError , img . concatenate ) <EOL> continue <EOL> array = img . concatenate ( ) <EOL> assert_equal ( array . shape , ( len ( img ) , ) + img [ <NUM_LIT:0> ] . shape ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from numpy . testing import run_module_suite <EOL> run_module_suite ( ) </s>
