Skip to content
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

Ecoscope 197 #245

Merged
merged 36 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4eb921d
test first iteration
davidovichmarcos Aug 5, 2024
493cc53
test pipeline remotely
davidovichmarcos Aug 9, 2024
302d173
Merge branch 'master' into ecoscope-197
davidovichmarcos Aug 9, 2024
407f784
fix indentation
davidovichmarcos Aug 9, 2024
61bc6c8
remove env
davidovichmarcos Aug 9, 2024
cece8c1
adding env var
davidovichmarcos Aug 9, 2024
7bcb4fb
adding var to env
davidovichmarcos Aug 12, 2024
8311989
test workflow directly
davidovichmarcos Aug 12, 2024
2f10c84
test
davidovichmarcos Aug 12, 2024
acad5ee
adding gcloud setup
davidovichmarcos Aug 13, 2024
d3f2fa2
change version
davidovichmarcos Aug 13, 2024
54a7bb7
fixes
davidovichmarcos Aug 13, 2024
dd48af0
moving deps to env file
davidovichmarcos Aug 14, 2024
a380655
test
davidovichmarcos Aug 14, 2024
ca25da1
fixes
davidovichmarcos Aug 14, 2024
b2211f9
Merge branch 'master' into ecoscope-197
davidovichmarcos Aug 14, 2024
921e3e9
skip test for other pipelines
davidovichmarcos Aug 14, 2024
a1e46ca
moving test to another folder
davidovichmarcos Aug 15, 2024
9522c0c
code review applied
davidovichmarcos Aug 16, 2024
614e80b
testing EE env vars
davidovichmarcos Aug 16, 2024
1b8daf1
fix dependency
davidovichmarcos Aug 16, 2024
b4ecb49
fix
davidovichmarcos Aug 16, 2024
0dcae8b
Merge branch 'master' into ecoscope-197
davidovichmarcos Aug 16, 2024
8802e4e
adding fail if EE is not setup
davidovichmarcos Aug 16, 2024
47a9eb5
adding pytest xdist
davidovichmarcos Aug 16, 2024
9337f0d
remove unused import
davidovichmarcos Aug 16, 2024
05d5dc1
rename file
davidovichmarcos Aug 16, 2024
f08bfa7
improve error handling
davidovichmarcos Aug 16, 2024
d346935
polishing code
davidovichmarcos Aug 16, 2024
56e985d
Update requirements-notebooks-test.txt
davidovichmarcos Aug 16, 2024
911b86d
fix error type
davidovichmarcos Aug 16, 2024
1922120
Merge remote-tracking branch 'origin/ecoscope-197' into ecoscope-197
davidovichmarcos Aug 16, 2024
c511f1a
adding errors
davidovichmarcos Aug 16, 2024
6a31d60
fixes
davidovichmarcos Aug 16, 2024
7f2136d
fix
davidovichmarcos Aug 16, 2024
6788e6c
fix
davidovichmarcos Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
pytest -v -r s --color=yes --cov=ecoscope --cov-append --cov-report=xml

- name: Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4
35 changes: 35 additions & 0 deletions .github/workflows/nb_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run notebook tests
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "*" ]
env:
ER_USERNAME: ${{ secrets.ER_USERNAME }}
ER_PASSWORD: ${{ secrets.ER_PASSWORD }}
EE_ACCOUNT: ${{ secrets.EE_ACCOUNT }}
EE_PRIVATE_KEY_DATA: ${{ secrets.EE_PRIVATE_KEY_DATA }}


jobs:
run_unit_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install pip
run: python -m ensurepip --upgrade
- name: Install dependencies
run: pip install -r requirements-notebooks-test.txt
- name: Use the kernel
run: python -m ipykernel install --user --name=venv
- name: Run unit tests
run: pytest -n auto nb-tests/test_notebooks.py -s
env:
ER_USERNAME: ${{ secrets.ER_USERNAME }}
ER_PASSWORD: ${{ secrets.ER_PASSWORD }}
EE_ACCOUNT: ${{ secrets.EE_ACCOUNT }}
EE_PRIVATE_KEY_DATA: ${{ secrets.EE_PRIVATE_KEY_DATA }}
60 changes: 60 additions & 0 deletions nb-tests/test_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import re
import pathlib
from dataclasses import dataclass
import ee
import papermill
import pytest

try:
EE_ACCOUNT = os.getenv("EE_ACCOUNT")
EE_PRIVATE_KEY_DATA = os.getenv("EE_PRIVATE_KEY_DATA")
if EE_ACCOUNT and EE_PRIVATE_KEY_DATA:
ee.Initialize(credentials=ee.ServiceAccountCredentials(EE_ACCOUNT, key_data=EE_PRIVATE_KEY_DATA))
except Exception:
raise ValueError("Earth Engine can not be initialized. Failing notebook tests")

NB_DIR = pathlib.Path(__file__).parent.parent / "doc" / "source" / "notebooks"

KNOWN_ERRORS_REGEXES = { # This is basically a GitHub ticket queue
"EarthRanger_IO.ipynb": "Series found",
"Relocations_and_Trajectories.ipynb": "No module named 'branca'",
"EcoGraph.ipynb": "not a zip file",
"EcoPlot.ipynb": "not a zip file",
"Landscape Grid.ipynb": "No module named 'branca'",
"Seasonal Calculation.ipynb": "No module named 'branca'",
"Tracking Data Gantt Chart.ipynb": "Bad CRC-32 for file 'er_relocs.csv.zip'",
"Remote Sensing Time Series Anomaly.ipynb": "No module named 'branca'",
"Reduce Regions.ipynb": "No module named 'branca'",
"Landscape Dynamics Data.ipynb": "No module named 'branca'",
}


@dataclass
class Notebook:
path: pathlib.Path
raises: bool = False
raises_match: str = None


ALL_NOTEBOOKS = [
Notebook(
path=p,
raises=False if p.name not in KNOWN_ERRORS_REGEXES else True,
raises_match=KNOWN_ERRORS_REGEXES.get(p.name),
)
for p in NB_DIR.rglob("*.ipynb")
]


@pytest.mark.parametrize(
"notebook",
ALL_NOTEBOOKS,
ids=[nb.path.name for nb in ALL_NOTEBOOKS],
)
def test_notebooks(notebook: Notebook):
if notebook.raises: # these are the ones we expect to raise errors
with pytest.raises(Exception, match=re.escape(notebook.raises_match)):
papermill.execute_notebook(str(notebook.path), "./output.ipynb", kernel_name="venv")
pytest.xfail(f"Notebook {notebook.path} is known to fail with error {notebook.raises_match}")
papermill.execute_notebook(str(notebook.path), "./output.ipynb", kernel_name="venv")
6 changes: 6 additions & 0 deletions requirements-notebooks-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pip-tools
pytest
papermill
.[all]
ipykernel
pytest-xdist
Loading