-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add golden test, optional_wd resolves to full path
- Loading branch information
1 parent
a3e3738
commit aba8f7c
Showing
7 changed files
with
121 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Golden Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
pytest: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
python_version: ["3.12"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: mamba-org/setup-micromamba@v1 | ||
with: | ||
environment-file: environment.yml | ||
create-args: >- | ||
python=${{ matrix.python_version }} | ||
- name: Pytest in conda environment | ||
shell: bash -l {0} | ||
run: | | ||
python -m pip install --no-deps . | ||
pytest -m golden |
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
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
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,77 @@ | ||
import filecmp | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
from zipfile import ZipFile | ||
|
||
import pytest | ||
import requests | ||
from shapely import box | ||
|
||
from burst2safe.burst2safe import burst2safe | ||
|
||
|
||
def bit_for_bit(reference: Path, secondary: Path): | ||
filecmp.clear_cache() | ||
return filecmp.cmp(reference, secondary, shallow=False) | ||
|
||
|
||
def prep_golden_safe(tmp_path: Path): | ||
golden_url = 'https://ffwilliams2-shenanigans.s3.us-west-2.amazonaws.com/burst2safe/S1A_IW_SLC__1SSV_20240103T015108_20240103T015112_051936_064669_51EE.zip' | ||
|
||
golden_dir = tmp_path / 'golden' | ||
golden_dir.mkdir(exist_ok=True) | ||
|
||
golden_zip = golden_dir / Path(golden_url).name | ||
with requests.get(golden_url, stream=True) as r: | ||
r.raise_for_status() | ||
with open(golden_zip, 'wb') as f: | ||
for chunk in r.iter_content(chunk_size=2**22): | ||
f.write(chunk) | ||
|
||
with ZipFile(golden_zip, 'r') as z: | ||
z.extractall(golden_dir) | ||
|
||
golden_safe = golden_zip.with_suffix('.SAFE') | ||
return golden_safe | ||
|
||
|
||
@pytest.mark.golden() | ||
def test_golden(tmp_path): | ||
safe_name = 'S1A_IW_SLC__1SSV_20240103T015108_20240103T015112_051936_064669_51EE.SAFE' | ||
golden_safe = (tmp_path / 'golden' / safe_name).resolve() | ||
new_safe = (tmp_path / safe_name).resolve() | ||
|
||
prep_golden_safe(tmp_path) | ||
|
||
with patch('burst2safe.measurement.Measurement.get_time_tag') as mock_get_time_tag: | ||
mock_get_time_tag.return_value = '2024:01:01 00:00:00' | ||
burst2safe( | ||
granules=[], | ||
orbit=51936, | ||
footprint=box(*[-117.3, 35.5, -117.2, 35.6]), | ||
polarizations=['VV', 'VH'], | ||
keep_files=True, | ||
work_dir=tmp_path, | ||
) | ||
|
||
golden_files = sorted([x.resolve() for x in golden_safe.rglob('*')]) | ||
new_files = sorted([x.resolve() for x in new_safe.rglob('*')]) | ||
|
||
golden_set = set([f.relative_to(golden_safe) for f in golden_files]) | ||
new_set = set([f.relative_to(new_safe) for f in new_files]) | ||
|
||
only_in_golden = [str(x) for x in golden_set - new_set] | ||
assert not only_in_golden | ||
|
||
only_in_new = [str(x) for x in new_set - golden_set] | ||
assert not only_in_new | ||
|
||
differing_files = [] | ||
for golden_file, new_file in zip(golden_files, new_files): | ||
if golden_file.is_dir(): | ||
continue | ||
|
||
if not bit_for_bit(golden_file, new_file): | ||
differing_files.append(new_file.relative_to(new_safe)) | ||
differing_files = [str(x) for x in differing_files] | ||
assert not differing_files |
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