Fixed a failing test when the source directory is on a readonly fs.
This commit is contained in:
parent
3deea61f26
commit
e127ef62de
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import struct
|
import struct
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
@ -541,54 +542,54 @@ class GDALRasterTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
||||||
class GDALBandTests(SimpleTestCase):
|
class GDALBandTests(SimpleTestCase):
|
||||||
def setUp(self):
|
rs_path = os.path.join(os.path.dirname(__file__), '../data/rasters/raster.tif')
|
||||||
self.rs_path = os.path.join(os.path.dirname(__file__), '../data/rasters/raster.tif')
|
|
||||||
rs = GDALRaster(self.rs_path)
|
|
||||||
self.band = rs.bands[0]
|
|
||||||
|
|
||||||
def test_band_data(self):
|
def test_band_data(self):
|
||||||
pam_file = self.rs_path + '.aux.xml'
|
rs = GDALRaster(self.rs_path)
|
||||||
self.assertEqual(self.band.width, 163)
|
band = rs.bands[0]
|
||||||
self.assertEqual(self.band.height, 174)
|
self.assertEqual(band.width, 163)
|
||||||
self.assertEqual(self.band.description, '')
|
self.assertEqual(band.height, 174)
|
||||||
self.assertEqual(self.band.datatype(), 1)
|
self.assertEqual(band.description, '')
|
||||||
self.assertEqual(self.band.datatype(as_string=True), 'GDT_Byte')
|
self.assertEqual(band.datatype(), 1)
|
||||||
self.assertEqual(self.band.color_interp(), 1)
|
self.assertEqual(band.datatype(as_string=True), 'GDT_Byte')
|
||||||
self.assertEqual(self.band.color_interp(as_string=True), 'GCI_GrayIndex')
|
self.assertEqual(band.color_interp(), 1)
|
||||||
self.assertEqual(self.band.nodata_value, 15)
|
self.assertEqual(band.color_interp(as_string=True), 'GCI_GrayIndex')
|
||||||
|
self.assertEqual(band.nodata_value, 15)
|
||||||
if numpy:
|
if numpy:
|
||||||
data = self.band.data()
|
data = band.data()
|
||||||
assert_array = numpy.loadtxt(
|
assert_array = numpy.loadtxt(
|
||||||
os.path.join(os.path.dirname(__file__), '../data/rasters/raster.numpy.txt')
|
os.path.join(os.path.dirname(__file__), '../data/rasters/raster.numpy.txt')
|
||||||
)
|
)
|
||||||
numpy.testing.assert_equal(data, assert_array)
|
numpy.testing.assert_equal(data, assert_array)
|
||||||
self.assertEqual(data.shape, (self.band.height, self.band.width))
|
self.assertEqual(data.shape, (band.height, band.width))
|
||||||
try:
|
|
||||||
smin, smax, smean, sstd = self.band.statistics(approximate=True)
|
def test_band_statistics(self):
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
rs_path = os.path.join(tmp_dir, 'raster.tif')
|
||||||
|
shutil.copyfile(self.rs_path, rs_path)
|
||||||
|
rs = GDALRaster(rs_path)
|
||||||
|
band = rs.bands[0]
|
||||||
|
pam_file = rs_path + '.aux.xml'
|
||||||
|
smin, smax, smean, sstd = band.statistics(approximate=True)
|
||||||
self.assertEqual(smin, 0)
|
self.assertEqual(smin, 0)
|
||||||
self.assertEqual(smax, 9)
|
self.assertEqual(smax, 9)
|
||||||
self.assertAlmostEqual(smean, 2.842331288343558)
|
self.assertAlmostEqual(smean, 2.842331288343558)
|
||||||
self.assertAlmostEqual(sstd, 2.3965567248965356)
|
self.assertAlmostEqual(sstd, 2.3965567248965356)
|
||||||
|
|
||||||
smin, smax, smean, sstd = self.band.statistics(approximate=False, refresh=True)
|
smin, smax, smean, sstd = band.statistics(approximate=False, refresh=True)
|
||||||
self.assertEqual(smin, 0)
|
self.assertEqual(smin, 0)
|
||||||
self.assertEqual(smax, 9)
|
self.assertEqual(smax, 9)
|
||||||
self.assertAlmostEqual(smean, 2.828326634228898)
|
self.assertAlmostEqual(smean, 2.828326634228898)
|
||||||
self.assertAlmostEqual(sstd, 2.4260526986669095)
|
self.assertAlmostEqual(sstd, 2.4260526986669095)
|
||||||
|
|
||||||
self.assertEqual(self.band.min, 0)
|
self.assertEqual(band.min, 0)
|
||||||
self.assertEqual(self.band.max, 9)
|
self.assertEqual(band.max, 9)
|
||||||
self.assertAlmostEqual(self.band.mean, 2.828326634228898)
|
self.assertAlmostEqual(band.mean, 2.828326634228898)
|
||||||
self.assertAlmostEqual(self.band.std, 2.4260526986669095)
|
self.assertAlmostEqual(band.std, 2.4260526986669095)
|
||||||
|
|
||||||
# Statistics are persisted into PAM file on band close
|
# Statistics are persisted into PAM file on band close
|
||||||
self.band = None
|
rs = band = None
|
||||||
self.assertTrue(os.path.isfile(pam_file))
|
self.assertTrue(os.path.isfile(pam_file))
|
||||||
finally:
|
|
||||||
# Close band and remove file if created
|
|
||||||
self.band = None
|
|
||||||
if os.path.isfile(pam_file):
|
|
||||||
os.remove(pam_file)
|
|
||||||
|
|
||||||
def test_read_mode_error(self):
|
def test_read_mode_error(self):
|
||||||
# Open raster in read mode
|
# Open raster in read mode
|
||||||
|
|
Loading…
Reference in New Issue