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

automated testing implementation #8

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
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
40 changes: 40 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
cd test
pytest test_testing.py
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/__pycache__
*/__pycache__
.vscode
4 changes: 2 additions & 2 deletions heatpathcal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse, os, sys
sys.path.append(os.path.abspath(str(os.getcwd())+"/src"))
import fileio, calculation
sys.path.append("./src")
import calculation, fileio

#command line parsing
Parser=argparse.ArgumentParser(description="Calculates the total resistance for given heat paths")
Expand Down
2 changes: 1 addition & 1 deletion info/input_file_guideline.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ If a heat path *travels through multiple paths*, keep them **on the same row**:\

**If no length was given**, by default, **use 1**.

For example files, please look in the [test directory](../test/) in this repository.
For example files, please look in the [sample directory](../sample/) in this repository.
File renamed without changes.
File renamed without changes.
Empty file added src/__init__.py
Empty file.
8 changes: 5 additions & 3 deletions src/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
May also be used to calculate contact resistance
"""
def rec_cs(k, A, L = 1):
return L/(k*A)
if (L == 0):
return abs(1/(k*A))
return abs(L/(k*A))

"""
Compute material resistance for cylindrical cross section
"""
def cyl_cs(k, r1, r2, L):
return (log(r1/r2))/(2*pi*L*k)
return abs((log(r1/r2))/(2*pi*L*k))

"""
Compute material resistance for sphereical object
"""
def sph(k, r1, r2):
return (r2-r1)/(4*pi*r2*r1*k)
return abs((r2-r1)/(4*pi*r2*r1*k))
15 changes: 15 additions & 0 deletions test/test_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
sys.path.append("../src")
import calculation, fileio, formula, structure

def test_rec_cs_regular():
assert formula.rec_cs(3, 5, 0.5) == 1/30

def test_rec_cs_nothird():
assert formula.rec_cs(3, 5) == 1/15

def test_rec_cs_zero():
assert formula.rec_cs(3, 5, 0) == 1/15

def test_rec_cs_negative():
assert formula.rec_cs(3, -5, 0.5) == 1/30
Loading