<s> import pytest <EOL> import rasterio <EOL> from rasterio . mask import mask as mask_tool <EOL> def test_nodata ( basic_image_file , basic_geometry ) : <EOL> nodata_val = <NUM_LIT:0> <EOL> geometries = [ basic_geometry ] <EOL> with rasterio . open ( basic_image_file , "<STR_LIT:r>" ) as src : <EOL> masked , transform = mask_tool ( src , geometries , crop = False , <EOL> nodata = nodata_val , invert = True ) <EOL> assert ( masked . data . all ( ) == nodata_val ) <EOL> def test_no_nodata ( basic_image_file , basic_geometry ) : <EOL> default_nodata_val = <NUM_LIT:0> <EOL> geometries = [ basic_geometry ] <EOL> with rasterio . open ( basic_image_file , "<STR_LIT:r>" ) as src : <EOL> masked , transform = mask_tool ( src , geometries , crop = False , invert = True ) <EOL> assert ( masked . data . all ( ) == default_nodata_val ) <EOL> def test_crop ( basic_image , basic_image_file , basic_geometry ) : <EOL> geometries = [ basic_geometry ] <EOL> with rasterio . open ( basic_image_file , "<STR_LIT:r>" ) as src : <EOL> masked , transform = mask_tool ( src , geometries , crop = True ) <EOL> image = basic_image <EOL> image [ <NUM_LIT:4> , : ] = <NUM_LIT:0> <EOL> image [ : , <NUM_LIT:4> ] = <NUM_LIT:0> <EOL> assert ( masked . shape == ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:3> ) ) <EOL> assert ( ( masked [ <NUM_LIT:0> ] == image [ <NUM_LIT:1> : <NUM_LIT:5> , <NUM_LIT:2> : <NUM_LIT:5> ] ) . all ( ) ) <EOL> def test_crop_all_touched ( basic_image , basic_image_file , basic_geometry ) : <EOL> geometries = [ basic_geometry ] <EOL> with rasterio . open ( basic_image_file , "<STR_LIT:r>" ) as src : <EOL> masked , transform = mask_tool ( src , geometries , crop = True , <EOL> all_touched = True ) <EOL> assert ( masked . shape == ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:3> ) ) <EOL> assert ( ( masked [ <NUM_LIT:0> ] == basic_image [ <NUM_LIT:1> : <NUM_LIT:5> , <NUM_LIT:2> : <NUM_LIT:5> ] ) . all ( ) ) <EOL> def test_crop_and_invert ( basic_image_file , basic_geometry ) : <EOL> geometries = [ basic_geometry ] <EOL> with rasterio . open ( basic_image_file ) as src : <EOL> with pytest . raises ( ValueError ) : <EOL> masked , transform = mask_tool ( src , geometries , <EOL> crop = True , invert = True ) </s>
