diff --git a/.github/workflows/ci_cd_wf.yml b/.github/workflows/ci_cd_wf.yml new file mode 100644 index 00000000..d853a685 --- /dev/null +++ b/.github/workflows/ci_cd_wf.yml @@ -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 }} + + \ No newline at end of file diff --git a/calculator.py b/calculator.py index feefb4e3..56954a6d 100644 --- a/calculator.py +++ b/calculator.py @@ -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)) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 222e40bb..16de5660 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ packaging==23.1 pluggy==1.0.0 pytest==7.3.1 tomli==2.0.1 +pytest-cov==4.1.0 + diff --git a/tests/test_calculator.py b/tests/test_calculator.py index e69de29b..aeae4a4d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -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 \ No newline at end of file