Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
test codev docker
Browse files Browse the repository at this point in the history
  • Loading branch information
WesGtoX committed Mar 27, 2021
1 parent 25ee07b commit 76dd2a8
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[run]
branch = True

[report]
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
omit =
.venv/*
venv/*

[html]
directory = htmlcov

[paths]
source =
src/
tests/
24 changes: 24 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Cov Test CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build the Docker image
run: docker-compose build --no-cache

- name: Run tests and upload coverage to Codecov
run: |
ci_env="bash <(curl -s https://codecov.io/env)"
ci_post_cov="bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}"
docker-compose run -e CI=true --rm api bash -c "$ci_env && pytest && $ci_post_cov"
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3.9.2-slim-buster

ENV PYTHONUNBUFFERED 1

# Install prerequisites
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y curl && \
apt-get install -y git

RUN pip install --upgrade pip

RUN mkdir /app
WORKDIR /app

COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY . /app/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Cov Test

[![codecov](https://codecov.io/gh/Hacksbr/cov-test/branch/main/graph/badge.svg?token=3YVKHF2eyl)](https://codecov.io/gh/Hacksbr/cov-test)

## License

Expand Down
27 changes: 27 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "70...100"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,files,footer"
behavior: default
require_changes: no

ignore:
- "test/"
- "*/**/test/*"
- "**/test/"
- "**/test/*"
- "**/test/**/"
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.8"

services:
api:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
4 changes: 4 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
python manage.py collectstatic --noinput
python manage.py migrate --no-input
python manage.py runserver 0.0.0.0:8000
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
testpaths = .
python_files = tests.py test_*.py *_tests.py
;addopts = --flake8 -vv -s --cov=./
addopts = --flake8 --cov=. -vv -s --cov-report=html
flake8-ignore =
*.py E501
.venv
33 changes: 33 additions & 0 deletions python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Cov Test CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
22 changes: 22 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
attrs==20.3.0
coverage==5.5
flake8==3.9.0
idna==3.1
iniconfig==1.1.1
mccabe==0.6.1
multidict==5.1.0
packaging==20.9
pluggy==0.13.1
py==1.10.0
pycodestyle==2.7.0
pyflakes==2.3.0
pyparsing==2.4.7
pytest==6.2.2
pytest-cov==2.11.1
pytest-flake8==1.0.7
PyYAML==5.4.1
six==1.15.0
toml==0.10.2
vcrpy==4.1.1
wrapt==1.12.1
yarl==1.6.3
Empty file added src/__init__.py
Empty file.
Empty file added src/main/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions src/main/calc_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def sum(a, b):
return a + b


def subtraction(a, b):
return a - b


# def sum_1(a, b, c):
# return a + b + c
#
#
# def subtraction_2(a, b, c):
# return a - b - c
10 changes: 10 additions & 0 deletions src/main/calc_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def division(a, b):
return a / b


def multiplication(a, b):
return a * b


# def multiplication_2(a, b, c, d):
# return (a * b) + (c - d)
14 changes: 14 additions & 0 deletions src/main/text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# def text_xx(a):
# return a * 2


def text_xxx(a):
return a * 3


def text_xxxx(a):
return a * 4


# def text(a):
# return a
Empty file added src/tests/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions src/tests/test_calc_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from src.main import calc_01
import pytest


@pytest.mark.parametrize('input,expected', [((2, 10), 12), ((3, 2), 5), ((5, 5), 10)])
def test_sum(input, expected):
value_a, value_b = input
result = calc_01.sum(value_a, value_b)
assert result == expected


@pytest.mark.parametrize('input,expected', [((3, 2), 1), ((10, 5), 5), ((17, 7), 10)])
def test_subtraction(input, expected):
value_a, value_b = input
result = calc_01.subtraction(value_a, value_b)
assert result == expected
16 changes: 16 additions & 0 deletions src/tests/test_calc_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from src.main import calc_02
import pytest


@pytest.mark.parametrize('input,expected', [((10, 2), 5), ((4, 2), 2), ((5, 5), 1)])
def test_division(input, expected):
value_a, value_b = input
result = calc_02.division(value_a, value_b)
assert result == expected


@pytest.mark.parametrize('input,expected', [((2, 10), 20), ((3, 2), 6), ((5, 5), 25)])
def test_multiplication(input, expected):
value_a, value_b = input
result = calc_02.multiplication(value_a, value_b)
assert result == expected
14 changes: 14 additions & 0 deletions src/tests/test_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from src.main import text
import pytest


@pytest.mark.parametrize('input,expected', [('a', 'aaa'), ('b', 'bbb'), ('c', 'ccc')])
def test_text_xxx(input, expected):
result = text.text_xxx(input)
assert result == expected


@pytest.mark.parametrize('input,expected', [('a', 'aaaa'), ('b', 'bbbb'), ('c', 'cccc')])
def test_text_xxxx(input, expected):
result = text.text_xxxx(input)
assert result == expected

0 comments on commit 76dd2a8

Please sign in to comment.