From 7e80f01551a89116c5de79b108abcfe09c0856f6 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Tue, 1 Oct 2024 16:40:50 -0500 Subject: [PATCH] fix: run wrapper in CI --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ .gitignore | 2 ++ app/__init__.py | 0 app/calculator.py | 15 +++++++++++++++ app/requirements.txt | 1 + app/test_calculator.py | 31 +++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 app/__init__.py create mode 100644 app/calculator.py create mode 100644 app/requirements.txt create mode 100644 app/test_calculator.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9c4d687 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,21 @@ +name: Workflow for Codecov wrapper +on: [push, pull_request] +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install dependencies + run: pip install -r app/requirements.txt + - name: Run tests and collect coverage + run: pytest --cov app ${{ env.CODECOV_ATS_TESTS }} + - name: Upload coverage to Codecov + run: ./run.sh + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6910834 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +.py[oc] diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/calculator.py b/app/calculator.py new file mode 100644 index 0000000..8a976b2 --- /dev/null +++ b/app/calculator.py @@ -0,0 +1,15 @@ +class Calculator: + + def add(x, y): + return x + y + + def subtract(x, y): + return x - y + + def multiply(x, y): + return x * y + + def divide(x, y): + if y == 0: + return 'Cannot divide by 0' + return x * 1.0 / y diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..c75c448 --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1 @@ +pytest-cov diff --git a/app/test_calculator.py b/app/test_calculator.py new file mode 100644 index 0000000..f564193 --- /dev/null +++ b/app/test_calculator.py @@ -0,0 +1,31 @@ +from .calculator import Calculator + + +def test_add(): + assert Calculator.add(1, 2) == 3.0 + assert Calculator.add(1.0, 2.0) == 3.0 + assert Calculator.add(0, 2.0) == 2.0 + assert Calculator.add(2.0, 0) == 2.0 + assert Calculator.add(-4, 2.0) == -2.0 + +def test_subtract(): + assert Calculator.subtract(1, 2) == -1.0 + assert Calculator.subtract(2, 1) == 1.0 + assert Calculator.subtract(1.0, 2.0) == -1.0 + assert Calculator.subtract(0, 2.0) == -2.0 + assert Calculator.subtract(2.0, 0.0) == 2.0 + assert Calculator.subtract(-4, 2.0) == -6.0 + +def test_multiply(): + assert Calculator.multiply(1, 2) == 2.0 + assert Calculator.multiply(1.0, 2.0) == 2.0 + assert Calculator.multiply(0, 2.0) == 0.0 + assert Calculator.multiply(2.0, 0.0) == 0.0 + assert Calculator.multiply(-4, 2.0) == -8.0 + +def test_divide(): + # assert Calculator.divide(1, 2) == 0.5 + assert Calculator.divide(1.0, 2.0) == 0.5 + assert Calculator.divide(0, 2.0) == 0 + assert Calculator.divide(-4, 2.0) == -2.0 + # assert Calculator.divide(2.0, 0.0) == 'Cannot divide by 0'