Skip to content

Commit

Permalink
feat: test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed Jun 24, 2024
1 parent f5cb904 commit 8e62292
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build
# To test with act: gh act --secret-file $ENV_FILE --workflows .github/workflows/unit.yml
on:
push:
branches:
- main
pull_request:

env:
EARTHENGINE_TOKEN: ${{ secrets.EARTHENGINE_TOKEN }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.10
- name: Install sepal_ui
run: python -m pip install "git+https://github.com/12rambau/sepal_ui.git@sepal_pre_release"
- name: Build with sepal_ui venv
run: module_venv
- name: Install nox
run: python -m pip install nox
- name: set entry point and run tests
run: |
cp ui.ipynb test_ui.ipynb
entry_point --test test_ui.ipynb
nox -s test_ui
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
*nox_ui.ipynb

# C extensions
*.so
Expand Down
2 changes: 2 additions & 0 deletions component/tile/viz_tile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sepal_ui import sepalwidgets as sw
from sepal_ui import mapping as sm
from sepal_ui.mapping.inspector_control import InspectorControl
from sepal_ui.scripts import utils as su
import ipyvuetify as v

Expand Down Expand Up @@ -36,6 +37,7 @@ def __init__(self, model, aoi_model):

# create a map
self.m = sm.SepalMap()
self.m.add_control(InspectorControl(self.m))
self.m.layout.height = "80vh"

legend_dict = dict(zip(cp.gfc_labels, cp.hex_palette))
Expand Down
72 changes: 72 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""All the process that can be run using nox.
The nox run are build in isolated environment that will be stored in .nox. to force the venv update, remove the .nox/xxx folder.
"""

from pathlib import Path
from pathlib import Path
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from jupyter_client.kernelspec import KernelSpecManager
import nox


@nox.session(reuse_venv=True)
def lint(session):
"""Apply the pre-commits."""
session.install("pre-commit")
session.run("pre-commit", "run", "--a", *session.posargs)


@nox.session(reuse_venv=True)
def app(session):
"""Run the application."""

entry_point = str(Path("ui.ipynb"))

# Duplicate the entry point file
session.run("cp", entry_point, "nox_ui.ipynb")

# change the kernel name in the entry point
session.run("entry_point", "--test", "nox_ui.ipynb")

session.run("jupyter", "trust", entry_point)
session.run(
"voila", "--show_tracebacks=True", "--template=sepal-ui-base", "nox_ui.ipynb"
)


@nox.session()
def test_ui():
"""Run the application."""

ksm = KernelSpecManager()
kernel_names = list(ksm.get_all_specs())
print(kernel_names)

# get the current path
root_folder = Path(__file__).parent.parent

test_notebooks = [root_folder / "test_ui.ipynb"]

for notebook in test_notebooks:
with open(notebook) as ff:
nb_in = nbformat.read(ff, nbformat.NO_CONVERT)

print("Running notebook", notebook)

try:
ep = ExecutePreprocessor(timeout=600, kernel_name="test-se.plan")

nb_out = ep.preprocess(nb_in)
except Exception as e:
print("########### Error running notebook", notebook)
raise e


@nox.session(reuse_venv=True)
def jupyter(session):
"""Run the application."""
session.install("-r", "requirements.txt")
session.run("jupyter", "trust", "no_ui.ipynb")
session.run("jupyter", "notebook", "no_ui.ipynb")
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ bqplot
matplotlib
numpy
pandas
# pin until sepal releases a new version and latest ipyvuetify version is installed
ipyvuetify==1.8.10


# build with latest sepal_ui release
1 change: 1 addition & 0 deletions ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
],
"metadata": {
"kernelspec": {
"title": "Global Forest Change module",
"display_name": " (venv) gfc_wrapper_python",
"language": "python",
"name": "venv-gfc_wrapper_python"
Expand Down

0 comments on commit 8e62292

Please sign in to comment.