Skip to content

Commit

Permalink
Fix CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
daklauss authored and schmoelder committed Jul 30, 2024
1 parent 8a4867f commit 112dadf
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 5 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: pipeline

on:
push:
branches:
- master
- dev
- add-dead-end-filtration
- test_ci
pull_request:


jobs:
test-job:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

env:
CONDA_FILE: environment.yml

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

- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
activate-environment: cadpythonsim
channels: conda-forge,

- name: install conda env
run: |
mamba env update -n cadpythonsim -f ${{ env.CONDA_FILE }}
- name: Install
run: |
python -m pip install --upgrade pip
pip install -e ./[testing]
- name: Test
run: |
pytest
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: ruff

name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
debug*
*.h5
*.egg-info
.vscode
Binary file added environment.yml
Binary file not shown.
120 changes: 115 additions & 5 deletions tests/test_residual.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import pytest
import numpy as np

"""
q_in q_out, was sind physikalisch sinnvolle szenarien
"""

TestCaseConc = {
# random number test
TestCaseConc_level1 = {
"values" : {
"c" : np.array([1, 2, 3]),
"c_dot" : np.array([4, 5, 6]),
Expand All @@ -19,25 +23,84 @@
"expected" : np.array([-11,-7,-3])
}

# flow in and out are equal, concentrations to
TestCaseConc_equal = {
"values" : {
"c" : np.array([0.1,]),
"c_dot" : np.array([0,]),
"V" : 1,
"V_dot" : 0,
"Q_in" : 1,
"Q_out" : 1,
"c_in" : np.array([0.1,])
},
"expected" : np.array([0,])
}

# flow in and out are equal, but concentrations going into the unit is not
TestCaseConc_diffcin = {
"values" : {
"c" : np.array([0.1,]),
"c_dot" : np.array([0,]),
"V" : 1.0,
"V_dot" : 0.0,
"Q_in" : 1.0,
"Q_out" : 1.0,
"c_in" : np.array([0.2,])
},
"expected" : np.array([-0.1,])
}

#flow in and out are not equal, concentrantions going in are
TestCaseConc_diffvol = {
"values" : {
"c" : np.array([0.1,]),
"c_dot" : np.array([0,]),
"V" : 1.0,
"V_dot" : 1.0,
"Q_in" : 2.0,
"Q_out" : 1.0,
"c_in" : np.array([0.1,])
},
"expected" : np.array([0,])
}

#flow in and out are not, equal, concentrations aren't equal too
TestCaseConc_diffvolc = {
"values" : {
"c" : np.array([0.1,]),
"c_dot" : np.array([0.2,]),
"V" : 1.0,
"V_dot" : 1.0,
"Q_in" : 2.0,
"Q_out" : 1.0,
"c_in" : np.array([0.2,])
},
"expected" : np.array([0,])
}


@pytest.mark.parametrize(
"parameters",
[
TestCaseConc
TestCaseConc_level1,
TestCaseConc_equal,
TestCaseConc_diffcin,
TestCaseConc_diffvol,
TestCaseConc_diffvolc
]
)
class TestResidualConcCSTR():
def test_calculation_concentration_cstr(self, parameters):

param_vec_conc = parameters["values"].values()

np.testing.assert_equal(calculate_residual_concentration_cstr(*param_vec_conc), parameters["expected"])

np.testing.assert_array_almost_equal(calculate_residual_concentration_cstr(*param_vec_conc), parameters["expected"])




# random number test
TestCaseVol = {
"values" : {
"V" : 1,
Expand All @@ -48,12 +111,59 @@ def test_calculation_concentration_cstr(self, parameters):
"expected" : 3
}

# Flow in and out are equal
TestCaseVol_equal = {
"values" : {
"V" : 1,
"V_dot" : 0,
"Q_in" : 1,
"Q_out" : 1,
},
"expected" : 0
}

# Flow in is larger than out
TestCaseVol_inge = {
"values" : {
"V" : 1,
"V_dot" : 1,
"Q_in" : 2,
"Q_out" : 1,
},
"expected" : 0
}

# Flow in is lesser than out
TestCaseVol_inle = {
"values" : {
"V" : 1,
"V_dot" : -1,
"Q_in" : 1,
"Q_out" : 2,
},
"expected" : 0
}

# Residual does not depend on Volumne

TestCaseVol_vol = {
"values" : {
"V" : 1e10,
"V_dot" : 0,
"Q_in" : 0,
"Q_out" : 0,
},
"expected" : 0
}

@pytest.mark.parametrize(
"parameters",
[
TestCaseVol
TestCaseVol,
TestCaseVol_equal,
TestCaseVol_inge,
TestCaseVol_inle,
TestCaseVol_vol
]
)

Expand Down

0 comments on commit 112dadf

Please sign in to comment.