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

ci: adding testing [demo] #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 48 additions & 0 deletions .github/workflows/ci-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI testing

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on: # Trigger the workflow on push or pull request, but only for the main branch
push:
branches: [master, main]
pull_request:
branches: [master, main]

defaults:
run:
shell: bash

jobs:
pytest:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, macOS-11, windows-latest]
python-version: ["3.8"]

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
env:
TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html"

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

- name: Get pip cache dir
id: pip-cache
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: Cache pip
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ hashFiles('setup.py') }}
restore-keys: pip-

- name: Tests
run: python setup.py test
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name = "SRMRpy",
version = "1.0",
version = "1.0.0",
packages = find_packages(),

install_requires = [
Expand Down
11 changes: 6 additions & 5 deletions test/test_srmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# This file is part of the SRMRpy library, and is licensed under the
# MIT license: https://github.com/jfsantos/SRMRpy/blob/master/LICENSE
import os.path

from srmrpy import srmr
from scipy.io.matlab import loadmat
Expand All @@ -11,22 +12,22 @@
fs = 16000
s = loadmat("test/test.mat")["s"][:,0]

correct_ratios = loadmat("test/correct_ratios.mat")['correct_ratios'][0]
correct_ratios = loadmat(os.path.join("test", "correct_ratios.mat"))['correct_ratios'][0]


def test_srmr():
ratio, avg_energy = srmr(s, fs)
assert np.allclose(ratio, correct_ratios[1], rtol=1e-6, atol=1e-12)
assert np.allclose(ratio, correct_ratios[1], rtol=1e-6, atol=1e-12), np.max(np.abs(ratio - correct_ratios[1]))

def test_srmr_fast():
ratio_norm_fast, avg_energy_norm_fast = srmr(s, fs, fast=True, norm=True, max_cf=30)
assert np.allclose(ratio_norm_fast, correct_ratios[2], rtol=1e-6, atol=1e-12)
assert np.allclose(ratio_norm_fast, correct_ratios[2], rtol=1e-6, atol=1e-12), np.max(np.abs(ratio_norm_fast - correct_ratios[2]))

def test_srmr_slow():
ratio_slow, avg_energy_slow = srmr(s, fs, fast=False)
assert np.allclose(ratio_slow, correct_ratios[0], rtol=1e-6, atol=1e-12)
assert np.allclose(ratio_slow, correct_ratios[0], rtol=1e-6, atol=1e-12), np.max(np.abs(ratio_slow - correct_ratios[0]))

def test_srmr_slow_norm():
ratio_norm, avg_energy_norm = srmr(s, fs, fast=False, norm=True, max_cf=30)
assert np.allclose(ratio_norm, correct_ratios[3], rtol=1e-6, atol=1e-12)
assert np.allclose(ratio_norm, correct_ratios[3], rtol=1e-6, atol=1e-12), np.max(np.abs(ratio_norm - correct_ratios[3]))