Skip to content
Open
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
56 changes: 56 additions & 0 deletions .github/workflows/ci_cd_wf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: test

on:
push:
branches:
- main
pull_request:
branches:
- "*"

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Check out repo code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.x"

- name: Install Dependencies
run: |
python -m pip install -r requirements.txt

- name: Run tests
run: |
python -m pytest -v tests

- name: Run tests and generate coverage report
run: |
python3 -m pytest --cov=./ --cov-report=xml \
--verbose \
--color=yes \
tests/

# Upload generated XML formatted coverage report artifact which will be later referenced by comment section on PRs

# Arguments like path, retention_days etc could differ based on your needs.
- name: Upload coverage report to GitHub
uses: actions/upload-artifact@v2.2.4
with:
name: coverage-report
path: ./coverage.xml

# Check if current job is running in the context of a pull request and whether it was triggered by PR event or not.
# If yes, then add comment on that PR providing details about code coverage information.

- name: Comment on Pull Request with coverage report
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}


2 changes: 1 addition & 1 deletion calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def div(a, b):
print("Sum of " + str(a) + " and " + str(b) + " is ", add(a, b))
print("Difference of " + str(a) + " and " + str(b) + " is ", sub(a, b))
print("Product of " + str(a) + " and " + str(b) + " is ", mul(a, b))
print("Division of " + str(a) + " and " + str(b) + " is ", div(a, b))
print("Division of " + str(a) + " and " + str(b) + " is ", div(a, b))
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ packaging==23.1
pluggy==1.0.0
pytest==7.3.1
tomli==2.0.1
pytest-cov==4.1.0

17 changes: 17 additions & 0 deletions tests/test_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from calculator import add, div, mul, sub


def test_add():
assert add(1, 1) == 2


def test_sub():
assert sub(1, 1) == 0


def test_mul():
assert mul(1, 1) == 1


def test_div():
assert div(2, 1) == 2