Skip to content

Commit 86c5f92

Browse files
committed
Fix test tool configuration
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]>
1 parent d63bbc7 commit 86c5f92

17 files changed

+79
-988
lines changed

.pylintrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[MESSAGES CONTROL]
2+
# The class object inheritance is required in Python 2.
3+
disable=useless-object-inheritance
4+
5+
[TYPECHECK]
6+
7+
# The falcon class is ignored because it causes warnings from
8+
# predefined HTTP status codes.
9+
#
10+
# Ignored because closing from contextlib causes unnecessary
11+
# warning from 'with' clause.
12+
ignored-classes=closing,falcon
13+
14+
# Ignored because test cases replace the implementations with
15+
# mock that has additional member attributes.
16+
ignored-modules=json,yaml
17+
18+
[FORMAT]
19+
20+
# Suited as of now for long lines in tests cases.
21+
max-line-length=145
22+
23+
[DESIGN]
24+
25+
# Suited as of now for long methods in tests cases.
26+
max-args=9
27+
max-statements=60

Makefile

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ MAKEFLAGS += --no-builtin-rules
44
MAKEFLAGS += --no-builtin-variables
55

66
.PHONY: docs
7-
.ONESHELL:
87

98
DEV_VERSION := 0.11a0
109
TAG_VERSION := 0.10.0
1110

12-
PKG_MANAGER := $(shell command -v dnf)
13-
PKG_COMMAND := list installed
14-
PYPY := pypy3
15-
PYPY2_LIBS := pypy pypy-devel postgresql-devel
16-
PYPY3_LIBS := pypy3 pypy3-devel postgresql-devel
11+
PIP := pip
1712
PYTHON := python
1813
PYTHON_VERSION := $(shell python -c 'import sys; print(sys.version_info[0])')
1914
INSTALL_USER :=
15+
COVERAGE := --cov=snippy --cov-branch
2016

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

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

3740
upgrade:
38-
$(PYTHON) -m pip install --upgrade . $(INSTALL_USER)
41+
$(PIP) install --upgrade . $(INSTALL_USER)
3942

4043
uninstall:
41-
$(PYTHON) -m pip uninstall --yes snippy
44+
$(PIP) uninstall --yes snippy .
45+
46+
upgrade-wheel:
47+
$(PYTHON) -m ensurepip $(INSTALL_USER)
48+
$(PYTHON) -m pip install pip setuptools wheel twine --upgrade $(INSTALL_USER)
4249

4350
install-devel:
4451
$(PYTHON) -m pip install .[devel] $(INSTALL_USER)
@@ -49,30 +56,26 @@ install-tests:
4956
install-server:
5057
$(PYTHON) -m pip install .[server] $(INSTALL_USER)
5158

52-
upgrade-wheel:
53-
$(PYTHON) -m ensurepip $(INSTALL_USER)
54-
$(PYTHON) -m pip install pip setuptools wheel twine --upgrade $(INSTALL_USER)
55-
5659
outdated:
5760
$(PYTHON) -m pip list --outdated
5861

5962
docs:
6063
make -C docs html
6164

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

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

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

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

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

7780
test-tox:
7881
tox
@@ -86,25 +89,24 @@ test-release-wheel: clean-all
8689
twine check dist/*
8790

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

9294
lint:
93-
$(PYTHON) -m pylint --jobs=0 --rcfile tests/pylint/pylint-snippy-tests.rc tests/ | tee tests/pylint/pylint-snippy-tests.txt
94-
$(PYTHON) -m pylint --jobs=0 --rcfile tests/pylint/pylint-snippy.rc snippy/ | tee tests/pylint/pylint-snippy.txt
95-
$(PYTHON) -m flake8 --config tests/flake8/flake8.ini snippy
95+
$(PYTHON) -m pylint --jobs=0 tests/
96+
$(PYTHON) -m pylint --jobs=0 snippy/
97+
$(PYTHON) -m flake8 snippy
9698

9799
pyflakes:
98100
$(PYTHON) -m pyflakes .
99101

100-
schema:
102+
jsonschema:
101103
openapi2jsonschema snippy/data/server/openapi/swagger-2.0.yml -o snippy/data/server/openapi/schema/
102104

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

106108
security-scan:
107-
-bandit -r snippy | tee tests/bandit/bandit.txt
109+
-bandit -r snippy
108110

109111
clean: clean-build clean-pyc clean-test
110112

@@ -160,47 +162,3 @@ prepare-release:
160162
@echo "$$(date +'%Y-%m-%dT%H:%M:%S'): Updated tool version ${DEV_VERSION} to ${TAG_VERSION}"
161163
make test-release
162164
@echo "$$(date +'%Y-%m-%dT%H:%M:%S'): All automated tests and checks run"
163-
164-
install-devel-pypy:
165-
@echo "##########################################################################"
166-
@echo "Requires on Fedora:"
167-
@echo " dnf install pypy3 -y"
168-
@echo " dnf install pypy3-devel -y"
169-
@echo " dnf install postgresql-devel -y"
170-
@echo "##########################################################################"
171-
$(PYPY) -m pip install .[develpypy]
172-
173-
install-server-pypy:
174-
@echo "##########################################################################"
175-
@echo "Requires on Fedora:"
176-
@echo " dnf install pypy3 -y"
177-
@echo " dnf install pypy3-devel -y"
178-
@echo " dnf install postgresql-devel -y"
179-
@echo "##########################################################################"
180-
$(PYPY) -m pip install .[serverpypy]
181-
182-
# $(call test-pypy-libs, pkg-manager, pkg-COMMAND, required-libs)
183-
#
184-
# Test if given array of pacakges is installed with given package
185-
# manager. Backslashes are aligned for 8 space tabs.
186-
define test-installed-libs
187-
$$( \
188-
set -x; \
189-
MISSING=(); \
190-
i=0; \
191-
if [ ! -z "${1}" ]; then \
192-
for PACKAGE in ${3}; do \
193-
if [ -z "$$(${1} ${2} | grep $${PACKAGE})" ]; then \
194-
MISSING+=$$PACKAGE; \
195-
fi \
196-
done; \
197-
else \
198-
false; \
199-
fi; \
200-
if [ $${#MISSING[@]} -eq 0 ]; then \
201-
true; \
202-
else \
203-
echo "$${MISSING[*]}"; \
204-
fi \
205-
)
206-
endef

TODO.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## WORKING
22
- [ ] Check and fix API perfromance test results after in-memory change.
3-
- [ ] Test if new pypy venv is able to select the pypy specific psycopg2cffi
43
- [ ] Change name of --scat to --cat?
54
- [ ] 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.
65
- [ ] Fix updating Markdown based solutions in text formats does not work because the Mkdn solution does not have text header and data structure.
@@ -28,8 +27,6 @@
2827
- [ ] Fix digest computation once things are setling down. Changing this forces changes to all tests and code that rely on digest.
2928
- [ ] Fix updating content without updates changes the updated timestamp. There is no need to store the content either.
3029
- [ ] 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.
31-
- [ ] Refactor Makefile to have python|python3|pypy|pypy3 as ${PYTHON}.
32-
- [ ] How to compile psycopg2 for PyPY?
3330
- [ ] 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.
3431
- [ ] 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
3532
- [ ] Fix server silent startup failure if for example the port is reserved. How to get proper error cause for user?
@@ -62,12 +59,13 @@
6259
- [ ] 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.
6360

6461
## RELEASING
65-
- [ ] Document user must be able to run Docker. Add instructions.
6662
- [ ] Automate PostgreSQL startup.
6763
- [ ] Remove running snippy container before testing.
68-
- [ ] 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)
6964
- [ ] 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.
7065

66+
## PACKAGING
67+
- [ ] Change Pytest, Pylint, Flake8, Pyflake and Bandit to use pyproject when the support comes. This merges the configuration files to one place.
68+
7169
## FEATURES
7270
- [ ] Add CORS https://stackoverflow.com/a/45183343. This is needed to make the server usable at all?
7371
- [ ] 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.
@@ -76,7 +74,6 @@
7674
- [ ] 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).
7775
- [ ] 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.
7876
- [ ] Add support to find dead links.
79-
- [ ] Add Travis CI for PyPy version v6.0 for Python 3 when it comes https://github.com/travis-ci/travis-ci/issues/9542
8077
- [ ] Add test client to measure performance of the server.
8178
- [ ] Add user management with a new user table that lins to contents table.
8279
- [ ] Add limit to multilevel sort fields to two fields to avoid complex scenarios.
@@ -132,7 +129,6 @@
132129
- [ ] 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.
133130
- [ ] 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?
134131
- [ ] 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.
135-
- [ ] 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.
136132

137133
## REFACTOR
138134
- [ ] Storage update() supports only one resource and this is not in line with others. Change to collection?
@@ -192,9 +188,10 @@
192188
- [ ] Fix the Python2 test database naming to be random temp file in the same folder to allow parallelism.
193189
- [ ] 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?
194190
- [ ] How to better prevent commits to snippy.db than git hooks or git --assume-unchanged?
191+
- [ ] 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.
195192

196193
## FOLLOW EXTERNAL BUGS/ISSUES
197-
- [ ] Misleading ValidationError from AnyOf required property list // https://github.com/Julian/jsonschema/issues/535
194+
- [x] Misleading ValidationError from AnyOf required property list // https://github.com/Julian/jsonschema/issues/535
198195
- [ ] Is there an external bug with more and ANSI color codes? // 'Linux more command with ANSI colors'
199196
- [ ] Pytest support for PEP-518 pyproject.toml is missing // https://github.com/pytest-dev/pytest/issues/1556
200197
- [ ] OpenAPI does not support OPTIONS HTTP method and it cannot be defined. // https://github.com/OAI/OpenAPI-Specification/issues/325

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[bdist_wheel]
22
universal=1
3+
4+
[flake8]
5+
max-line-length = 140

tests/bandit/bandit.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159
# Originals
160160
JSON_LOAD = json.load
161161

162+
# pylint: disable=too-many-lines
163+
162164
# Pytest hooks.
163165
def pytest_addoption(parser):
164166
"""Pytest hook to add command line options.
@@ -188,11 +190,11 @@ def pytest_sessionstart(session):
188190
Database.set_database(database)
189191
Database.delete_all_contents()
190192

191-
def pytest_report_header(config):
193+
def pytest_report_header(_):
192194
"""Pytest hook to set report header.
193195
194196
Args:
195-
config (obj): Pytest Config() object.
197+
_ (obj): Pytest Config() object.
196198
"""
197199

198200
return 'database: {}{}{}'.format(Helper.COLOR_OK, Database.get_database(), Helper.COLOR_END)

tests/flake8/flake8.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/lib/content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from tests.lib.snippet import Snippet
4747
from tests.lib.solution import Solution
4848

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

5252
# categories

0 commit comments

Comments
 (0)