|
6 | 6 | import json |
7 | 7 | import subprocess |
8 | 8 | import numpy as np |
| 9 | +import PIL.Image |
9 | 10 | from osgeo import gdal |
10 | 11 |
|
11 | 12 | # The name of the source file to test and it's path |
@@ -129,3 +130,47 @@ def test_outputfile_command_line(): |
129 | 130 | img = gdal.Open(os.path.join(working_space, orthomosaic_mask_name)).ReadAsArray() |
130 | 131 | assert img is not None |
131 | 132 | assert isinstance(img, np.ndarray) |
| 133 | + |
| 134 | + |
| 135 | +def test_plain_tiff(): |
| 136 | + """Runs the command line for a non-GeoTiff file and tests the result""" |
| 137 | + orthomosaic_mask_name = 'plain_mask.tif' |
| 138 | + result_name = 'result.json' |
| 139 | + source_image = os.path.join(TESTING_FILE_PATH, 'orthomosaic.tif') |
| 140 | + source_metadata = os.path.join(TESTING_FILE_PATH, 'experiment.yaml') |
| 141 | + assert os.path.exists(source_image) |
| 142 | + assert os.path.exists(source_metadata) |
| 143 | + |
| 144 | + # Create a non-georeferenced tiff image from the source image |
| 145 | + plain_tiff_image = os.path.join(TESTING_FILE_PATH, 'plain.tif') |
| 146 | + if os.path.exists(plain_tiff_image): |
| 147 | + os.unlink(plain_tiff_image) |
| 148 | + img = PIL.Image.open(source_image) |
| 149 | + img_array = np.array(img) |
| 150 | + result = PIL.Image.fromarray(img_array) |
| 151 | + result.save(plain_tiff_image) |
| 152 | + |
| 153 | + # Setup parameters for running the test |
| 154 | + working_space = os.path.realpath('./test_results') |
| 155 | + os.makedirs(working_space, exist_ok=True) |
| 156 | + for expected_file in [result_name, orthomosaic_mask_name]: |
| 157 | + cur_path = os.path.join(working_space, expected_file) |
| 158 | + if os.path.exists(cur_path): |
| 159 | + os.unlink(cur_path) |
| 160 | + |
| 161 | + command_line = [SOURCE_PATH, '--metadata', source_metadata, '--working_space', working_space, plain_tiff_image] |
| 162 | + subprocess.run(command_line, check=True) |
| 163 | + |
| 164 | + # Check that the expected files were created |
| 165 | + for expected_file in [result_name, orthomosaic_mask_name]: |
| 166 | + assert os.path.exists(os.path.join(working_space, expected_file)) |
| 167 | + |
| 168 | + # Inspect the created files |
| 169 | + with open(os.path.join(working_space, result_name)) as in_file: |
| 170 | + res = json.load(in_file) |
| 171 | + assert 'code' in res |
| 172 | + assert res['code'] == 0 |
| 173 | + |
| 174 | + img = gdal.Open(os.path.join(working_space, orthomosaic_mask_name)).ReadAsArray() |
| 175 | + assert img is not None |
| 176 | + assert isinstance(img, np.ndarray) |
0 commit comments