mirror of https://github.com/fail2ban/fail2ban
coverage
parent
5a4b47464b
commit
3be82a9ce9
|
@ -7,5 +7,6 @@ source =
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
pragma: no cover
|
pragma: ?no ?cover
|
||||||
pragma: systemd no cover
|
pragma: ?${F2B_PY}.x no ?cover
|
||||||
|
pragma: ?systemd no ?cover
|
||||||
|
|
15
.travis.yml
15
.travis.yml
|
@ -18,8 +18,9 @@ python:
|
||||||
- pypy3.3-5.5-alpha
|
- pypy3.3-5.5-alpha
|
||||||
before_install:
|
before_install:
|
||||||
- echo "running under $TRAVIS_PYTHON_VERSION"
|
- echo "running under $TRAVIS_PYTHON_VERSION"
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == 2* || $TRAVIS_PYTHON_VERSION == pypy* && $TRAVIS_PYTHON_VERSION != pypy3* ]]; then export F2B_PY_2=true && echo "Set F2B_PY_2"; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == 2* || $TRAVIS_PYTHON_VERSION == pypy* && $TRAVIS_PYTHON_VERSION != pypy3* ]]; then export F2B_PY=2; fi
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == 3* || $TRAVIS_PYTHON_VERSION == pypy3* ]]; then export F2B_PY_3=true && echo "Set F2B_PY_3"; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == 3* || $TRAVIS_PYTHON_VERSION == pypy3* ]]; then export F2B_PY=3; fi
|
||||||
|
- echo "Set F2B_PY=$F2B_PY"
|
||||||
- travis_retry sudo apt-get update -qq
|
- travis_retry sudo apt-get update -qq
|
||||||
# Set this so sudo executes the correct python binary
|
# Set this so sudo executes the correct python binary
|
||||||
# Anything not using sudo will already have the correct environment
|
# Anything not using sudo will already have the correct environment
|
||||||
|
@ -31,20 +32,20 @@ install:
|
||||||
# coveralls
|
# coveralls
|
||||||
- travis_retry pip install coveralls codecov
|
- travis_retry pip install coveralls codecov
|
||||||
# dnspython or dnspython3
|
# dnspython or dnspython3
|
||||||
- if [[ "$F2B_PY_2" ]]; then travis_retry pip install dnspython; fi
|
- if [[ "$F2B_PY" = 2 ]]; then travis_retry pip install dnspython; fi
|
||||||
- if [[ "$F2B_PY_3" ]]; then travis_retry pip install dnspython3; fi
|
- if [[ "$F2B_PY" = 3 ]]; then travis_retry pip install dnspython3; fi
|
||||||
# gamin - install manually (not in PyPI) - travis-ci system Python is 2.7
|
# gamin - install manually (not in PyPI) - travis-ci system Python is 2.7
|
||||||
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then travis_retry sudo apt-get install -qq python-gamin && cp /usr/share/pyshared/gamin.py /usr/lib/pyshared/python2.7/_gamin.so $VIRTUAL_ENV/lib/python2.7/site-packages/; fi
|
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then travis_retry sudo apt-get install -qq python-gamin && cp /usr/share/pyshared/gamin.py /usr/lib/pyshared/python2.7/_gamin.so $VIRTUAL_ENV/lib/python2.7/site-packages/; fi
|
||||||
# pyinotify
|
# pyinotify
|
||||||
- travis_retry pip install pyinotify
|
- travis_retry pip install pyinotify
|
||||||
before_script:
|
before_script:
|
||||||
# Manually execute 2to3 for now
|
# Manually execute 2to3 for now
|
||||||
- if [[ "$F2B_PY_3" ]]; then ./fail2ban-2to3; fi
|
- if [[ "$F2B_PY" = 3 ]]; then ./fail2ban-2to3; fi
|
||||||
script:
|
script:
|
||||||
# Keep the legacy setup.py test approach of checking coverage for python2
|
# Keep the legacy setup.py test approach of checking coverage for python2
|
||||||
- if [[ "$F2B_PY_2" ]]; then coverage run setup.py test; fi
|
- if [[ "$F2B_PY" = 2 ]]; then coverage run setup.py test; fi
|
||||||
# Coverage doesn't pick up setup.py test with python3, so run it directly (with same verbosity as from setup)
|
# Coverage doesn't pick up setup.py test with python3, so run it directly (with same verbosity as from setup)
|
||||||
- if [[ "$F2B_PY_3" ]]; then coverage run bin/fail2ban-testcases --verbosity=2; fi
|
- if [[ "$F2B_PY" = 3 ]]; then coverage run bin/fail2ban-testcases --verbosity=2; fi
|
||||||
# Use $VENV_BIN (not python) or else sudo will always run the system's python (2.7)
|
# Use $VENV_BIN (not python) or else sudo will always run the system's python (2.7)
|
||||||
- sudo $VENV_BIN/pip install .
|
- sudo $VENV_BIN/pip install .
|
||||||
# Doc files should get installed on Travis under Linux
|
# Doc files should get installed on Travis under Linux
|
||||||
|
|
|
@ -44,7 +44,7 @@ if PREFER_ENC.startswith('ANSI_'): # pragma: no cover
|
||||||
# py-2.x: try to minimize influence of sporadic conversion errors on python 2.x,
|
# py-2.x: try to minimize influence of sporadic conversion errors on python 2.x,
|
||||||
# caused by implicit converting of string/unicode (e. g. `str(u"\uFFFD")` produces an error
|
# caused by implicit converting of string/unicode (e. g. `str(u"\uFFFD")` produces an error
|
||||||
# if default encoding is 'ascii');
|
# if default encoding is 'ascii');
|
||||||
if sys.version_info < (3,): # python >= 2.6
|
if sys.version_info < (3,): # pragma: 3.x no cover
|
||||||
# correct default (global system) encoding (mostly UTF-8):
|
# correct default (global system) encoding (mostly UTF-8):
|
||||||
def __resetDefaultEncoding(encoding):
|
def __resetDefaultEncoding(encoding):
|
||||||
global PREFER_ENC
|
global PREFER_ENC
|
||||||
|
@ -56,7 +56,7 @@ if sys.version_info < (3,): # python >= 2.6
|
||||||
try:
|
try:
|
||||||
from imp import load_dynamic as __ldm
|
from imp import load_dynamic as __ldm
|
||||||
_sys = __ldm('_sys', 'sys')
|
_sys = __ldm('_sys', 'sys')
|
||||||
except ImportError: # pragma: no cover (only if load_dynamic fails)
|
except ImportError: # pragma: no cover - only if load_dynamic fails
|
||||||
reload(sys)
|
reload(sys)
|
||||||
_sys = sys
|
_sys = sys
|
||||||
if hasattr(_sys, "setdefaultencoding"):
|
if hasattr(_sys, "setdefaultencoding"):
|
||||||
|
@ -78,7 +78,7 @@ if sys.version_info < (3,): # python >= 2.6
|
||||||
# [True, True, False]; # -- python2
|
# [True, True, False]; # -- python2
|
||||||
# [True, False, True]; # -- python3
|
# [True, False, True]; # -- python3
|
||||||
#
|
#
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,): # pragma: 2.x no cover
|
||||||
def uni_decode(x, enc=PREFER_ENC, errors='strict'):
|
def uni_decode(x, enc=PREFER_ENC, errors='strict'):
|
||||||
try:
|
try:
|
||||||
if isinstance(x, bytes):
|
if isinstance(x, bytes):
|
||||||
|
@ -92,7 +92,7 @@ if sys.version_info >= (3,):
|
||||||
if not isinstance(x, bytes):
|
if not isinstance(x, bytes):
|
||||||
return str(x)
|
return str(x)
|
||||||
return x.decode(PREFER_ENC, 'replace')
|
return x.decode(PREFER_ENC, 'replace')
|
||||||
else:
|
else: # pragma: 3.x no cover
|
||||||
def uni_decode(x, enc=PREFER_ENC, errors='strict'):
|
def uni_decode(x, enc=PREFER_ENC, errors='strict'):
|
||||||
try:
|
try:
|
||||||
if isinstance(x, unicode):
|
if isinstance(x, unicode):
|
||||||
|
|
|
@ -173,7 +173,7 @@ class CallingMap(MutableMapping, object):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.data)
|
return len(self.data)
|
||||||
|
|
||||||
def copy(self): # pargma: no cover
|
def copy(self): # pragma: no cover
|
||||||
return self.__class__(_merge_copy_dicts(self.data, self.storage))
|
return self.__class__(_merge_copy_dicts(self.data, self.storage))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ class Actions(JailThread, Mapping):
|
||||||
self.immutable = immutable
|
self.immutable = immutable
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def copy(self): # pargma: no cover
|
def copy(self): # pragma: no cover
|
||||||
return self.__class__(self.__ticket, self.__jail, self.immutable, self.data.copy())
|
return self.__class__(self.__ticket, self.__jail, self.immutable, self.data.copy())
|
||||||
|
|
||||||
def _mi4ip(self, overalljails=False):
|
def _mi4ip(self, overalljails=False):
|
||||||
|
|
|
@ -45,7 +45,7 @@ def _json_default(x):
|
||||||
x = list(x)
|
x = list(x)
|
||||||
return uni_string(x)
|
return uni_string(x)
|
||||||
|
|
||||||
if sys.version_info >= (3,):
|
if sys.version_info >= (3,): # pragma: 2.x no cover
|
||||||
def _json_dumps_safe(x):
|
def _json_dumps_safe(x):
|
||||||
try:
|
try:
|
||||||
x = json.dumps(x, ensure_ascii=False, default=_json_default).encode(
|
x = json.dumps(x, ensure_ascii=False, default=_json_default).encode(
|
||||||
|
@ -54,7 +54,8 @@ if sys.version_info >= (3,):
|
||||||
# adapter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
# adapter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
||||||
try:
|
try:
|
||||||
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
||||||
except: pass
|
except: # pragma: no cover
|
||||||
|
pass
|
||||||
x = '{}'
|
x = '{}'
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
@ -65,10 +66,11 @@ if sys.version_info >= (3,):
|
||||||
# converter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
# converter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
||||||
try:
|
try:
|
||||||
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
||||||
except: pass
|
except: # pragma: no cover
|
||||||
|
pass
|
||||||
x = {}
|
x = {}
|
||||||
return x
|
return x
|
||||||
else:
|
else: # pragma: 3.x no cover
|
||||||
def _normalize(x):
|
def _normalize(x):
|
||||||
if isinstance(x, dict):
|
if isinstance(x, dict):
|
||||||
return dict((_normalize(k), _normalize(v)) for k, v in x.iteritems())
|
return dict((_normalize(k), _normalize(v)) for k, v in x.iteritems())
|
||||||
|
@ -88,7 +90,8 @@ else:
|
||||||
# adapter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
# adapter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
||||||
try:
|
try:
|
||||||
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
||||||
except: pass
|
except: # pragma: no cover
|
||||||
|
pass
|
||||||
x = '{}'
|
x = '{}'
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
@ -99,7 +102,8 @@ else:
|
||||||
# converter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
# converter handler should be exception-safe, so avoid possible errors in log-handlers (concat, str. conversion, etc)
|
||||||
try:
|
try:
|
||||||
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
|
||||||
except: pass
|
except: # pragma: no cover
|
||||||
|
pass
|
||||||
x = {}
|
x = {}
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@ from StringIO import StringIO
|
||||||
|
|
||||||
from utils import LogCaptureTestCase, logSys as DefLogSys
|
from utils import LogCaptureTestCase, logSys as DefLogSys
|
||||||
|
|
||||||
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger, uni_decode
|
from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger, \
|
||||||
from ..helpers import splitwords
|
splitwords, uni_decode, uni_string
|
||||||
from ..server.mytime import MyTime
|
from ..server.mytime import MyTime
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,6 +193,14 @@ class TestsUtilsTest(LogCaptureTestCase):
|
||||||
self.assertEqual(mbasename("/long/path/base.py"), 'path.base')
|
self.assertEqual(mbasename("/long/path/base.py"), 'path.base')
|
||||||
self.assertEqual(mbasename("/long/path/base"), 'path.base')
|
self.assertEqual(mbasename("/long/path/base"), 'path.base')
|
||||||
|
|
||||||
|
def testUniConverters(self):
|
||||||
|
self.assertRaises(Exception, uni_decode,
|
||||||
|
(b'test' if sys.version_info >= (3,) else u'test'), 'f2b-test::non-existing-encoding')
|
||||||
|
uni_decode((b'test\xcf' if sys.version_info >= (3,) else u'test\xcf'))
|
||||||
|
uni_string(b'test\xcf')
|
||||||
|
uni_string('test\xcf')
|
||||||
|
uni_string(u'test\xcf')
|
||||||
|
|
||||||
def testTraceBack(self):
|
def testTraceBack(self):
|
||||||
# pretty much just a smoke test since tests runners swallow all the detail
|
# pretty much just a smoke test since tests runners swallow all the detail
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue