diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..7820094 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,46 @@ +# 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 + pull-requests: write + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - 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 pytest-cov + 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 and calculate coverage + run: | + pytest --cov-report "xml:coverage.xml" --cov=. + - name: Create Coverage + if: ${{ github.event_name == 'pull_request' }} + uses: orgoro/coverage@v3 + with: + coverageFile: coverage.xml + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/__pycache__/functions.cpython-312.pyc b/__pycache__/functions.cpython-312.pyc new file mode 100644 index 0000000..24a0e57 Binary files /dev/null and b/__pycache__/functions.cpython-312.pyc differ diff --git a/__pycache__/test_functions.cpython-312-pytest-8.3.2.pyc b/__pycache__/test_functions.cpython-312-pytest-8.3.2.pyc new file mode 100644 index 0000000..d073533 Binary files /dev/null and b/__pycache__/test_functions.cpython-312-pytest-8.3.2.pyc differ diff --git a/functions.py b/functions.py index 7cdbb28..a6481f0 100644 --- a/functions.py +++ b/functions.py @@ -3,7 +3,7 @@ def add(a, b): def subtract(a, b): - return a + b + return a - b def multiply(a, b): @@ -11,4 +11,6 @@ def multiply(a, b): def convert_fahrenheit_to_celsius(fahrenheit): - return multiply(subtract(fahrenheit, 32), 9 / 5) + if fahrenheit < -459.67: + raise AssertionError("Temperature below absolute zero is not possible.") + return multiply(subtract(fahrenheit, 32), 5 / 9) diff --git a/test_functions.py b/test_functions.py index ffd7a65..cf4f2b9 100644 --- a/test_functions.py +++ b/test_functions.py @@ -8,12 +8,12 @@ def test_add(): assert add("space", "ship") == "spaceship" -# def test_subtract(): -# assert subtract(3,2) == 1 +def test_subtract(): + assert subtract(3,2) == 1 -# def test_convert_fahrenheit_to_celsius(): -# assert f2c(32) == 0 -# assert f2c(122) == pytest.approx(50) -# with pytest.raises(AssertionError): -# f2c(-600) +def test_convert_fahrenheit_to_celsius(): + assert f2c(32) == 0 + assert f2c(122) == pytest.approx(50) + with pytest.raises(AssertionError): + f2c(-600)