Commit 045059d0 authored by Jessica Palka's avatar Jessica Palka
Browse files

Extending the test-script: testing the save-function and several plot-functions.

parent 1237594e
Pipeline #924 failed with stages
in 42 seconds
......@@ -106,7 +106,9 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
cls.testtiff = GeoArray(cls.L8_2bands_extract10x11)
# Serialize the "GeoArray"-class to the "data"-directory
with open("".join((tests_path,"/tests/data/testtiff_path.tmp")), "wb") as f:
serialized_testtiff_path = "".join((tests_path,"/tests/data/output/testtiff_path.tmp"))
os.makedirs(os.path.dirname(serialized_testtiff_path), exist_ok=True)
with open(serialized_testtiff_path, "wb") as f:
dill.dump(cls.testtiff, f)
if cls.k == 1:
......@@ -125,7 +127,9 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
projection=cls.given_projection, bandnames=cls.given_bandnames)
# Serialize the "GeoArray"-class to the "data"-directory
with open("".join((tests_path,"/tests/data/testtiff_array.tmp")),"wb") as f:
serialized_testtiff_array = "".join((tests_path, "/tests/data/output/testtiff_array.tmp"))
os.makedirs(os.path.dirname(serialized_testtiff_array), exist_ok=True)
with open(serialized_testtiff_array,"wb") as f:
dill.dump(cls.testtiff, f)
......@@ -199,7 +203,7 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
def test_Bandnames(self):
"""
Testing the function: bandnames.
Test, if the default band names were correctly assigned.
Test, if the default (for k=0) and set (for k=1) band names respectively were correctly assigned.
"""
self.assertEqual(self.testtiff.bandnames, self.expected_bandnames,
msg="The bandnames of the Tiff-file are different than ['B1', 'B2'] (format: OrderedDict)")
......@@ -311,15 +315,15 @@ class Test_GeoarrayAppliedOnPathArray(unittest.TestCase):
"""
Testing the function: nodata,
indirect testing of the functions: find_noDataVal(), set_gdalDataset_meta(!).
Test, if the nodata value of the GeoArray-instance was correctly assigned.
Test, if the set/default nodata value of the GeoArray-instance was correctly assigned.
"""
if self.k == 1:
if self.testtiff.nodata == None:
self.testtiff.nodata = self.given_nodata
else:
self.skipTest("The nodata-value of the 'GeoArray'-object instanced with a numpy.array and without "
self.assertIsNone(self.testtiff.nodata,
msg="The nodata-value of the 'GeoArray'-object instanced with a numpy.array and without "
"declaring a nodata-value is not automatically set to 'None'! "
"The test 'test_NoDataValueOfTiff' will be skipped.")
"The remaining assertion in the test 'test_NoDataValueOfTiff' will not be executed.")
self.testtiff.nodata = self.given_nodata
self.assertEqual(self.testtiff.nodata, self.given_nodata,
msg="The nodata-value of the tested Tiff-file (%s) is not as expected (%s)!"
......@@ -375,23 +379,25 @@ class Test_GeoarrayFunctions(unittest.TestCase):
# Opening the temporary serialized variables (see setUpClass of test case 1) to re-use in the new test case
# without the need to inherit the variables from test case 1.
if cls.k == 0:
with open("".join((tests_path, "/tests/data/testtiff_path.tmp")), "rb") as f:
with open("".join((tests_path, "/tests/data/output/testtiff_path.tmp")), "rb") as f:
cls.testtiff = dill.load(f)
if cls.k == 1:
with open("".join((tests_path, "/tests/data/testtiff_array.tmp")), "rb") as f:
with open("".join((tests_path, "/tests/data/output/testtiff_array.tmp")), "rb") as f:
cls.testtiff = dill.load(f)
@classmethod
def tearDownClass(cls):
# Removing the temporary serialized variables from the 'data'-directory. If test case 2 is not executed,
# the files will be removed at the end of this script in the "if __name__ == '__main__'"-code segment.
if cls.k == 0:
os.remove("".join((tests_path, "/tests/data/testtiff_path.tmp")))
if cls.k == 1:
os.remove("".join((tests_path, "/tests/data/testtiff_array.tmp")))
# Removing the "../tests/data/output"-directory with all files. If test case 2 is not executed, the files
# will be removed at the end of this script in the "if __name__ == '__main__'"-code segment.
data_dir = "".join((tests_path, "/tests/data/output/"))
data_dir_list = os.listdir(data_dir)
for files in data_dir_list:
os.remove(path.join(data_dir, files))
os.rmdir(data_dir)
......@@ -420,11 +426,11 @@ class Test_GeoarrayFunctions(unittest.TestCase):
"""
Testing the function: mask_baddata.
Test,
a) if the output of the mask_baddata-function is "None", when the baddata-mask is not set and
a) if the output of the mask_baddata-function is "None", when the baddata-mask is not set, and
b) if the output of the mask_baddata-function is an instance of "BadDataMask"(class, defined in masks.py).
"""
L8_BadDataMask10x11 = "".join((tests_path, "/tests/data/L8_BadDataMask10x11.tif"))
bdm = masks.BadDataMask(L8_BadDataMask10x11)
self.L8_BadDataMask10x11 = "".join((tests_path, "/tests/data/L8_BadDataMask10x11.tif"))
bdm = masks.BadDataMask(self.L8_BadDataMask10x11)
for i in range(0, 2, 1):
with self.subTest(i=1):
......@@ -449,7 +455,8 @@ class Test_GeoarrayFunctions(unittest.TestCase):
def test_MetadataIsInstanceOfGeodataframe(self):
# TODO test, if the metadata-function gives an output
# TODO: Create metadata-file.
# TODO: Test, if the metadata-function gives an output
"""
Testing the function: metadata.
Test, if the output of the metadata-function is an instance of GeoDataFrame.
......@@ -459,6 +466,54 @@ class Test_GeoarrayFunctions(unittest.TestCase):
def test_SaveTiffToDisk(self):
"""
Testing the function: save,
after executing the function and
test with 2 stages.
Stage 1: After saving the original TIFF-Image (output format "GTiff") to the "../tests/data"-directory with
the "save"-function and then instancing the copied TIFF-Image as "GeoArray"-object, it is first
tested, if the file exists in the aforementioned directory. When the file exists,
induction of stage 2...
Stage 2: Testing, whether a) the object "testtiff_copy" is an instance of the "GeoArray"-class, and b) if the
numpy.array of the copied TIFF-Image is identical to the numpy.array of the original TIFF-Image.
If the newly created file does not exist in the "data"-directory (Stage 1), the whole test will be skipped.
"""
# Saving the "GeoArray"-instance "testtiff" with the "save"-function of the "GeoArray"-class to the
# "../tests/data"-directory of this repository and instancing it again as a "GeoArray"-object.
L8_2bands_extract10x11_copy = "".join((tests_path, "/tests/data/output/L8_BadDataMask10x11_copy.tif"))
self.testtiff.save(L8_2bands_extract10x11_copy, fmt="GTiff")
testtiff_copy = GeoArray(L8_2bands_extract10x11_copy)
if path.exists(L8_2bands_extract10x11_copy):
assert isinstance(testtiff_copy, GeoArray) and \
np.array_equal(self.testtiff[:], testtiff_copy[:]), \
"The copy of the original TIFF-Image, saved by the 'GeoArray' save-function, %s an instance of " \
"class 'GeoArray'. Its numpy.array %s identical to the numpy.array of the original TIFF-Image." \
% ("IS" if isinstance(testtiff_copy, GeoArray) else "IS NOT",
"IS" if np.array_equal(self.testtiff[:], testtiff_copy[:]) else "IS NOT")
else:
self.skipTest("The file '%s' does not exists in the directory '%s'. "
"The test 'test_SaveTiffToDisk' will be skipped."
%(path.basename(L8_2bands_extract10x11_copy), path.dirname(L8_2bands_extract10x11_copy)))
def test_PlottingFunctions(self):
# FIXME: This test-function is not yet complete! + (TODO: Use other parameters of the plot functions!)
# TODO: Idea: Testing of plot-functions with "from matplotlib.testing.decorators import image_comparison" (?)
# TODO: Example of matplotlib.testing.decorators under: https://github.com/ketch/griddle/blob/master/tests/plot_tests.py
self.testtiff.show()
# self.testtiff.show(interactive=True) # only works if test is started with ipython.
self.testtiff.show_map()
# self.testtiff.show_map_utm() # Function still under construction.
self.testtiff.show_histogram()
# ----> TODO: Write tests for the remaining functions!
......@@ -501,8 +556,8 @@ if __name__ == '__main__':
# If-else loop: Creating and executing the second test suite (created with the tests of the test case 2), only
# if the first test case was successful and no test was skipped. Otherwise, a note will be printed as output to
# inform the user that test case 2 was skipped. Additionally, the serialized variable "testtiff" from test
# case 1 will be removed in the else-statement.
# inform the user that test case 2 was skipped. Additionally, the "../tests/data/output"-directory with files
# will be removed in the else-statement.
if testResult.wasSuccessful() and testResult.skipped == []:
other_suite = unittest.TestSuite()
more_test = None
......@@ -518,10 +573,13 @@ if __name__ == '__main__':
# TODO: Change the verbosity of the TextTestRunner to 1
else:
if k == 0:
os.remove("".join((tests_path, "/tests/data/testtiff_path.tmp")))
if k == 1:
os.remove("".join((tests_path, "/tests/data/testtiff_array.tmp")))
data_dir = "".join((tests_path, "/tests/data/output/"))
data_dir_list = os.listdir(data_dir)
for files in data_dir_list:
os.remove(path.join(data_dir, files))
os.rmdir(data_dir)
print("Test case 2: Since %s error/ %s failure/ %s skip occured in the first test case the second test "
"case 'Test_GeoarrayFunctions' will be skipped."
%(len(testResult.errors), len(testResult.failures), len(testResult.skipped)))
......
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