generated from linz/template-python-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add script to run end-to-end tests TDE-820 #613
Open
paulfouquet
wants to merge
11
commits into
master
Choose a base branch
from
tests/local-end-to-end-test-tde-820
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2d27264
wip
paulfouquet 6388445
wip
paulfouquet 2774b18
wip
paulfouquet 5928312
test: add script to run end to end tests
paulfouquet 52f1592
fix: pylint complaining about duplicate code
paulfouquet 62f9c4d
fix: ci fails
paulfouquet 9a80cc0
fix: docker and path issues
paulfouquet e98c627
fix: path inconsistancy
paulfouquet 537d5c7
fix: unecessary ignore
paulfouquet f2aada9
Merge branch 'master' into tests/local-end-to-end-test-tde-820
paulfouquet 35e1724
Merge branch 'master' into tests/local-end-to-end-test-tde-820
paulfouquet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,9 @@ ignore_missing_imports = true | |
name = "topo-imagery" | ||
version = "3.0.1" | ||
description = "A collection of scripts for processing imagery" | ||
packages = [ | ||
{ include = "scripts" } | ||
] | ||
authors = [ | ||
"Blayne Chard <[email protected]>", | ||
"Daniel Silk <[email protected]>", | ||
|
@@ -35,6 +38,9 @@ authors = [ | |
"Megan Davidson <[email protected]>" | ||
] | ||
|
||
[tool.poetry.scripts] | ||
e2e = "scripts.tests.run_docker_tests:main" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10.6" | ||
boto3 = "^1.28.24" | ||
|
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import argparse | ||
import json | ||
import os | ||
import subprocess | ||
import sys | ||
import tempfile | ||
from enum import Enum | ||
from typing import List, NamedTuple, Optional | ||
|
||
from linz_logger import get_log | ||
|
||
from scripts.cli.cli_helper import InputParameterError, TileFiles, get_tile_files | ||
from scripts.files.fs import read | ||
|
||
docker_tests_dir = "tests/data/" | ||
|
||
|
||
class DataType(str, Enum): | ||
ALL = "all" | ||
AERIAL = "aerial" | ||
ELEVATION = "elevation" | ||
HISTORICAL = "historical" | ||
|
||
|
||
class StandardisingArgs(NamedTuple): | ||
file: str | ||
preset: str | ||
extra_args: Optional[List[str]] = [] | ||
|
||
|
||
def get_preset(data_type: DataType) -> str: | ||
"""Get the preset corresponding to the Data Type. | ||
|
||
Args: | ||
data_type: type of the data | ||
|
||
Returns: | ||
a preset | ||
""" | ||
preset = "webp" | ||
if data_type == DataType.ELEVATION: | ||
preset = "dem_lerc" | ||
|
||
return preset | ||
|
||
|
||
def get_standardising_args(data_type: DataType, test_file_suffix: str) -> List[StandardisingArgs]: | ||
"""Get some specific arguments to run `standardise_validate.py`. | ||
|
||
Args: | ||
data_type: the data type to test | ||
test_file_suffix: suffix of the input file | ||
|
||
Returns: | ||
a list of `StandardisingArgs` | ||
""" | ||
standardising_args = [] | ||
if data_type == DataType.ALL: | ||
for type_enum in DataType: | ||
if type_enum == DataType.ALL: | ||
continue | ||
standardising_args.extend(get_standardising_args(type_enum, test_file_suffix)) | ||
return standardising_args | ||
|
||
standardising_args.append(StandardisingArgs(file=data_type + test_file_suffix, preset=get_preset(data_type))) | ||
if data_type == DataType.AERIAL: | ||
# Add the cutline test | ||
standardising_args.append( | ||
StandardisingArgs( | ||
file=data_type + test_file_suffix, | ||
preset=get_preset(data_type), | ||
extra_args=["--cutline", os.path.join(docker_tests_dir, "cutline.fgb")], | ||
) | ||
) | ||
return standardising_args | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-t", | ||
"--type", | ||
dest="type", | ||
choices=[DataType.ALL.value, DataType.AERIAL.value, DataType.ELEVATION.value, DataType.HISTORICAL.value], | ||
required=True, | ||
help="The data type to run the test on.", | ||
) | ||
parser.add_argument( | ||
"--aws", dest="is_aws", required=False, action="store_true", help="Runs the test using files stored on AWS S3." | ||
) | ||
arguments = parser.parse_args() | ||
data_type = arguments.type | ||
test_file_suffix = ".json" | ||
if arguments.is_aws: | ||
test_file_suffix = "_aws.json" | ||
local_tests_dir = "scripts/tests/data" | ||
|
||
# Build Docker | ||
subprocess.call("docker build -t topo-imagery-test .", shell=True) | ||
|
||
# Get the standardise_validate.py arguments | ||
standardising_args = get_standardising_args(data_type, test_file_suffix) | ||
|
||
for arg in standardising_args: | ||
with tempfile.TemporaryDirectory() as tmp_path: | ||
# Parse the input JSON file in order to test the output | ||
source = json.dumps(json.loads(read(os.path.join(local_tests_dir, arg.file)))) | ||
# pylint: disable-msg=duplicate-code | ||
try: | ||
tile_files: List[TileFiles] = get_tile_files(source) | ||
except InputParameterError as e: | ||
get_log().error("An error occurred while getting tile_files", error=str(e)) | ||
sys.exit(1) | ||
|
||
extra_args = "" | ||
if arg.extra_args: | ||
" ".join(arg.extra_args) | ||
# Run standardise_validate.py with test file | ||
subprocess.call( | ||
f"docker run -v {tmp_path}:/tmp/ topo-imagery-test python3 standardise_validate.py \ | ||
--from-file {os.path.join(docker_tests_dir, arg.file)} --preset {arg.preset} \ | ||
--target-epsg 2193 --source-epsg 2193 --target /tmp/ --collection-id 123 \ | ||
--start-datetime 2023-01-01 --end-datetime 2023-01-01 {extra_args}", | ||
shell=True, | ||
) | ||
|
||
# Verify output(s) | ||
for tile in tile_files: | ||
output_file = f"{tile.output}.tiff" | ||
return_code = subprocess.call( | ||
f"cmp --silent {os.path.join(tmp_path, output_file)} \ | ||
{os.path.join(local_tests_dir, 'output',output_file)}", | ||
shell=True, | ||
) | ||
if return_code != 0: | ||
get_log().error(f"End-to-end test failed with data type {os.path.splitext(arg.file)[0]}") | ||
sys.exit(1) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to
.gitignore
all thetests
directories from this copy, and instead mount them when necessary.