Skip to content

Commit

Permalink
PR review addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
konstntokas committed May 14, 2024
1 parent 81bfdfa commit bc453ed
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 133 deletions.
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,41 @@ access data from the [STAC - SpatioTemporal Asset Catalogs](https://stacspec.org
Installing xcube-cmems directly from the git repository, clone the repository,
direct into `xcube-stac`, and follow the steps below:

```
$ conda env create -f environment.yml
$ conda activate xcube-stac
$ pip install .
```bash
conda env create -f environment.yml
conda activate xcube-stac
pip install .
```
This installs all the dependencies of `xcube-stac` into a fresh conda environment,
then installs xcube-stac into this environment from the repository.

## Testing

To run the unit test suite:

```bash
pytest
```

To analyze test coverage (after installing pytest as above):

```bash
pytest --cov=xcube_stac
```

To produce an HTML
[coverage report](https://pytest-cov.readthedocs.io/en/latest/reporting.html):

```bash
pytest --cov-report html --cov=xcube_stac
```

### Some notes on the strategy of unittesting:

The unit test suite uses [pytest-recording](https://pypi.org/project/pytest-recording/) to mock STAC catalogs. During development an actual HTTP request is performed to a STAC catalog and the responses are saved in `cassettes/**.yaml` files. During testing, only the `cassettes/**.yaml` files are used without an actual HTTP request. During development run

```bash
pytest -v -s --record-mode new_episodes
```

which saves the responses to `cassettes/**.yaml`. The testing can be then performed as usual.
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
- defaults
dependencies:
# Required
- python>=3.10
- python>=3.11
- pystac
- pystac-client
- xarray
Expand All @@ -13,4 +13,5 @@ dependencies:
- black
- flake8
- pytest
- pytest-cov
- pytest-recording
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ exclude = [

[project.optional-dependencies]
dev = [
"black",
"flake8",
"pytest",
"pytest-cov",
"pytest-recording",
"black",
"flake8"
"pytest-recording"
]

[project.urls]
Expand Down
150 changes: 150 additions & 0 deletions test/cassettes/test_stac/StacTest.test_do_bboxes_intersect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: https://raw.githubusercontent.com/stac-extensions/label/main/examples/multidataset/catalog.json
response:
body:
string: "{\n \"stac_version\": \"1.0.0-rc.1\",\n \"type\": \"Catalog\",\n
\ \"id\": \"label_extension_demo\",\n \"title\": \"label extension demo\",\n
\ \"description\": \"Sample ML training data labels in the STAC format\",\n
\ \"links\": [\n {\n \"rel\": \"root\",\n \"href\": \"./catalog.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"zanzibar/collection.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"spacenet-buildings/collection.json\"\n
\ }\n ]\n}"
headers:
Accept-Ranges:
- bytes
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- max-age=300
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- '236'
Content-Security-Policy:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- text/plain; charset=utf-8
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Tue, 14 May 2024 09:08:52 GMT
ETag:
- W/"acb7a8d6636e24e32f4018c14f1c4ff418a82567b2746560f9eae6ad97a48a54"
Expires:
- Tue, 14 May 2024 09:13:52 GMT
Source-Age:
- '0'
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization,Accept-Encoding,Origin
Via:
- 1.1 varnish
X-Cache:
- HIT
X-Cache-Hits:
- '0'
X-Content-Type-Options:
- nosniff
X-Fastly-Request-ID:
- 676dd71a8ff122cdec17e94a3ab8a088bd54d819
X-Frame-Options:
- deny
X-GitHub-Request-Id:
- D0EE:148AA2:18A7844:1A1CD48:66432132
X-Served-By:
- cache-fra-eddf8230108-FRA
X-Timer:
- S1715677732.487448,VS0,VE143
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
- request:
body: null
headers:
Connection:
- close
Host:
- raw.githubusercontent.com
User-Agent:
- Python-urllib/3.12
method: GET
uri: https://raw.githubusercontent.com/stac-extensions/label/main/examples/multidataset/catalog.json
response:
body:
string: "{\n \"stac_version\": \"1.0.0-rc.1\",\n \"type\": \"Catalog\",\n
\ \"id\": \"label_extension_demo\",\n \"title\": \"label extension demo\",\n
\ \"description\": \"Sample ML training data labels in the STAC format\",\n
\ \"links\": [\n {\n \"rel\": \"root\",\n \"href\": \"./catalog.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"zanzibar/collection.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"spacenet-buildings/collection.json\"\n
\ }\n ]\n}"
headers:
Accept-Ranges:
- bytes
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- max-age=300
Connection:
- close
Content-Length:
- '436'
Content-Security-Policy:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- text/plain; charset=utf-8
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Tue, 14 May 2024 09:08:52 GMT
ETag:
- '"e74ebcbc46d43c5b693ecb995381fbeba03583627e6d65b21ed7678a10d94729"'
Expires:
- Tue, 14 May 2024 09:13:52 GMT
Source-Age:
- '0'
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization,Accept-Encoding,Origin
Via:
- 1.1 varnish
X-Cache:
- MISS
X-Cache-Hits:
- '0'
X-Content-Type-Options:
- nosniff
X-Fastly-Request-ID:
- 36989abd8874aadf2e50450fc56334d4fe7c358e
X-Frame-Options:
- deny
X-GitHub-Request-Id:
- 6A22:312E01:32FCAB4:35F3692:66432A24
X-Served-By:
- cache-fra-eddf8230147-FRA
X-Timer:
- S1715677733.682246,VS0,VE177
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
150 changes: 150 additions & 0 deletions test/cassettes/test_stac/StacTest.test_is_datetime_in_range.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: https://raw.githubusercontent.com/stac-extensions/label/main/examples/multidataset/catalog.json
response:
body:
string: "{\n \"stac_version\": \"1.0.0-rc.1\",\n \"type\": \"Catalog\",\n
\ \"id\": \"label_extension_demo\",\n \"title\": \"label extension demo\",\n
\ \"description\": \"Sample ML training data labels in the STAC format\",\n
\ \"links\": [\n {\n \"rel\": \"root\",\n \"href\": \"./catalog.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"zanzibar/collection.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"spacenet-buildings/collection.json\"\n
\ }\n ]\n}"
headers:
Accept-Ranges:
- bytes
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- max-age=300
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Length:
- '236'
Content-Security-Policy:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- text/plain; charset=utf-8
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Tue, 14 May 2024 09:08:53 GMT
ETag:
- W/"acb7a8d6636e24e32f4018c14f1c4ff418a82567b2746560f9eae6ad97a48a54"
Expires:
- Tue, 14 May 2024 09:13:53 GMT
Source-Age:
- '1'
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization,Accept-Encoding,Origin
Via:
- 1.1 varnish
X-Cache:
- HIT
X-Cache-Hits:
- '1'
X-Content-Type-Options:
- nosniff
X-Fastly-Request-ID:
- 2cbca05f9d22f301c772d1262935378fd999b79a
X-Frame-Options:
- deny
X-GitHub-Request-Id:
- D0EE:148AA2:18A7844:1A1CD48:66432132
X-Served-By:
- cache-fra-eddf8230053-FRA
X-Timer:
- S1715677734.969463,VS0,VE1
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
- request:
body: null
headers:
Connection:
- close
Host:
- raw.githubusercontent.com
User-Agent:
- Python-urllib/3.12
method: GET
uri: https://raw.githubusercontent.com/stac-extensions/label/main/examples/multidataset/catalog.json
response:
body:
string: "{\n \"stac_version\": \"1.0.0-rc.1\",\n \"type\": \"Catalog\",\n
\ \"id\": \"label_extension_demo\",\n \"title\": \"label extension demo\",\n
\ \"description\": \"Sample ML training data labels in the STAC format\",\n
\ \"links\": [\n {\n \"rel\": \"root\",\n \"href\": \"./catalog.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"zanzibar/collection.json\"\n
\ },\n {\n \"rel\": \"child\",\n \"href\": \"spacenet-buildings/collection.json\"\n
\ }\n ]\n}"
headers:
Accept-Ranges:
- bytes
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- max-age=300
Connection:
- close
Content-Length:
- '436'
Content-Security-Policy:
- default-src 'none'; style-src 'unsafe-inline'; sandbox
Content-Type:
- text/plain; charset=utf-8
Cross-Origin-Resource-Policy:
- cross-origin
Date:
- Tue, 14 May 2024 09:08:54 GMT
ETag:
- '"e74ebcbc46d43c5b693ecb995381fbeba03583627e6d65b21ed7678a10d94729"'
Expires:
- Tue, 14 May 2024 09:13:54 GMT
Source-Age:
- '1'
Strict-Transport-Security:
- max-age=31536000
Vary:
- Authorization,Accept-Encoding,Origin
Via:
- 1.1 varnish
X-Cache:
- HIT
X-Cache-Hits:
- '1'
X-Content-Type-Options:
- nosniff
X-Fastly-Request-ID:
- 4d79d1d040b572d5e021147a378a3e58b1c0a14a
X-Frame-Options:
- deny
X-GitHub-Request-Id:
- 6A22:312E01:32FCAB4:35F3692:66432A24
X-Served-By:
- cache-fra-eddf8230034-FRA
X-Timer:
- S1715677734.018500,VS0,VE2
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
5 changes: 3 additions & 2 deletions test/test_opener.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
# SOFTWARE.

import unittest
import pytest

import pytest
from xcube.util.jsonschema import JsonObjectSchema
from xcube_stac.store import StacDataOpener

from xcube_stac.stac import Stac
from xcube_stac.store import StacDataOpener


class StacDataOpenerTest(unittest.TestCase):
Expand Down
Loading

0 comments on commit bc453ed

Please sign in to comment.