Skip to content

Commit f671d9d

Browse files
authored
Tests, Github Actions, and Python 3.8, 3.9 support (#4)
Adds a fixture, test, and the github workflow required to run the tests on github actions. I originally added a test data file copied from https://github.com/stac-utils/pystac/blob/v1.6.1/tests/data-files/examples/1.0.0/simple-item.json but then I realized I can just link out to that file where it lives. I still need to decide whether tests should do reads from remote files or not.
1 parent c7eb91e commit f671d9d

File tree

8 files changed

+112
-7
lines changed

8 files changed

+112
-7
lines changed

.github/workflows/tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
schedule:
9+
- cron: "20 22 * * 0"
10+
11+
concurrency:
12+
group: ${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
defaults:
16+
run:
17+
shell: bash -l {0}
18+
19+
jobs:
20+
test:
21+
name: ${{ matrix.python-version }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [ubuntu-latest]
27+
python-version: ["3.8", "3.9", "3.10", "3.11"]
28+
environment-file: ["environment.yaml"]
29+
defaults:
30+
run:
31+
shell: bash -l {0}
32+
33+
steps:
34+
- name: checkout repo
35+
uses: actions/[email protected]
36+
37+
- name: setup micromamba
38+
uses: mamba-org/provision-with-micromamba@main
39+
with:
40+
environment-file: ${{ matrix.environment-file }}
41+
micromamba-version: "latest"
42+
extra-specs: python=${{ matrix.python-version }}
43+
channel-priority: "flexible"
44+
45+
- name: install xpystac
46+
run: pip install .
47+
48+
- name: run tests
49+
id: status
50+
run: pytest -v .

.pre-commit-config.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11

22
repos:
3+
- repo: https://github.com/MarcoGorelli/absolufy-imports
4+
rev: v0.3.1
5+
hooks:
6+
- id: absolufy-imports
7+
name: absolufy-imports
8+
- repo: https://github.com/pycqa/isort
9+
rev: 5.12.0
10+
hooks:
11+
- id: isort
12+
language_version: python3
13+
- repo: https://github.com/asottile/pyupgrade
14+
rev: v3.2.2
15+
hooks:
16+
- id: pyupgrade
17+
args:
18+
- --py38-plus
319
- repo: https://github.com/psf/black
4-
rev: "22.12.0"
20+
rev: "23.1.0"
521
hooks:
622
- id: black
7-
additional_dependencies: ['click==8.0.4']
823
- repo: https://github.com/pycqa/flake8
924
rev: 6.0.0
1025
hooks:

environment.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: xpystac-dev
2+
channels:
3+
- conda-forge
4+
- nodefaults
5+
dependencies:
6+
- python
7+
# required
8+
- pystac
9+
- xarray
10+
# optional
11+
- fsspec
12+
- planetary-computer
13+
- pystac-client
14+
- requests
15+
- rioxarray
16+
- stackstac
17+
- zarr
18+
# testing
19+
- pytest

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pystac
2+
import pytest
3+
4+
5+
@pytest.fixture(scope="module")
6+
def simple_item() -> pystac.Item:
7+
path = "https://raw.githubusercontent.com/stac-utils/pystac/2.0/tests/data-files/examples/1.0.0/simple-item.json"
8+
return pystac.Item.from_file(path)

tests/test_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pystac
2+
3+
from xpystac.core import to_xarray
4+
5+
6+
def test_asset_to_xarray(simple_item):
7+
asset = simple_item.assets["visual"]
8+
assert asset.media_type == pystac.MediaType.COG
9+
ds = to_xarray(asset)
10+
assert ds

xpystac/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import functools
2+
from typing import List, Union
23

34
import pystac
45
import xarray
56

6-
from .utils import _import_optional_dependency
7+
from xpystac.utils import _import_optional_dependency
78

89

910
@functools.singledispatch
@@ -18,8 +19,8 @@ def to_xarray(item, **kwargs) -> xarray.Dataset:
1819
@to_xarray.register(pystac.Item)
1920
@to_xarray.register(pystac.ItemCollection)
2021
def _(
21-
obj: pystac.Item | pystac.ItemCollection,
22-
drop_variables: str | list[str] = None,
22+
obj: Union[pystac.Item, pystac.ItemCollection],
23+
drop_variables: Union[str, List[str]] = None,
2324
**kwargs,
2425
) -> xarray.Dataset:
2526
stackstac = _import_optional_dependency("stackstac")

xpystac/xarray_plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
from typing import List, Union
2+
13
import pystac
24
from xarray.backends import BackendEntrypoint
35

4-
from .core import to_xarray
6+
from xpystac.core import to_xarray
57

68

79
class STACBackend(BackendEntrypoint):
810
def open_dataset(
911
self,
1012
obj,
1113
*,
12-
drop_variables: str | list[str] = None,
14+
drop_variables: Union[str, List[str]] = None,
1315
**kwargs,
1416
):
1517
return to_xarray(obj, drop_variables=drop_variables, **kwargs)

0 commit comments

Comments
 (0)