Skip to content

Commit

Permalink
Merge pull request #135 from nasa/feature/issue1-28-increase-test-cov…
Browse files Browse the repository at this point in the history
…erage

Feature/issue 128 increase test coverage
  • Loading branch information
danielfromearth authored Jun 27, 2024
2 parents 96e5cc2 + f5e9d46 commit 39698ec
Show file tree
Hide file tree
Showing 18 changed files with 670 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.4.2'
rev: 'v0.4.10'
hooks:
- id: ruff
args: [ "--fix" ]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [issue #127](https://github.com/nasa/batchee/issues/127): Group dependabot updates into fewer PRs
- [issue #129](https://github.com/nasa/batchee/issues/129): Add autoupdate schedule for pre-commit
### Changed
- [issue #128](https://github.com/nasa/batchee/issues/128): Increase continuous integration/unit test coverage
### Deprecated
### Removed
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion batcher/harmony/service_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def process_catalog(self, catalog: pystac.Catalog) -> list[pystac.Catalog]:
_get_output_date_range([item]),
)
output_item.add_asset(
f"data_{idx}",
"data",
Asset(
_get_item_url(item),
title=_get_item_url(item),
Expand Down
3 changes: 1 addition & 2 deletions batcher/tempo_filename_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import logging
import re
from argparse import ArgumentParser
from pathlib import Path

default_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,7 +98,7 @@ def main() -> list[list[str]]:
if args.verbose:
logging.basicConfig(level=logging.DEBUG)

input_filenames = [str(Path(f).resolve()) for f in args.file_names]
input_filenames = args.file_names

batch_indices = get_batch_indices(input_filenames)
unique_category_indices: list[int] = sorted(set(batch_indices), key=batch_indices.index)
Expand Down
196 changes: 98 additions & 98 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pathlib import Path

import pytest


def pytest_addoption(parser):
"""Sets up optional argument to keep temporary testing directory."""
parser.addoption(
"--keep-tmp",
action="store_true",
help="Keep temporary directory after testing. Useful for debugging.",
)


@pytest.fixture(scope="class")
def pass_options(request):
"""Adds optional argument to a test class."""
request.cls.KEEP_TMP = request.config.getoption("--keep-tmp")


@pytest.fixture(scope="function", autouse=True)
def temp_output_dir(tmpdir_factory) -> Path:
return Path(tmpdir_factory.mktemp("tmp-"))
16 changes: 16 additions & 0 deletions tests/data/harmony/message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sources": [{
"collection": "C1234088182-EEDTEST"
}],
"format": {
"mime": "application/x-netcdf4"
},
"subset": {},
"requestId": "00001111-2222-3333-4444-555566667777",
"user": "jdoe",
"client": "harmony-example",
"isSynchronous": false,
"stagingLocation": "s3://example-bucket/public/some-org/some-service/some-uuid/",
"callback": "http://localhost/some-path",
"version": "0.10.0"
}
48 changes: 48 additions & 0 deletions tests/data/harmony/source/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "cfc32383-cfd1-4e43-8d5f-55f539b6fa59",
"links": [
{
"rel": "harmony_source",
"href": "https://cmr.uat.earthdata.nasa.gov/search/concepts/C1234088182-EEDTEST"
},
{
"rel": "item",
"href": "./granule_S012G01.json",
"type": "application/json",
"title": "granule_S012G01"
},
{
"rel": "item",
"href": "./granule_S012G02.json",
"type": "application/json",
"title": "granule_S012G02"
},
{
"rel": "item",
"href": "./granule_S013G01.json",
"type": "application/json",
"title": "granule_S013G01"
},
{
"rel": "item",
"href": "./granule_S013G02.json",
"type": "application/json",
"title": "granule_S013G02"
},
{
"rel": "item",
"href": "./granule_S014G01.json",
"type": "application/json",
"title": "granule_S014G01"
},
{
"rel": "item",
"href": "./granule_S014G02.json",
"type": "application/json",
"title": "granule_S014G02"
}
],
"description": "CMR Granules for C1234088182-EEDTEST batch 1"
}
36 changes: 36 additions & 0 deletions tests/data/harmony/source/catalog0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "cfc32383-cfd1-4e43-8d5f-55f539b6fa59",
"links": [
{
"rel": "harmony_source",
"href": "https://cmr.uat.earthdata.nasa.gov/search/concepts/C1234088182-EEDTEST"
},
{
"rel": "item",
"href": "./granule_S012G01.json",
"type": "application/json",
"title": "granule_S012G01"
},
{
"rel": "item",
"href": "./granule_S012G02.json",
"type": "application/json",
"title": "granule_S012G02"
},
{
"rel": "item",
"href": "./granule_S013G01.json",
"type": "application/json",
"title": "granule_S013G01"
},
{
"rel": "next",
"href": "tests/data/harmony/source/catalog1.json",
"type": "application/json",
"title": "Next page"
}
],
"description": "CMR Granules for C1234088182-EEDTEST batch 1"
}
36 changes: 36 additions & 0 deletions tests/data/harmony/source/catalog1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "cfc32383-cfd1-4e43-8d5f-55f539b6fa59",
"links": [
{
"rel": "harmony_source",
"href": "https://cmr.uat.earthdata.nasa.gov/search/concepts/C1234088182-EEDTEST"
},
{
"rel": "item",
"href": "./granule_S013G02.json",
"type": "application/json",
"title": "granule_S013G02"
},
{
"rel": "item",
"href": "./granule_S014G01.json",
"type": "application/json",
"title": "granule_S014G01"
},
{
"rel": "item",
"href": "./granule_S014G02.json",
"type": "application/json",
"title": "granule_S014G02"
},
{
"rel": "prev",
"href": "tests/data/harmony/source/catalog0.json",
"type": "application/json",
"title": "Previous page"
}
],
"description": "CMR Granules for C1234088182-EEDTEST batch 2"
}
49 changes: 49 additions & 0 deletions tests/data/harmony/source/granule_S012G01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "51d02b24-d00e-4640-9887-05f98f6b96d8",
"type": "Feature",
"links": [],
"properties": {
"start_datetime": "2020-01-02T00:00:00.000Z",
"end_datetime": "2020-01-02T23:59:59.000Z"
},
"bbox": [1, 3, 1, 3],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-179.95,
-89.95
],
[
-179.95,
89.95
],
[
179.95,
89.95
],
[
179.95,
-89.95
],
[
-179.95,
-89.95
]
]
]
},
"assets": {
"data": {
"href": "file://tests/data/harmony/granules/TEMPO_NO2_L2_V03_20240601T120101Z_S012G01.nc",
"title": "TEMPO_NO2_L2_V03_20240601T120101Z_S012G01.nc",
"type": "application/x-netcdf4",
"roles": [
"data"
]
}
}
}
49 changes: 49 additions & 0 deletions tests/data/harmony/source/granule_S012G02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "21eb7dc5-7a9d-4374-9a88-12451ba653ef",
"type": "Feature",
"links": [],
"properties": {
"start_datetime": "2020-01-03T00:00:00.000Z",
"end_datetime": "2020-01-03T23:59:59.000Z"
},
"bbox": [-1, -3, -1, -3],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-179.95,
-89.95
],
[
-179.95,
89.95
],
[
179.95,
89.95
],
[
179.95,
-89.95
],
[
-179.95,
-89.95
]
]
]
},
"assets": {
"data": {
"href": "file://tests/data/harmony/granules/TEMPO_NO2_L2_V03_20240601T120107Z_S012G02.nc",
"title": "TEMPO_NO2_L2_V03_20240601T120107Z_S012G02.nc",
"type": "application/x-netcdf4",
"roles": [
"data"
]
}
}
}
49 changes: 49 additions & 0 deletions tests/data/harmony/source/granule_S013G01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"stac_version": "1.0.0-beta.2",
"stac_extensions": [],
"id": "dc07a25a-54bd-4389-97b6-c1d68cf0d586",
"type": "Feature",
"links": [],
"properties": {
"start_datetime": "2020-01-05T00:00:00.000Z",
"end_datetime": "2020-01-05T23:59:59.000Z"
},
"bbox": [-4, -2, -4, 2],
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-179.95,
-89.95
],
[
-179.95,
89.95
],
[
179.95,
89.95
],
[
179.95,
-89.95
],
[
-179.95,
-89.95
]
]
]
},
"assets": {
"data": {
"href": "file://tests/data/harmony/granules/TEMPO_NO2_L2_V03_20240601T120202Z_S013G01.nc",
"title": "TEMPO_NO2_L2_V03_20240601T120202Z_S013G01.nc",
"type": "application/x-netcdf4",
"roles": [
"data"
]
}
}
}
Loading

0 comments on commit 39698ec

Please sign in to comment.