Skip to content

Commit

Permalink
Fix test tool configuration
Browse files Browse the repository at this point in the history
Test tools Pylint, Flake8 and Bandit configurations were
simplified.

The Pylint configuration was a long default configuration
that contained all the options with most of the options
in default values. There was also a separate files for the
tests and snippy source code. Now only the needed options
are configured and the files are merged to one default
file 'pylintrc'.

The Flake8 configuration was moved to setup.cfg to remove
own configuration file.

The result files for Pylint and Bandit were removed. This
was not a good idea in the past.

The configuration should be read from pyproject.toml. But
the tools do not yet support this feature.

[1] pylint-dev/pylint#617
[2] https://gitlab.com/pycqa/flake8/issues/428
[3] pytest-dev/pytest#1556

Signed-off-by: Heikki Laaksonen <[email protected]>
  • Loading branch information
heilaaks committed May 12, 2019
1 parent d63bbc7 commit 86c5f92
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 988 deletions.
27 changes: 27 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[MESSAGES CONTROL]
# The class object inheritance is required in Python 2.
disable=useless-object-inheritance

[TYPECHECK]

# The falcon class is ignored because it causes warnings from
# predefined HTTP status codes.
#
# Ignored because closing from contextlib causes unnecessary
# warning from 'with' clause.
ignored-classes=closing,falcon

# Ignored because test cases replace the implementations with
# mock that has additional member attributes.
ignored-modules=json,yaml

[FORMAT]

# Suited as of now for long lines in tests cases.
max-line-length=145

[DESIGN]

# Suited as of now for long methods in tests cases.
max-args=9
max-statements=60
106 changes: 32 additions & 74 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables

.PHONY: docs
.ONESHELL:

DEV_VERSION := 0.11a0
TAG_VERSION := 0.10.0

PKG_MANAGER := $(shell command -v dnf)
PKG_COMMAND := list installed
PYPY := pypy3
PYPY2_LIBS := pypy pypy-devel postgresql-devel
PYPY3_LIBS := pypy3 pypy3-devel postgresql-devel
PIP := pip
PYTHON := python
PYTHON_VERSION := $(shell python -c 'import sys; print(sys.version_info[0])')
INSTALL_USER :=
COVERAGE := --cov=snippy --cov-branch

# Only the Python 3 implememtation supports parallel tests. Sqlite database
# Only the Python 3 implementation supports parallel tests. Sqlite database
# can be run as a in-memory database only with Python 3. An in-memory DB is
# is needed for parallel testing.
ifeq ($(PYTHON_VERSION), 3)
Expand All @@ -27,18 +23,29 @@ else
PYTEST_CORES :=
endif

# The new pyproject.toml based PEP517 does not support --editable and it
# is not possible to run --user install inside a virtual environment. In
# order to use the install targets outside of a virtual environemnt, the
# INSTALL_USER variable must be set to '--user'.
# The new pyproject.toml from PEP517 does not support --editable install.
# It is not possible to run --user install inside a virtual environment.
#
# When the Makefile is used outside of a virtual environment to intsall
# dependencies, the INSTALL_USER variable should be set to '--user' to
# avoid a global install.
#
# There is a different between 'pip' and 'python -m pip' when installing
# the project itself. The later does not work with the uninstall with an
# actitve virtual environment. Using 'pip' works inside active virtual
# environment as well as without virtual environment.
install:
$(PYTHON) -m pip install . $(INSTALL_USER)
$(PIP) install . $(INSTALL_USER)

upgrade:
$(PYTHON) -m pip install --upgrade . $(INSTALL_USER)
$(PIP) install --upgrade . $(INSTALL_USER)

uninstall:
$(PYTHON) -m pip uninstall --yes snippy
$(PIP) uninstall --yes snippy .

upgrade-wheel:
$(PYTHON) -m ensurepip $(INSTALL_USER)
$(PYTHON) -m pip install pip setuptools wheel twine --upgrade $(INSTALL_USER)

install-devel:
$(PYTHON) -m pip install .[devel] $(INSTALL_USER)
Expand All @@ -49,30 +56,26 @@ install-tests:
install-server:
$(PYTHON) -m pip install .[server] $(INSTALL_USER)

upgrade-wheel:
$(PYTHON) -m ensurepip $(INSTALL_USER)
$(PYTHON) -m pip install pip setuptools wheel twine --upgrade $(INSTALL_USER)

outdated:
$(PYTHON) -m pip list --outdated

docs:
make -C docs html

test:
$(PYTHON) -m pytest -x ./tests/test_*.py --cov snippy --snippy-db sqlite -m "not (docker or server)" $(PYTEST_CORES)
$(PYTHON) -m pytest -x ${COVERAGE} --snippy-db sqlite -m "not (docker or server)" $(PYTEST_CORES)

test-docker:
$(PYTHON) -m pytest -x ./tests/test_*.py --cov snippy --snippy-db sqlite -m "docker"
$(PYTHON) -m pytest -x ${COVERAGE} --snippy-db sqlite -m "docker"

test-server:
$(PYTHON) -m pytest -x ./tests/test_*.py --cov snippy --snippy-db sqlite -m "server"
$(PYTHON) -m pytest -x ${COVERAGE} --snippy-db sqlite -m "server"

test-postgresql:
$(PYTHON) -m pytest -x ./tests/test_*.py --cov snippy --snippy-db postgresql -m "not (docker or server)"
$(PYTHON) -m pytest -x ${COVERAGE} --snippy-db postgresql -m "not (docker or server)"

test-in-memroy:
$(PYTHON) -m pytest -x ./tests/test_*.py --cov snippy --snippy-db in-memory -m "not (docker or server)"
$(PYTHON) -m pytest -x ${COVERAGE} --snippy-db in-memory -m "not (docker or server)"

test-tox:
tox
Expand All @@ -86,25 +89,24 @@ test-release-wheel: clean-all
twine check dist/*

coverage:
$(PYTHON) -m pytest --cov=snippy --cov-branch --cov-report html tests/ -m "not (server or docker)"
$(PYTHON) -m pytest --cov=snippy tests/
$(PYTHON) -m pytest ${COVERAGE} --cov-report html -m "not (server or docker)" $(PYTEST_CORES)

lint:
$(PYTHON) -m pylint --jobs=0 --rcfile tests/pylint/pylint-snippy-tests.rc tests/ | tee tests/pylint/pylint-snippy-tests.txt
$(PYTHON) -m pylint --jobs=0 --rcfile tests/pylint/pylint-snippy.rc snippy/ | tee tests/pylint/pylint-snippy.txt
$(PYTHON) -m flake8 --config tests/flake8/flake8.ini snippy
$(PYTHON) -m pylint --jobs=0 tests/
$(PYTHON) -m pylint --jobs=0 snippy/
$(PYTHON) -m flake8 snippy

pyflakes:
$(PYTHON) -m pyflakes .

schema:
jsonschema:
openapi2jsonschema snippy/data/server/openapi/swagger-2.0.yml -o snippy/data/server/openapi/schema/

docker: clean-all
docker build --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} -t heilaaks/snippy .

security-scan:
-bandit -r snippy | tee tests/bandit/bandit.txt
-bandit -r snippy

clean: clean-build clean-pyc clean-test

Expand Down Expand Up @@ -160,47 +162,3 @@ prepare-release:
@echo "$$(date +'%Y-%m-%dT%H:%M:%S'): Updated tool version ${DEV_VERSION} to ${TAG_VERSION}"
make test-release
@echo "$$(date +'%Y-%m-%dT%H:%M:%S'): All automated tests and checks run"

install-devel-pypy:
@echo "##########################################################################"
@echo "Requires on Fedora:"
@echo " dnf install pypy3 -y"
@echo " dnf install pypy3-devel -y"
@echo " dnf install postgresql-devel -y"
@echo "##########################################################################"
$(PYPY) -m pip install .[develpypy]

install-server-pypy:
@echo "##########################################################################"
@echo "Requires on Fedora:"
@echo " dnf install pypy3 -y"
@echo " dnf install pypy3-devel -y"
@echo " dnf install postgresql-devel -y"
@echo "##########################################################################"
$(PYPY) -m pip install .[serverpypy]

# $(call test-pypy-libs, pkg-manager, pkg-COMMAND, required-libs)
#
# Test if given array of pacakges is installed with given package
# manager. Backslashes are aligned for 8 space tabs.
define test-installed-libs
$$( \
set -x; \
MISSING=(); \
i=0; \
if [ ! -z "${1}" ]; then \
for PACKAGE in ${3}; do \
if [ -z "$$(${1} ${2} | grep $${PACKAGE})" ]; then \
MISSING+=$$PACKAGE; \
fi \
done; \
else \
false; \
fi; \
if [ $${#MISSING[@]} -eq 0 ]; then \
true; \
else \
echo "$${MISSING[*]}"; \
fi \
)
endef
13 changes: 5 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## WORKING
- [ ] Check and fix API perfromance test results after in-memory change.
- [ ] Test if new pypy venv is able to select the pypy specific psycopg2cffi
- [ ] Change name of --scat to --cat?
- [ ] Fix cause 'Content has been created without internal errors.' This breaks when there is e.g. created and bad request. That is the cause ok does not see 404 and sends OK.
- [ ] Fix updating Markdown based solutions in text formats does not work because the Mkdn solution does not have text header and data structure.
Expand Down Expand Up @@ -28,8 +27,6 @@
- [ ] Fix digest computation once things are setling down. Changing this forces changes to all tests and code that rely on digest.
- [ ] Fix updating content without updates changes the updated timestamp. There is no need to store the content either.
- [ ] Add delete for wheel build directory for automation. If the folder exist this is a problem (at least used to be) see how to fail python release/building/something.
- [ ] Refactor Makefile to have python|python3|pypy|pypy3 as ${PYTHON}.
- [ ] How to compile psycopg2 for PyPY?
- [ ] Config get_resource could return empty Resource instead of None in failure. This is now related to new migrate refactoring that prevents migrating template resources.
- [ ] Fix (remove) the LANG in Alpine based dockerfile? Is this useless as MUSL does not support locales? https://github.com/gliderlabs/docker-alpine/issues/144
- [ ] Fix server silent startup failure if for example the port is reserved. How to get proper error cause for user?
Expand Down Expand Up @@ -62,12 +59,13 @@
- [ ] Fix (optimize) Why GET with limit=20 is much slower than limit=1? Even POST with one resource is much faster than GET with limit=20 (Sqlite in tests). The test produced 409 from trying to POST the same content in loop.

## RELEASING
- [ ] Document user must be able to run Docker. Add instructions.
- [ ] Automate PostgreSQL startup.
- [ ] Remove running snippy container before testing.
- [ ] Use make upgrade-wheel PYTHON=pypy3 instead of PYPY targets. Change setup so that it looks the python version and there are no pypy specific extras (like the server)
- [ ] Snippy asciinema semi faked prompt fails with rest api responses. The prompt is in the same line as the last curly bracket from rest api response.

## PACKAGING
- [ ] Change Pytest, Pylint, Flake8, Pyflake and Bandit to use pyproject when the support comes. This merges the configuration files to one place.

## FEATURES
- [ ] Add CORS https://stackoverflow.com/a/45183343. This is needed to make the server usable at all?
- [ ] Add decsription, name, versions and source to CLI? Or does this make the CLI too bloated? These can be updated via editor or REST API.
Expand All @@ -76,7 +74,6 @@
- [ ] Add combine on top of migrate and merge. The combine would allow adding for example a tag to an existing list of tags. This would be nice for CLI and could be used with RFC 6902 (JSON Patch) (if implemented).
- [ ] Add support to search phrases like has 'active end'. This should return one result with default set but it returns two since each word is searched separately.
- [ ] Add support to find dead links.
- [ ] Add Travis CI for PyPy version v6.0 for Python 3 when it comes https://github.com/travis-ci/travis-ci/issues/9542
- [ ] Add test client to measure performance of the server.
- [ ] Add user management with a new user table that lins to contents table.
- [ ] Add limit to multilevel sort fields to two fields to avoid complex scenarios.
Expand Down Expand Up @@ -132,7 +129,6 @@
- [ ] Why changing self._data = data in data setter in line 160 to self.data = data in config base seems to cause core. This can be used to set the Travis gdb parameters.
- [ ] Should _add_date in Content() be based on updated when DATE already set? The reason would be that this sets the text template DATE and it should be always latest which is updated?
- [ ] Fix tox and Python 3.4. Tox -e py34 // http://notes.webutvikling.org/darn-installation-of-python-3-4/. This was broken with Fedora 26. With Fedora 30 this works. This is heere because complication instructions are not complete in tox.ini.
- [ ] Fix PyPy 5.5.0 (Python 3.3) that does not have sqlite uri=True and does not have server 'ssl_version': ssl.PROTOCOL_TLSv1_2. Otherwise tests pass with exception of schema validation errors. works with later Pypy would be the best quess.

## REFACTOR
- [ ] Storage update() supports only one resource and this is not in line with others. Change to collection?
Expand Down Expand Up @@ -192,9 +188,10 @@
- [ ] Fix the Python2 test database naming to be random temp file in the same folder to allow parallelism.
- [ ] Why when in Python2 a database test fails, it leaves hanging resources and DB clean does not work? Was this fixed into sqlite3_helper already?
- [ ] How to better prevent commits to snippy.db than git hooks or git --assume-unchanged?
- [ ] Fix PyPy 5.5.0 (Python 3.3) that does not have sqlite uri=True and does not have server 'ssl_version': ssl.PROTOCOL_TLSv1_2. This is working with latest PyPy implementations and this is not a priority fix.

## FOLLOW EXTERNAL BUGS/ISSUES
- [ ] Misleading ValidationError from AnyOf required property list // https://github.com/Julian/jsonschema/issues/535
- [x] Misleading ValidationError from AnyOf required property list // https://github.com/Julian/jsonschema/issues/535
- [ ] Is there an external bug with more and ANSI color codes? // 'Linux more command with ANSI colors'
- [ ] Pytest support for PEP-518 pyproject.toml is missing // https://github.com/pytest-dev/pytest/issues/1556
- [ ] OpenAPI does not support OPTIONS HTTP method and it cannot be defined. // https://github.com/OAI/OpenAPI-Specification/issues/325
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[bdist_wheel]
universal=1

[flake8]
max-line-length = 140
39 changes: 0 additions & 39 deletions tests/bandit/bandit.txt

This file was deleted.

6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
# Originals
JSON_LOAD = json.load

# pylint: disable=too-many-lines

# Pytest hooks.
def pytest_addoption(parser):
"""Pytest hook to add command line options.
Expand Down Expand Up @@ -188,11 +190,11 @@ def pytest_sessionstart(session):
Database.set_database(database)
Database.delete_all_contents()

def pytest_report_header(config):
def pytest_report_header(_):
"""Pytest hook to set report header.
Args:
config (obj): Pytest Config() object.
_ (obj): Pytest Config() object.
"""

return 'database: {}{}{}'.format(Helper.COLOR_OK, Database.get_database(), Helper.COLOR_END)
Expand Down
3 changes: 0 additions & 3 deletions tests/flake8/flake8.ini

This file was deleted.

2 changes: 1 addition & 1 deletion tests/lib/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from tests.lib.snippet import Snippet
from tests.lib.solution import Solution

class Content(object): # pylint: disable=too-many-public-methods
class Content(object): # pylint: disable=too-many-public-methods, too-many-lines
"""Helper methods for content testing."""

# categories
Expand Down
Loading

0 comments on commit 86c5f92

Please sign in to comment.