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

Fix ci testing #72

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 40 additions & 8 deletions .github/workflows/workflows.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
name: Python package
name: Run tests

on: [push]

env:
pytest_cpus: 2 # How many cpu cores will be used to run tests
pytest_cov_dir: 'dgmr' # The directory that pytest-cov will look at the coverage

jobs:
call-run-python-tests:
uses: openclimatefix/.github/.github/workflows/python-test.yml@main
with:
# 0 means don't use pytest-xdist
pytest_numcpus: "2"
# pytest-cov looks at this folder
pytest_cov_dir: "dgmr"
run-python-tests:
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"] # The python versions to run tests on
os: ["ubuntu-latest", "macos-latest"] # The os's to run tests on

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/requirements.txt

- name: Run tests
run: |
pytest -n $pytest_cpus --cov-report=xml --cov=$pytest_cov_dir

- name: Report coverage
run: |
coverage report -m

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: false
4 changes: 4 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest
pytest-xdist
coverage
pytest-cov
8 changes: 8 additions & 0 deletions tests/test_losses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
""" Test loss functions"""

import os
import sys

sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
)

from dgmr.losses import SSIMLoss, MS_SSIMLoss, SSIMLossDynamic, tv_loss
import torch

Expand Down
7 changes: 7 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import os
import sys

sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
)

import torch
import torch.nn.functional as F
from dgmr import (
Expand Down