Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

issue: #7 | PyTest, Makefile & Coverage Report #22

Merged
merged 16 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ venv.bak/
[._]ss[a-gi-z]
[._]sw[a-p]

#IDEs
.vscode

# Session
Session.vim

Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ repos:
- id: end-of-file-fixer
exclude_types: [svg]
- id: flake8
- id: name-tests-test

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.730
hooks:
- id: mypy
files: ^yarpc/.+$

- repo: local
hooks:
- id: pytest
name: pytest
entry: pytest tests/unit
language: python
files: (^|/)tests/.+\.py$
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
before_install:
- choco install python
- python -m pip install --upgrade pip
- choco install make
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH

cache:
Expand All @@ -28,9 +29,7 @@ install:
- pip3 install pre-commit pytest pytest-cov codecov

script:
- pre-commit run --all-files
- pip3 install .
- pytest --cov --cov-report=xml
- make ci-test

after_script:
- codecov -f coverage.xml
48 changes: 48 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
YARPC=yarpc
TEST_DIR=tests
PYTHON?=python3
PIP?=pip
PYTEST?=pytest

.PHONY: create-env
create-env:
rm -rf env
$(PYTHON) -m $(PIP) install --user virtualenv
$(PYTHON) -m venv env
source env/bin/activate

.PHONY: install
install:
$(PIP) install --upgrade $(PIP)
$(PIP) install -r $(TEST_DIR)/utils/requirements.txt

.PHONY: test
test: .cleanCoverage
$(PYTEST) $(TEST_DIR)/unit

.cleanCoverage:
@echo 'cleaning coverage files ...'
rm -f .coverage
rm -fr htmlcov/

.PHONY: open-report
open-report: .cleanCoverage
$(PYTEST) --cov=$(YARPC) --cov-report=term-missing --cov-report=html
open htmlcov/index.html

.PHONY: ci-test
ci-test:
$(PIP) install -r tests/utils/requirements.txt
pre-commit run --all-files
$(PIP) install .
$(PYTEST) --cov --cov-report=xml

.PHONY: help
help:
@echo '==================================== HELP ===================================='
@echo 'create-env - creates a virtualenv'
@echo 'install - install all run pre requisites to run tests and coverage report'
@echo 'test - run unit tests on all Python files'
@echo 'open-report - check code coverage of all Python files'
@echo 'lint - run pylint and flake8 on all your Python files'
@echo ''
Empty file added tests/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/unit/constants_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from yarpc import constants


def test_NoValue_object():
"""
Should ensure the NoValue property is an object
"""
assert isinstance(constants.NoValue, object)
28 changes: 28 additions & 0 deletions tests/unit/enums_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from yarpc import StatusCode

all_enumaration_types = [
StatusCode.SUCCESS,
StatusCode.BAD_FORMAT,
StatusCode.UNKNOWN_COMMAND,
StatusCode.BAD_PARAMS,
StatusCode.INTERNAL_ERROR,
]


def test_properties_values():
"""
Should ensure that variables are set to their expected values
"""

vals = [0, 1, 2, 3, 4]
for enum in all_enumaration_types:
assert enum.value == vals[enum.value]


def test_properties_types():
"""
Should have the enum variable of type Enum
"""

for enum in all_enumaration_types:
assert type(enum) == StatusCode
6 changes: 6 additions & 0 deletions tests/utils/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest-cov==2.8.1
pytest==5.2.1
aioredis==1.3.0
isort==4.3.21
black==19.3b0
flake8==3.7.8