def test_load_as_matrix_tempfile(self): """ Test that whole image is loaded successfully using tempfile loader. """ wrapped_temp_loader = mock.MagicMock(wraps=load_dataset_tempfile) wrapped_vsimem_loader = mock.MagicMock(wraps=load_dataset_vsimem) with mock.patch.dict( GdalImageReader.LOAD_METHOD_CONTEXTMANAGERS, { GdalImageReader.LOAD_METHOD_TEMPFILE: wrapped_temp_loader, GdalImageReader.LOAD_METHOD_VSIMEM: wrapped_vsimem_loader }): # Using tempfile load method reader = GdalImageReader( load_method=GdalImageReader.LOAD_METHOD_TEMPFILE) mat = reader._load_as_matrix(GH_FILE_ELEMENT) assert mat.shape == (600, 512, 3) wrapped_temp_loader.assert_called_once_with(GH_FILE_ELEMENT) wrapped_vsimem_loader.assert_not_called()
def test_load_as_matrix_vsimem(self): """ Test that whole image is loaded successfully using vsimem loader. """ if LooseVersion(osgeo.__version__).version[0] < 2: pytest.skip("Skipping VSIMEM test because GDAL version < 2") wrapped_temp_loader = mock.MagicMock(wraps=load_dataset_tempfile) wrapped_vsimem_loader = mock.MagicMock(wraps=load_dataset_vsimem) with mock.patch.dict( GdalImageReader.LOAD_METHOD_CONTEXTMANAGERS, { GdalImageReader.LOAD_METHOD_TEMPFILE: wrapped_temp_loader, GdalImageReader.LOAD_METHOD_VSIMEM: wrapped_vsimem_loader }): # Using VSIMEM load method reader = GdalImageReader( load_method=GdalImageReader.LOAD_METHOD_VSIMEM) mat = reader._load_as_matrix(GH_FILE_ELEMENT) assert mat.shape == (600, 512, 3) wrapped_temp_loader.assert_not_called() wrapped_vsimem_loader.assert_called_once_with(GH_FILE_ELEMENT)