Skip to content

Commit

Permalink
Post test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Schnaufer committed Oct 9, 2020
1 parent 8d8c9dd commit b04f86b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion soilmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def add_parameters(self, parser: argparse.ArgumentParser) -> None:
# pylint: disable=no-self-use
parser.add_argument('--out_file', type=str, help='the path to save the masked file to')

parser.epilog += 'Mask files are saved with the .msk filename extension added when not specified. '
parser.epilog += ' Mask files are saved with the .msk filename extension added when not specified.'

def check_continue(self, environment: Environment, check_md: dict, transformer_md: list,
full_md: list) -> tuple:
Expand Down
33 changes: 32 additions & 1 deletion tests/test_soilmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_prepare_metadata_for_geotiff():
assert value == str(test[METADATA_KEY_TRANSLATION['transformer_repo']]['repUrl'])


def test_command_line():
def test_simple_line():
"""Runs the command line and tests the result"""
orthomosaic_mask_name = 'orthomosaic_mask.tif'
result_name = 'result.json'
Expand Down Expand Up @@ -98,3 +98,34 @@ def test_command_line():
img = gdal.Open(os.path.join(working_space, orthomosaic_mask_name)).ReadAsArray()
assert img is not None
assert isinstance(img, np.ndarray)


def test_outputfile_command_line():
"""Runs the command line and tests the result"""
orthomosaic_mask_name = 'soilmask.tif'
result_name = 'result.json'
source_image = os.path.join(TESTING_FILE_PATH, 'orthomosaic.tif')
source_metadata = os.path.join(TESTING_FILE_PATH, 'experiment.yaml')
assert os.path.exists(source_image)
assert os.path.exists(source_metadata)

working_space = os.path.realpath('./test_results')
os.makedirs(working_space, exist_ok=True)

command_line = [SOURCE_PATH, '--metadata', source_metadata, '--working_space', working_space,
'--out_file', orthomosaic_mask_name, source_image]
subprocess.run(command_line, check=True)

# Check that the expected files were created
for expected_file in [result_name, orthomosaic_mask_name]:
assert os.path.exists(os.path.join(working_space, expected_file))

# Inspect the created files
with open(os.path.join(working_space, result_name)) as in_file:
res = json.load(in_file)
assert 'code' in res
assert res['code'] == 0

img = gdal.Open(os.path.join(working_space, orthomosaic_mask_name)).ReadAsArray()
assert img is not None
assert isinstance(img, np.ndarray)

0 comments on commit b04f86b

Please sign in to comment.