diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml new file mode 100644 index 00000000..f6b808c5 --- /dev/null +++ b/.github/workflows/api.yml @@ -0,0 +1,19 @@ +name: API workflow + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + name: Test python API + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v2 + with: + python-version: '3.11' + - name: Install requirements + run: pip install -r api/requirements.txt + - name: Run tests and collect coverage + run: pytest --cov + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@v3 \ No newline at end of file diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml new file mode 100644 index 00000000..106030aa --- /dev/null +++ b/.github/workflows/config.yml @@ -0,0 +1,24 @@ + version: 2.1 + + orbs: + codecov: codecov/codecov@3.2.2 + + jobs: + test-api: + docker: + - image: cimg/python:3.10.2 + steps: + - checkout + - run: + name: Install requirements + command: pip install -r api/requirements.txt + - run: + name: Run tests and collect coverage + command: pytest --cov api.calculator + - codecov/upload + + workflows: + version: 2.1 + build-test: + jobs: + - test-api \ No newline at end of file diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 00000000..9d0d7dc1 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,11 @@ + steps: + - uses: actions/checkout@master + - uses: codecov/codecov-action@v4 + + with: + fail_ci_if_error: true # optional (default = false) + files: ./coverage1.xml,./coverage2.xml # optional + flags: unittests # optional + name: codecov-umbrella # optional + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) diff --git a/README.md b/README.md index 8471a1b6..ffbf3853 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # codecov-demo This repository is meant to show the features and functionalities of Codecov. You can follow along [here](https://docs.codecov.com/docs/codecov-tutorial). + +[![codecov](https://codecov.io/gh/NCherfaoui/codecov-demo/graph/badge.svg?token=ZEaY1zqYfQ)](https://codecov.io/gh/NCherfaoui/codecov-demo) \ No newline at end of file diff --git a/api/app.py b/api/app.py new file mode 100644 index 00000000..d91792d1 --- /dev/null +++ b/api/app.py @@ -0,0 +1,35 @@ +from flask import ( + Flask, + request, +) + +from calculator.calculator import Calculator + +app = Flask(__name__) + +@app.route('/api/add', methods=['POST']) +def add(): + return operation('add', 2) + +@app.route('/api/subtract', methods=['POST']) +def subtract(): + return operation('subtract', 2) + +@app.route('/api/multiply', methods=['POST']) +def multiply(): + return operation('multiply', 2) + +@app.route('/api/divide', methods=['POST']) +def divide(): + return operation('divide', 2) + +def operation(method, num_factors): + factors = [] + if num_factors == 2: + factors.append(float(request.json.get('x'))) + factors.append(float(request.json.get('y'))) + + return str(getattr(Calculator, method)(*factors)) + + +app.run(host='0.0.0.0', port=8080) \ No newline at end of file diff --git a/api/calculator/__init__.py b/api/calculator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/api/calculator/calculator.py b/api/calculator/calculator.py new file mode 100644 index 00000000..f92e65e2 --- /dev/null +++ b/api/calculator/calculator.py @@ -0,0 +1,14 @@ +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 \ No newline at end of file diff --git a/api/calculator/test_calculator.py b/api/calculator/test_calculator.py new file mode 100644 index 00000000..6067e895 --- /dev/null +++ b/api/calculator/test_calculator.py @@ -0,0 +1,42 @@ +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 + + +def test_divide_by_0(): + """ """ + assert Calculator.divide(2.0, 0) == "Cannot divide by 0" diff --git a/api/requirements.txt b/api/requirements.txt new file mode 100644 index 00000000..1a73aa07 --- /dev/null +++ b/api/requirements.txt @@ -0,0 +1,142 @@ +anyio==4.2.0 +argon2-cffi==23.1.0 +argon2-cffi-bindings==21.2.0 +arrow==1.3.0 +asttokens==2.4.1 +async-lru==2.0.4 +attrs==23.2.0 +Babel==2.14.0 +beautifulsoup4==4.12.2 +bleach==6.1.0 +blinker==1.7.0 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +comm==0.2.1 +contourpy==1.2.0 +coverage==7.4.1 +cycler==0.12.1 +debugpy==1.8.0 +decorator==5.1.1 +defusedxml==0.7.1 +exceptiongroup==1.2.0 +executing==2.0.1 +fastjsonschema==2.19.1 +filelock==3.13.1 +Flask==3.0.2 +fonttools==4.47.0 +fqdn==1.5.1 +fsspec==2023.12.2 +gitdb==4.0.11 +GitPython==3.1.41 +idna==3.6 +iniconfig==2.0.0 +ipykernel==6.28.0 +ipython==8.20.0 +isoduration==20.11.0 +itsdangerous==2.1.2 +jedi==0.19.1 +Jinja2==3.1.2 +joblib==1.3.2 +json5==0.9.14 +jsonpointer==2.4 +jsonschema==4.20.0 +jsonschema-specifications==2023.12.1 +jupyter-events==0.9.0 +jupyter-lsp==2.2.1 +jupyter-server-mathjax==0.2.6 +jupyter_client==8.6.0 +jupyter_core==5.7.1 +jupyter_server==2.12.3 +jupyter_server_terminals==0.5.1 +jupyterlab==4.0.10 +jupyterlab_git==0.50.0 +jupyterlab_pygments==0.3.0 +jupyterlab_server==2.25.2 +kiwisolver==1.4.5 +MarkupSafe==2.1.3 +matplotlib==3.8.2 +matplotlib-inline==0.1.6 +mistune==3.0.2 +mpmath==1.3.0 +nbclient==0.9.0 +nbconvert==7.14.0 +nbdime==4.0.1 +nbformat==5.9.2 +nest-asyncio==1.5.8 +networkx==3.2.1 +notebook_shim==0.2.3 +numpy==1.26.3 +nvidia-cublas-cu12==12.1.3.1 +nvidia-cuda-cupti-cu12==12.1.105 +nvidia-cuda-nvrtc-cu12==12.1.105 +nvidia-cuda-runtime-cu12==12.1.105 +nvidia-cudnn-cu12==8.9.2.26 +nvidia-cufft-cu12==11.0.2.54 +nvidia-curand-cu12==10.3.2.106 +nvidia-cusolver-cu12==11.4.5.107 +nvidia-cusparse-cu12==12.1.0.106 +nvidia-nccl-cu12==2.18.1 +nvidia-nvjitlink-cu12==12.3.101 +nvidia-nvtx-cu12==12.1.105 +overrides==7.4.0 +packaging==23.2 +pandas==2.1.4 +pandocfilters==1.5.0 +parso==0.8.3 +pexpect==4.9.0 +pillow==10.2.0 +platformdirs==4.1.0 +plotly==5.18.0 +pluggy==1.4.0 +prometheus-client==0.19.0 +prompt-toolkit==3.0.43 +psutil==5.9.7 +ptyprocess==0.7.0 +pure-eval==0.2.2 +pycparser==2.21 +Pygments==2.17.2 +pyparsing==3.1.1 +pytest==8.0.0 +pytest-cov==4.1.0 +python-dateutil==2.8.2 +python-json-logger==2.0.7 +pytz==2023.3.post1 +PyYAML==6.0.1 +pyzmq==25.1.2 +referencing==0.32.1 +requests==2.31.0 +rfc3339-validator==0.1.4 +rfc3986-validator==0.1.1 +rpds-py==0.16.2 +scikit-learn==1.3.2 +scipy==1.11.4 +seaborn==0.13.1 +Send2Trash==1.8.2 +six==1.16.0 +smmap==5.0.1 +sniffio==1.3.0 +soupsieve==2.5 +stack-data==0.6.3 +sympy==1.12 +tenacity==8.2.3 +terminado==0.18.0 +threadpoolctl==3.2.0 +tinycss2==1.2.1 +tomli==2.0.1 +torch==2.1.2 +tornado==6.4 +traitlets==5.14.1 +triton==2.1.0 +types-python-dateutil==2.8.19.20240106 +typing_extensions==4.9.0 +tzdata==2023.4 +uri-template==1.3.0 +urllib3==2.0.7 +wcwidth==0.2.13 +webcolors==1.13 +webencodings==0.5.1 +websocket-client==1.7.0 +Werkzeug==3.0.1 diff --git a/api/smiles/__init__.py b/api/smiles/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/api/smiles/smiles.py b/api/smiles/smiles.py new file mode 100644 index 00000000..ebdbb666 --- /dev/null +++ b/api/smiles/smiles.py @@ -0,0 +1,5 @@ +class Smiles: + def smile(): + return ":)" + def frown(): + return ":(" \ No newline at end of file diff --git a/api/smiles/test_smiles.py b/api/smiles/test_smiles.py new file mode 100644 index 00000000..4c3b8fa8 --- /dev/null +++ b/api/smiles/test_smiles.py @@ -0,0 +1,4 @@ +from .smiles import Smiles + +def test_smile(): + assert Smiles.smile() == ":)" \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..bc65af09 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,25 @@ +coverage: + status: + project: + default: + target: 100% + threshold: 1% +comment: + layout: "header, diff, flags, components" + +component_management: + individual_components: + - component_id: api # this is an identifier that should not be changed + name: api # this is a display name, and can be changed freely + paths: + - api + component_management: + individual_components: + - component_id: api-calculator # this is an identifier that should not be changed + name: calculator # this is a display name, and can be changed freely + paths: + - api/calculator/ + - component_id: api-smiles # this is an identifier that should not be changed + name: smiles # this is a display name, and can be changed freely + paths: + - api/smiles/ \ No newline at end of file