Skip to content

Commit

Permalink
implemented testing components
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Antonellis committed Jan 26, 2021
1 parent dc15c4b commit 6c123a6
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .bandit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bandit]
exclude: tests,venv,env
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-complexity = 8
ignore = E203,W503,E501
builtins = unicode
tee = True
exclude = venv,env
280 changes: 280 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
manually added
################
# VS Code
.vscode/*

# Custom coverage directory
cov_html/

# build output
dist/

# venvs
style_venv/

.DS_Store

################################
# Bellow is created as described
################################
# Created by https://www.gitignore.io/api/emacs,python,intellij+all
# Edit at https://www.gitignore.io/?templates=emacs,python,intellij+all

### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Org-mode
.org-id-locations
*_archive

# flymake-mode
*_flymake.*

# eshell files
/eshell/history
/eshell/lastdir

# elpa packages
/elpa/

# reftex files
*.rel

# AUCTeX auto folder
/auto/

# cask packages
.cask/
dist/

# Flycheck
flycheck_*.el

# server auth directory
/server/

# projectiles files
.projectile

# directory configuration
.dir-locals.el

# network security
/network-security.data


### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### Python Patch ###
.venv/

# End of https://www.gitignore.io/api/emacs,python,intellij+all
glove_embeddings
/output/
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
8 changes: 7 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
version: "3.4"
services:

dev:
dev: &dev
build:
dockerfile: "./docker/Dockerfile"
context: "."
image: "extra-model-dev"
volumes:
- ./:/io

# run all the tests and linting locally
# - black & isort will format code to address issues
test:
<<: *dev
command: docker/run_tests.sh --format-code
6 changes: 6 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
FROM python:3.6-buster

RUN mkdir /io
COPY . /io
WORKDIR /io

RUN pip install -r requirements.txt -r requirements-test.txt

CMD bash
53 changes: 53 additions & 0 deletions docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

set -eo pipefail

BLACK_ACTION="--check"
ISORT_ACTION="--check-only"

function usage
{
echo "usage: run_tests.sh [--format-code]"
echo ""
echo " --format-code : Format the code instead of checking formatting."
exit 1
}

while [[ $# -gt 0 ]]; do
arg="$1"
case $arg in
--format-code)
BLACK_ACTION="--quiet"
ISORT_ACTION=""
;;
-h|--help)
usage
;;
"")
# ignore
;;
*)
echo "Unexpected argument: ${arg}"
usage
;;
esac
shift
done

# only generate html locally
pytest tests --cov-report html

echo "Running MyPy..."
mypy extra_model tests

echo "Running black..."
black ${BLACK_ACTION} extra_model tests

echo "Running iSort..."
isort ${ISORT_ACTION} extra_model tests

echo "Running flake8..."
flake8 extra_model tests

echo "Running bandit..."
bandit --ini .bandit --quiet -r extra_model
2 changes: 2 additions & 0 deletions extra_model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def example():
return "hello, world"
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
addopts = --verbose --cov=extra_model --cov-report html:cov_html --cov-report term
python_files = tests/*.py
9 changes: 9 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bandit==1.7.0
black==20.8b1
flake8==3.8.4
isort==5.7.0
mypy==0.800
pytest==6.2.2
pytest-cov==2.11.1
pytest-mock==3.5.1
pdbpp==0.10.2
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
click==7.1.2
Empty file added tests/__init__.py
Empty file.
Loading

0 comments on commit 6c123a6

Please sign in to comment.