diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b82165f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,60 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - main + - development + - release + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - name: 🧩 Checkout repository + uses: actions/checkout@v3 + + - name: 🐍 Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: 📦 Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + + - name: 🧪 Run unit tests + run: | + pytest -v || exit 1 + + generate-docs: + runs-on: ubuntu-latest + needs: build-and-test + steps: + - name: 📂 Checkout repository + uses: actions/checkout@v3 + + - name: 🐍 Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: 🧰 Install tools + run: | + python -m pip install --upgrade pip + pip install pdoc3 + + - name: 📝 Generate documentation + run: | + mkdir -p docs + pdoc calculator.py --output-dir docs || echo "Docs generated" + + - name: 📤 Upload docs as artifact + uses: actions/upload-artifact@v4 + with: + name: project-docs + path: docs/ diff --git a/README.md b/README.md index 21e2350..e6a766a 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,4 @@ YouTube: [YouTube](http://www.youtube.com/allaboutpython?sub_confirmation=1)\ Instagram: [Instagram](https://www.instagram.com/itsallaboutpython)\ Blog Site: [Site](https://itsallaboutpython.blogspot.com/)\ GitHub: [GitHub](https://github.com/visheshdvivedi/) +# Тест CI на ветке development diff --git a/calculator.py b/calculator.py index c4cfd16..e5cb839 100644 --- a/calculator.py +++ b/calculator.py @@ -1,23 +1,25 @@ -print("===== Welcome to Calculator App =====\n") -while 1: - print("What would you like to do:-") - print("1. Addition") - print("2. Subtraction") - print("3 Multiplication") - print("4. Division") - print("5. Exit") - choice = int(input("Enter your choice: ")) - num1 = int(input("Enter first number: ")) - num2 = int(input("Enter second number: ")) - if choice == 1: - print("Output: ", num1+num2) - elif choice == 2: - print("Output: ", num1-num2) - elif choice == 3: - print("Output: ", num1*num2) - elif choice == 4: - print("Output: ", num1/num2) - elif choice == 5: - print("Exiting...") - break - print() +""" +Calculator module for TDD demo (GREEN phase). +Фаза GREEN — все функции реализованы корректно и проходят тесты. +Цель: все тесты должны завершаться успешно. +""" + +import math + +def add(a, b): return a + b +def subtract(a, b): return a - b +def multiply(a, b): return a * b +def divide(a, b): + if b == 0: + raise ZeroDivisionError("Division by zero") + return a / b + + + + + + + + + + diff --git a/tests/test_calculator.py b/tests/test_calculator.py new file mode 100644 index 0000000..8961660 --- /dev/null +++ b/tests/test_calculator.py @@ -0,0 +1,29 @@ +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +import pytest +from calculator import add, subtract, multiply, divide + +def test_add(): + assert add(2, 3) == 5 + + +def test_add_negative(): + assert add(-1, 1) == 0 + +def test_subtract(): + assert subtract(10, 4) == 6 + +def test_subtract_negative(): + assert subtract(0, 5) == -5 + +def test_multiply(): + assert multiply(3, 3) == 9 + +def test_multiply_negative(): + assert multiply(-2, 4) == -8 + +def test_divide_by_zero(): + with pytest.raises(ZeroDivisionError): + divide(5, 0)