diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..7981386 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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 diff --git a/.gitignore b/.gitignore index 550d67d..5371a01 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -src/__pycache__ +*/__pycache__ +.vscode \ No newline at end of file diff --git a/heatpathcal.py b/heatpathcal.py index 6879a4a..da8f2d6 100644 --- a/heatpathcal.py +++ b/heatpathcal.py @@ -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") diff --git a/info/input_file_guideline.md b/info/input_file_guideline.md index 721fd17..a40648a 100644 --- a/info/input_file_guideline.md +++ b/info/input_file_guideline.md @@ -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. \ No newline at end of file +For example files, please look in the [sample directory](../sample/) in this repository. \ No newline at end of file diff --git a/test/high/battery_support_bracket_to_panel.csv b/sample/high/battery_support_bracket_to_panel.csv similarity index 100% rename from test/high/battery_support_bracket_to_panel.csv rename to sample/high/battery_support_bracket_to_panel.csv diff --git a/test/high/negz_xy_panels.csv b/sample/high/negz_xy_panels.csv similarity index 100% rename from test/high/negz_xy_panels.csv rename to sample/high/negz_xy_panels.csv diff --git a/test/high/rail_to_xy_panel.csv b/sample/high/rail_to_xy_panel.csv similarity index 100% rename from test/high/rail_to_xy_panel.csv rename to sample/high/rail_to_xy_panel.csv diff --git a/test/low/battery_top_bracket_to_eps.csv b/sample/low/battery_top_bracket_to_eps.csv similarity index 100% rename from test/low/battery_top_bracket_to_eps.csv rename to sample/low/battery_top_bracket_to_eps.csv diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/formula.py b/src/formula.py index 0c621cc..b047eb8 100644 --- a/src/formula.py +++ b/src/formula.py @@ -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)) diff --git a/test/test_testing.py b/test/test_testing.py new file mode 100644 index 0000000..878205e --- /dev/null +++ b/test/test_testing.py @@ -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 \ No newline at end of file