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 13 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$
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install:
- pip3 install pre-commit pytest pytest-cov codecov

script:
- pip install -r tests/utils/requirements.txt
- pre-commit run --all-files
- pip3 install .
- pytest --cov --cov-report=xml
Expand Down
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
YARPC=yarpc
TEST_DIR=tests/unit

.PHONY: create-env
create-env:
rm -rf env
python3 -m pip install --user virtualenv
python3 -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)

.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 -a "Google Chrome" htmlcov/index.html

.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