Commit 198807df authored by Jessica Palka's avatar Jessica Palka
Browse files

Commiting the first part of the new test case

parent 4c85d4d8
......@@ -37,23 +37,13 @@ from geoarray import __file__ as path_geoarrayLib
###################################################################################
# Test case: Test_GeoarrayAppliedOnTiffPath
class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
@classmethod
def setUpClass(cls):
global L8_2bands_extract10x11
# Test case: Test_BaseFunctionsOfGeoarray
L8_2bands_extract10x11 = \
os.path.join(os.path.dirname(path_geoarrayLib), '../tests/data/L8_2bands_extract10x11.tif')
cls.testtiff = GeoArray(L8_2bands_extract10x11)
cls.TiffIsInstanceOfGeoarray(cls)
cls.ArrOfTiffIsInMemory(cls)
class Test_BaseFunctionsOfGeoarray(unittest.TestCase):
__test__ = False
testtiff = None
def TiffIsInstanceOfGeoarray(self):
"""
......@@ -65,7 +55,7 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
try:
assert isinstance(self.testtiff, GeoArray)
except AssertionError:
self.skipTest(Test_GeoarrayAppliedOnTiffPath,
self.skipTest(Test_BaseFunctionsOfGeoarray,
reason="The created object 'testtiff' is not an instance of class 'GeoArray'. "
"All tests of the Test Case 'Test_GeoarrayAppliedOnTiffPath' will be skipped!")
......@@ -84,30 +74,30 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
expected_conditions = ((None, False), (True, True))
#PATH
if os.path.isfile(L8_2bands_extract10x11):
# PATH
if isinstance(L8_2bands_extract10x11, str) and os.path.isfile(L8_2bands_extract10x11):
try:
assert (testtiff_basicfunctions[0] == expected_conditions[0][0]) and \
(testtiff_basicfunctions[1] == expected_conditions[0][1])
(testtiff_basicfunctions[1] == expected_conditions[0][1])
except AssertionError:
self.skipTest(Test_GeoarrayAppliedOnTiffPath,
reason="A path is passed to 'GeoArray'. But the output of the functions "
"arr and is_inmem %s do not match as expected %s!"
%(testtiff_basicfunctions, expected_conditions[0]))
self.skipTest(Test_BaseFunctionsOfGeoarray,
reason="A path is passed to 'GeoArray'. But the output of the functions "
"arr and is_inmem %s do not match as expected %s!"
%(testtiff_basicfunctions, expected_conditions[0]))
#NUMPY.NDARRAY
# NUMPY.NDARRAY
elif isinstance(L8_2bands_extract10x11, np.ndarray):
try:
assert (isinstance(testtiff_basicfunctions[0], np.ndarray) == expected_conditions[1][0]) and \
(testtiff_basicfunctions[1] == expected_conditions[1][1])
except AssertionError:
self.skipTest(Test_GeoarrayAppliedOnTiffPath,
self.skipTest(Test_BaseFunctionsOfGeoarray,
reason="A numpy.ndarray is passed to 'GeoArray'. But the output of the functions "
"arr and is_inmem %s do not match as expected %s!"
%(testtiff_basicfunctions, expected_conditions[1]))
else:
self.skipTest(Test_GeoarrayAppliedOnTiffPath,
self.skipTest(Test_BaseFunctionsOfGeoarray,
reason="The variable committed to the 'GeoArray'-class is neither a path nor a numpy.ndarray."
"All tests of the Test Case 'Test_GeoarrayAppliedOnTiffPath' will be skipped!")
......@@ -135,7 +125,7 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
"""
expected_shape = (10, 11, 2)
expected_result = (3, *expected_shape) #dimensions, rows, columns, bands
expected_result = (len(expected_shape), *expected_shape) #dimensions, rows, columns, bands
testtiff_shapefunctions = (self.testtiff.ndim, self.testtiff.rows, self.testtiff.columns, self.testtiff.bands)
shape_property = ('DIMENSIONS', 'ROWS', 'COLUMNS', 'BANDS')
......@@ -150,7 +140,7 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
else:
print("The shape of the array behind the 'Geoarray'-object is not as expected! "
"The test 'test_ShapeOfTiffArray' will be skipped.")
self.skipTest(Test_GeoarrayAppliedOnTiffPath)
self.skipTest(Test_BaseFunctionsOfGeoarray)
......@@ -177,13 +167,12 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
If an exception is raised as an error in stage 1 or 2, the test will be skipped.
"""
expected_geotransform = (365985.0, 30.0, 0.0, 5916615.0, 0.0, -30.0)
expected_resolution = (30, 30) #(expected_geotransform[1], expected_geotransform[-1])
expected_resolution = (30, 30) #(info_geotransform[1], info_geotransform[-1])
expected_grid = [[365985.0, 366015.0], [5916615.0, 5916585.0]]
testtiff_resolutionfunctions = (self.testtiff.xgsd, self.testtiff.ygsd)
if self.testtiff.geotransform == expected_geotransform:
if self.testtiff.geotransform == given_geotransform:
if testtiff_resolutionfunctions == expected_resolution:
self.assertEqual(self.testtiff.xygrid_specs, expected_grid,
msg='The [[xOrigin, xGSD], [yOrigin, yGSD]]-grid is not as expected!')
......@@ -192,11 +181,11 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
print("The x/y-resolution %s of the grid of the tested Tiff-file is not as expected %s! "
"The function 'XYGRID_SPECS' will not be tested."
%(testtiff_resolutionfunctions, expected_resolution))
self.skipTest(Test_GeoarrayAppliedOnTiffPath)
self.skipTest(Test_BaseFunctionsOfGeoarray)
else:
print("The geotransform-tuple of the array behind the 'GeoArray'-object is not as expected! "
"The test 'test_GeotransformTiff' will be skipped.")
self.skipTest(Test_GeoarrayAppliedOnTiffPath)
self.skipTest(Test_BaseFunctionsOfGeoarray)
......@@ -209,18 +198,17 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
If the pszProj5-string is not as expected (Stage 1), the whole test will be skipped.
"""
expected_pszProj4_string = '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs'
expected_epsg = 32633
# Convert WKT-string of the projection to a pszProj4_string
# Code adapted from source:
# mgleahy, 2010-11-21 http://spatialnotes.blogspot.de/2010/11/converting-wkt-projection-info-to-proj4.html
# mgleahy, 2010-11-21, http://spatialnotes.blogspot.de/2010/11/converting-wkt-projection-info-to-proj4.html
srs = osgeo.osr.SpatialReference()
srs.ImportFromWkt(self.testtiff.projection)
testtiff_pszProj4_string = srs.ExportToProj4()
if testtiff_pszProj4_string.strip(' /t/n/r') == expected_pszProj4_string:
if testtiff_pszProj4_string.strip(' /t/n/r') == given_pszProj4_string:
self.assertEqual(self.testtiff.epsg, expected_epsg,
msg="The EPSG-code returned by the 'GeoArray' epsg-function (%s) is not "
"equal to the expected code (%s)." %(self.testtiff.epsg, expected_epsg))
......@@ -228,7 +216,7 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
else:
print("The projections of the 'GeoArray'-object is not as expected! "
"The test 'test_ProjectionTiff' will be skipped.")
self.skipTest(Test_GeoarrayAppliedOnTiffPath)
self.skipTest(Test_BaseFunctionsOfGeoarray)
......@@ -237,13 +225,90 @@ class Test_GeoarrayAppliedOnTiffPath(unittest.TestCase):
Test, if the nodata value of the image was correctly assigned.
"""
expected_nodata = -9999.0
self.assertEqual(self.testtiff.nodata, expected_nodata,
self.assertEqual(self.testtiff.nodata, given_nodata,
msg="The nodata-value of the tested Tiff-file (%s) is not as expected (%s)!"
%(self.testtiff.nodata, expected_nodata))
%(self.testtiff.nodata, given_nodata))
###################################################################################
# Test case: Test_GeoarrayAppliedOnTiffPath
class Test_GeoarrayAppliedOnTiffPath(Test_BaseFunctionsOfGeoarray):
__test__ = True
@classmethod
def setUpClass(cls):
global L8_2bands_extract10x11, given_geotransform, given_pszProj4_string, given_nodata
L8_2bands_extract10x11 = "../tests/data/L8_2bands_extract10x11.tif"
given_geotransform = (365985.0, 30.0, 0.0, 5916615.0, 0.0, -30.0)
given_pszProj4_string = '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs'
given_nodata = -9999.0
cls.testtiff = GeoArray(L8_2bands_extract10x11)
Test_BaseFunctionsOfGeoarray.TiffIsInstanceOfGeoarray(cls)
Test_BaseFunctionsOfGeoarray.ArrOfTiffIsInMemory(cls)
###################################################################################
# Test case: Test_GeoarrayAppliedOnArray
class Test_GeoarrayAppliedOnArray(Test_BaseFunctionsOfGeoarray):
__test__ = True
@classmethod
def setUpClass(cls):
#super(Test_GeoarrayAppliedOnTiffPath, cls).setUp(cls)
global L8_2bands_extract10x11, given_geotransform, given_pszProj4_string, given_nodata
# Load array from file
array_path = "../tests/data/L8_2bands_extract10x11_array.txt"
L8_2bands_extract10x11 = np.loadtxt(array_path, 'float32').reshape(10, 11, 2)
# Declare known geoinformations
given_geotransform = (365985.0, 30.0, 0.0, 5916615.0, 0.0, -30.0)
given_pszProj4_string = '+proj=utm +zone=33 +datum=WGS84 +units=m +no_defs'
srs = osgeo.osr.SpatialReference()
srs.ImportFromProj4(given_pszProj4_string)
given_projection = srs.ExportToWkt()
given_nodata = -9999.0
# Create "GeoArray" instance with an array, not a path
cls.testtiff = GeoArray(L8_2bands_extract10x11, geotransform=given_geotransform, projection=given_projection,
nodata=given_nodata)
Test_BaseFunctionsOfGeoarray.TiffIsInstanceOfGeoarray(cls)
Test_BaseFunctionsOfGeoarray.ArrOfTiffIsInMemory(cls)
#super(Test_GeoarrayAppliedOnTiffPath, cls).setUp(cls)
###################################################################################
# Defining a test suite
def suite():
'''
Defining a test suite existing of both test cases. All tests that start with "test_" are added to the test suite.
Note that both test cases ('Test_GeoarrayAppliedOnTiffPath' and 'Test_GeoarrayAppliedOnTiffPath') inherit all
tests from the test case 'Test_BaseFunctionsOfGeoarray'.
'''
Suite = unittest.TestSuite()
Suite.addTest(unittest.makeSuite(Test_GeoarrayAppliedOnTiffPath))
Suite.addTest(unittest.makeSuite(Test_GeoarrayAppliedOnArray))
return Suite
if __name__ == '__main__':
unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
#unittest.main(argv=['first-arg-is-ignored'],exit=False, verbosity=2)
unittest.TextTestRunner(verbosity=2).run(suite())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment