Skip to content

Commit

Permalink
Merge pull request #1 from ukaea/james/ci
Browse files Browse the repository at this point in the history
James/ci
  • Loading branch information
samueljackson92 committed Aug 12, 2024
2 parents 00e795b + 2088113 commit 2872c18
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI
on: [ pull_request ]

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up environment
run: |
git lfs fetch && git lfs pull
sudo apt update && sudo apt install -y libopenmpi-dev
pip install uv
uv venv venv
source venv/bin/activate
uv pip install -r requirements.txt
uv pip install --upgrade --force-reinstall "numpy<2.0"
- name: Run tests
run: |
source venv/bin/activate
python -m pytest -rsx tests/
ruff-code-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
6 changes: 2 additions & 4 deletions src/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def __init__(

def __call__(self, shot: int):
self.data_dir.mkdir(exist_ok=True, parents=True)
local_path = self.data_dir / f"{shot}.{self.file_format}"


create = CreateDatasetTask(
self.metadata_dir,
Expand All @@ -123,7 +121,8 @@ def __call__(self, shot: int):
try:
create()
except Exception as e:
import traceback; traceback.print_exc();
import traceback
traceback.print_exc()
print(traceback.format_exc())
logging.error(f"Failed to run workflow with error {type(e)}: {e}")

Expand All @@ -145,7 +144,6 @@ def run_workflows(self, shot_list: list[int], parallel=True):
def _run_workflows_serial(self, shot_list: list[int]):
n = len(shot_list)
for i, shot in enumerate(shot_list):
result = self.workflow(shot)
logging.info(f"Done shot {i+1}/{n} = {(i+1)/n*100:.2f}%")

def _run_workflows_parallel(self, shot_list: list[int]):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import pytest

pyuda_import = pytest.importorskip("pyuda")
from src.archive.reader import ( # noqa: E402
from src.reader import ( # noqa: E402
DatasetReader, # noqa: E402
SignalMetadataReader, # noqa: E402
SourceMetadataReader, # noqa: E402
) # noqa: E402


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_list_signals():
shot = 30420
reader = DatasetReader(shot)
Expand All @@ -22,7 +22,7 @@ def test_list_signals():
info = signals[0]
assert info.name == "abm/calib_shot"


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_list_signals_exclude_raw():
shot = 30420
reader = DatasetReader(shot)
Expand All @@ -34,7 +34,7 @@ def test_list_signals_exclude_raw():
info = signals[0]
assert info.name == "abm/calib_shot"


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_read_signal():
shot = 30420
reader = DatasetReader(shot)
Expand All @@ -47,7 +47,7 @@ def test_read_signal():
assert dataset.attrs["name"] == "abm/calib_shot"
assert dataset["time"].shape == (1,)


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_read_image():
shot = 30420
reader = DatasetReader(shot)
Expand All @@ -64,15 +64,15 @@ def test_read_image():
assert dataset["data"].shape == (186, 912, 768)
assert list(dataset.dims.keys()) == ["time", "height", "width"]


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_read_signals_metadata():
shot = 30420
reader = SignalMetadataReader(shot)
df = reader.read_metadata()

assert isinstance(df, pd.DataFrame)


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_read_sources_metadata():
shot = 30420
reader = SourceMetadataReader(shot)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import zarr
import xarray as xr
import subprocess
from src.archive.uploader import UploadConfig
from src.uploader import UploadConfig
from pathlib import Path
import os
import pytest

pyuda_import = pytest.importorskip("pyuda")
from src.archive.writer import DatasetWriter # noqa: E402
from src.archive.task import ( # noqa: E402
from src.writer import DatasetWriter # noqa: E402
from src.task import ( # noqa: E402
CreateDatasetTask, # noqa: E402
CleanupDatasetTask, # noqa: E402
UploadDatasetTask, # noqa: E402
CreateSourceMetadataTask, # noqa: E402
CreateSignalMetadataTask, # noqa: E402
) # noqa: E402


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_create_dataset_task(tmpdir, mocker):
metadata_dir = tmpdir / "uda"
shot = 30420
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_create_dataset_task(tmpdir, mocker):
ds = xr.open_zarr(dataset_path, group="abm")
assert len(ds.data_vars) == 3


@pytest.mark.skip(reason="Pyuda client unavailable")
@pytest.mark.usefixtures("fake_dataset")
def test_write_cleanup(tmpdir, fake_dataset):
shot = 30420
Expand All @@ -59,7 +59,7 @@ def test_write_cleanup(tmpdir, fake_dataset):
task()
assert not writer.dataset_path.exists()


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_upload_dataset(mocker):
mocker.patch("subprocess.run")

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_upload_dataset(mocker):
env=env,
)


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_source_metadata_reader(tmpdir):
shot = 30420
task = CreateSourceMetadataTask(data_dir=tmpdir, shot=shot)
Expand All @@ -104,7 +104,7 @@ def test_source_metadata_reader(tmpdir):
df = pd.read_parquet(path)
assert isinstance(df, pd.DataFrame)


@pytest.mark.skip(reason="Pyuda client unavailable")
def test_signal_metadata_reader(tmpdir):
shot = 30420
task = CreateSignalMetadataTask(data_dir=tmpdir, shot=shot)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import xarray as xr
from src.archive.transforms import (
from src.transforms import (
AddXSXCameraParams,
DropDatasets,
DropZeroDimensions,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import zarr
import xarray as xr
from src.archive.writer import DatasetWriter
from src.writer import DatasetWriter

pyuda_import = pytest.importorskip("pyuda")

Expand Down

0 comments on commit 2872c18

Please sign in to comment.