diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..0b9a44b Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7b1425a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI Pipeline + +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install pytest flake8 coverage + + - name: Lint code + run: flake8 . + + - name: Run tests + run: pytest + + - name: Run coverage + run: | + coverage run -m pytest + coverage report \ No newline at end of file diff --git a/calculator/__init__.py b/calculator/__init__.py index 871f6fd..3891761 100644 --- a/calculator/__init__.py +++ b/calculator/__init__.py @@ -1 +1 @@ -from .calculator import Calculator +from .calculator import Calculator # noqa: F401 diff --git a/calculator/calculator.py b/calculator/calculator.py index 934990d..d907f13 100644 --- a/calculator/calculator.py +++ b/calculator/calculator.py @@ -3,7 +3,8 @@ class Calculator: - """Calculator class with methods to sum, subtract, multiply, divide square and find square root""" + """Calculator class with methods to sum, subtract, multiply, +divide, square, and find square root.""" def __init__(self, memory=0): self.memory = memory @@ -28,12 +29,12 @@ def sum(self, a, b=None): """ try: - if b == None: + if b is None: b = self.memory self.memory = float(a) + float(b) return self.memory - except: + except Exception: return 'Invalid input' def subtract(self, a, b=None): @@ -49,13 +50,13 @@ def subtract(self, a, b=None): """ try: - if b == None: + if b is None: b = a a = self.memory self.memory = float(a) - float(b) return self.memory - except: + except Exception: return 'Invalid input' def multiply(self, a, b=None): @@ -71,12 +72,12 @@ def multiply(self, a, b=None): """ try: - if b == None: + if b is None: b = self.memory self.memory = float(a) * float(b) return self.memory - except: + except Exception: return 'Invalid input' def divide(self, a, b=None): @@ -92,7 +93,7 @@ def divide(self, a, b=None): """ try: - if b == None: + if b is None: b = a a = self.memory @@ -100,7 +101,7 @@ def divide(self, a, b=None): return self.memory except ZeroDivisionError: return 'Can not divide by zero.' - except: + except Exception: return 'Invalid input' def square(self, a=None): @@ -115,12 +116,12 @@ def square(self, a=None): """ try: - if a == None: + if a is None: a = self.memory self.memory = float(a) ** 2 return self.memory - except: + except Exception: return 'Invalid input' def sqrt(self, a=None): @@ -135,10 +136,10 @@ def sqrt(self, a=None): """ try: - if a == None: + if a is None: a = self.memory self.memory = math.sqrt(float(a)) return self.memory - except: + except Exception: return 'Invalid input' diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 1a2d7b6..84f283f 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,5 +1,3 @@ -import pytest - from calculator.calculator import Calculator c = Calculator()