Skip to content

Commit

Permalink
Merge pull request #102 from Snawoot/fix_tests
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
Snawoot authored Aug 4, 2023
2 parents 9997ae6 + 9eceb4c commit c647342
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 106 deletions.
80 changes: 1 addition & 79 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,85 +60,14 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
missing-docstring,
import-error,
broad-except,
Expand Down Expand Up @@ -266,13 +195,6 @@ max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
21 changes: 17 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
language: python
dist: bionic

addons:
postgresql: "10"
apt:
packages:
- postgresql-10
- postgresql-client-10

matrix:
include:
- python: 3.9
- python: 3.11
env: TOXENV=lint
- python: 3.9
- python: 3.11
env: TOXENV=cover
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.8
env: TOXENV=py38
- python: 3.9
env: TOXENV=py39
- python: 3.10
env: TOXENV=py310
- python: 3.11
env: TOXENV=py311
- python: 3.7
env: TOXENV=py37-uvloop
- python: 3.8
env: TOXENV=py38-uvloop
- python: 3.9
env: TOXENV=py39-uvloop
- python: 3.10
env: TOXENV=py310-uvloop
- python: 3.11
env: TOXENV=py311-uvloop
install:
- "sudo -H env PYTHON=\"$(command -v python)\" tests/install.debian.sh"
script:
Expand Down
21 changes: 11 additions & 10 deletions postfix_mta_sts_resolver/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ async def amain(cfg, loop): # pragma: no cover
def main(): # pragma: no cover
args = parse_args()
if args.pidfile is not None:
with open(args.pidfile, 'w') as f:
f.write(str(os.getpid()))
with open(args.pidfile, 'w', encoding='ascii') as pid_file:
pid_file.write(str(os.getpid()))
if args.group is not None:
try:
g = grp.getgrnam(args.group)
os.setegid(g.gr_gid)
except Exception as e:
print("Unable to change eGID to '{}': {}".format(args.group, e), file=sys.stderr)
group = grp.getgrnam(args.group)
os.setegid(group.gr_gid)
except Exception as exc:
print("Unable to change eGID to '{}': {}".format(args.group, exc), file=sys.stderr)
return os.EX_OSERR
if args.user is not None:
try:
p = pwd.getpwnam(args.user)
os.seteuid(p.pw_uid)
except Exception as e:
print("Unable to change eUID to '{}': {}".format(args.user, e), file=sys.stderr)
passwd = pwd.getpwnam(args.user)
os.seteuid(passwd.pw_uid)
except Exception as exc:
print("Unable to change eUID to '{}': {}".format(args.user, exc), file=sys.stderr)
return os.EX_OSERR
with utils.AsyncLoggingHandler(args.logfile) as log_handler:
logger = utils.setup_logger('MAIN', args.verbosity, log_handler)
Expand All @@ -148,3 +148,4 @@ def main(): # pragma: no cover
evloop.run_until_complete(amain(cfg, evloop))
evloop.close()
logger.info("Server finished its work.")
return os.EX_OK
4 changes: 2 additions & 2 deletions postfix_mta_sts_resolver/postgres_cache.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=invalid-name,protected-access

import asyncio
import asyncpg
import json
import logging

import asyncpg

from .defaults import POSTGRES_TIMEOUT
from .base_cache import BaseCache, CacheEntry

Expand Down
4 changes: 2 additions & 2 deletions tests/install.debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PYTHON="${PYTHON:-python3}"
# run under travis, but not under autopkgtest
if [ -z "${AUTOPKGTEST_TMP+x}" ] ; then
apt-get update
apt-get install -y redis-server postgresql dnsmasq lsof nginx-extras tinyproxy \
apt-get install -y redis-server dnsmasq lsof nginx-extras tinyproxy \
build-essential libssl-dev libffi-dev python3-dev cargo
systemctl start redis-server || { journalctl -xe ; false ; }
"$PYTHON" -m pip install cryptography
Expand All @@ -17,7 +17,7 @@ fi
install -m 644 tests/resolv.conf /etc/resolv-dnsmasq.conf
cat tests/dnsmasq.conf.appendix >> /etc/dnsmasq.conf
echo 'nameserver 127.0.0.1' > /etc/resolv.conf
systemctl restart dnsmasq postgresql || { journalctl -xe ; false ; }
systemctl restart dnsmasq || { journalctl -xe ; false ; }


# certificates for the test cases
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async def setup_cache(cache_type, cache_opts):
("sqlite", {}, False),
("redis", {"url": "redis://127.0.0.1/0?socket_timeout=5&socket_connect_timeout=5"}, True),
("redis", {"url": "redis://127.0.0.1/0?socket_timeout=5&socket_connect_timeout=5"}, False),
("postgres", {"dsn": "postgres://postgres@%2Frun%2Fpostgresql/postgres"}, True),
("postgres", {"dsn": "postgres://postgres@%2Frun%2Fpostgresql/postgres"}, False),
("postgres", {"dsn": "postgres://postgres@localhost:5432"}, True),
("postgres", {"dsn": "postgres://postgres@localhost:5432"}, False),
])
@pytest.mark.asyncio
async def test_cache_lifecycle(cache_type, cache_opts, safe_set):
Expand Down
14 changes: 7 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[tox]
envlist = py{36,37,38,39}, py{37,38,39}-uvloop, lint, cover
envlist = py{37,38,39,310,311}, py{37,38,39,310,311}-uvloop, lint, cover
skipsdist = true

[testenv]
passenv = TOXENV
commands =
py{36,37,38,39}: pip install -e '.[dev,sqlite,redis]'
py{37,38,39}-uvloop: pip install -e '.[dev,sqlite,redis,uvloop]'
py{37,38,39,310,311}: pip install -e '.[dev,sqlite,redis,postgres]'
py{37,38,39,310,311}-uvloop: pip install -e '.[dev,sqlite,redis,postgres,uvloop]'
pytest .

[testenv:lint]
basepython = python3.9
basepython = python3.11
commands =
pip install -e '.[dev,sqlite,redis]'
pylint --reports=n --rcfile=.pylintrc postfix_mta_sts_resolver

[testenv:cover]
passenv = TOXENV
basepython = python3.9
basepython = python3.11
commands =
pip install -e ".[dev,sqlite,redis]"
pip install -e ".[dev,sqlite,redis,postgres]"
pytest --cov . --cov-append --cov-report= .
coverage report --fail-under=97 --include="postfix_mta_sts_resolver/*" --show-missing
coverage report --fail-under=90 --include="postfix_mta_sts_resolver/*" --show-missing

0 comments on commit c647342

Please sign in to comment.