Skip to content

Commit 4f1b513

Browse files
authored
Add test of VRT support (#15)
1 parent abd97d5 commit 4f1b513

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

processinghistory/tests.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,51 @@ def test_useDataset(self):
206206

207207
self.deleteTempFiles([filename])
208208

209+
def test_vrtsupport(self):
210+
"""
211+
Test VRT support
212+
"""
213+
kea1 = 'img1.kea'
214+
kea2 = 'img2.kea'
215+
vrt = 'test.vrt'
216+
tmpfileList = [kea1, kea2, vrt]
217+
makeRaster(kea1)
218+
makeRaster(kea2)
219+
history.writeHistoryToFile(filename=kea1)
220+
history.writeHistoryToFile(filename=kea2)
221+
gdal.BuildVRT(vrt, [kea1, kea2])
222+
223+
# First test read with no history
224+
procHist = history.readHistoryFromFile(vrt)
225+
self.assertIsNone(procHist,
226+
msg="Read from VRT with no history should return None")
227+
228+
# Add history
229+
history.writeHistoryToFile(filename=vrt)
230+
# Read it back, and check that the components were added as parents
231+
procHist = history.readHistoryFromFile(vrt)
232+
parentsList = sorted(procHist.parentsByKey[history.CURRENTFILE_KEY])
233+
self.assertEqual(len(parentsList), 2,
234+
msg="Incorrect number of parents from VRT")
235+
componentList = sorted([kea1, kea2])
236+
for i in range(len(componentList)):
237+
parentFile = parentsList[i][0]
238+
componentFile = componentList[i]
239+
self.assertEqual(componentFile, parentFile)
240+
241+
# Check that parents are not actually included in the VRT
242+
ds = gdal.Open(vrt)
243+
procHistJSON = ds.GetMetadataItem(history.METADATA_GDALITEMNAME)
244+
procHist = history.ProcessingHistory.fromJSON(procHistJSON)
245+
self.assertEqual(len(procHist.parentsByKey[history.CURRENTFILE_KEY]),
246+
0, msg="Should be no parents embedded in VRT")
247+
self.assertEqual(len(procHist.parentsByKey), 1,
248+
msg="Should be exactly 1 parent entry in VRT")
249+
self.assertEqual(len(procHist.metadataByKey), 1,
250+
msg="Should be exactly 1 metadata entry in VRT")
251+
252+
self.deleteTempFiles(tmpfileList)
253+
209254
@staticmethod
210255
def deleteTempFiles(filelist):
211256
"""

0 commit comments

Comments
 (0)