summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsebres <serg.brester@sebres.de>2018-07-04 19:06:41 +0200
committersebres <serg.brester@sebres.de>2018-07-04 20:16:11 +0200
commit3be82a9ce9a6a090d0f4e728122b06cf918215a8 (patch)
treee4cc54b85ce8a6afb0388f63f00ecb6ccb87ed2b
parent5a4b47464bda7cfa9d54ac23efeea64ddfcac18e (diff)
downloadfail2ban-3be82a9ce9a6a090d0f4e728122b06cf918215a8.tar.gz
coverage
-rw-r--r--.coveragerc5
-rw-r--r--.travis.yml15
-rw-r--r--fail2ban/helpers.py8
-rw-r--r--fail2ban/server/action.py2
-rw-r--r--fail2ban/server/actions.py2
-rw-r--r--fail2ban/server/database.py16
-rw-r--r--fail2ban/tests/misctestcase.py12
7 files changed, 37 insertions, 23 deletions
diff --git a/.coveragerc b/.coveragerc
index 19bc3db4..442ddb82 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -7,5 +7,6 @@ source =
[report]
exclude_lines =
- pragma: no cover
- pragma: systemd no cover
+ pragma: ?no ?cover
+ pragma: ?${F2B_PY}.x no ?cover
+ pragma: ?systemd no ?cover
diff --git a/.travis.yml b/.travis.yml
index 0c611a95..16a71249 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,8 +18,9 @@ python:
- pypy3.3-5.5-alpha
before_install:
- 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 == 3* || $TRAVIS_PYTHON_VERSION == pypy3* ]]; then export F2B_PY_3=true && echo "Set F2B_PY_3"; 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; fi
+ - echo "Set F2B_PY=$F2B_PY"
- travis_retry sudo apt-get update -qq
# Set this so sudo executes the correct python binary
# Anything not using sudo will already have the correct environment
@@ -31,20 +32,20 @@ install:
# coveralls
- travis_retry pip install coveralls codecov
# dnspython or dnspython3
- - 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" = 2 ]]; then travis_retry pip install dnspython; 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
- 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
- travis_retry pip install pyinotify
before_script:
# Manually execute 2to3 for now
- - if [[ "$F2B_PY_3" ]]; then ./fail2ban-2to3; fi
+ - if [[ "$F2B_PY" = 3 ]]; then ./fail2ban-2to3; fi
script:
# 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)
- - 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)
- sudo $VENV_BIN/pip install .
# Doc files should get installed on Travis under Linux
diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py
index 9a07dc81..11dec5aa 100644
--- a/fail2ban/helpers.py
+++ b/fail2ban/helpers.py
@@ -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,
# caused by implicit converting of string/unicode (e. g. `str(u"\uFFFD")` produces an error
# 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):
def __resetDefaultEncoding(encoding):
global PREFER_ENC
@@ -56,7 +56,7 @@ if sys.version_info < (3,): # python >= 2.6
try:
from imp import load_dynamic as __ldm
_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)
_sys = sys
if hasattr(_sys, "setdefaultencoding"):
@@ -78,7 +78,7 @@ if sys.version_info < (3,): # python >= 2.6
# [True, True, False]; # -- python2
# [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'):
try:
if isinstance(x, bytes):
@@ -92,7 +92,7 @@ if sys.version_info >= (3,):
if not isinstance(x, bytes):
return str(x)
return x.decode(PREFER_ENC, 'replace')
-else:
+else: # pragma: 3.x no cover
def uni_decode(x, enc=PREFER_ENC, errors='strict'):
try:
if isinstance(x, unicode):
diff --git a/fail2ban/server/action.py b/fail2ban/server/action.py
index 957d0d7d..10d1acd9 100644
--- a/fail2ban/server/action.py
+++ b/fail2ban/server/action.py
@@ -173,7 +173,7 @@ class CallingMap(MutableMapping, object):
def __len__(self):
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))
diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py
index f7cb6ce6..1c095249 100644
--- a/fail2ban/server/actions.py
+++ b/fail2ban/server/actions.py
@@ -323,7 +323,7 @@ class Actions(JailThread, Mapping):
self.immutable = immutable
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())
def _mi4ip(self, overalljails=False):
diff --git a/fail2ban/server/database.py b/fail2ban/server/database.py
index e8832c09..5536f1e6 100644
--- a/fail2ban/server/database.py
+++ b/fail2ban/server/database.py
@@ -45,7 +45,7 @@ def _json_default(x):
x = list(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):
try:
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)
try:
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
- except: pass
+ except: # pragma: no cover
+ pass
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)
try:
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
- except: pass
+ except: # pragma: no cover
+ pass
x = {}
return x
-else:
+else: # pragma: 3.x no cover
def _normalize(x):
if isinstance(x, dict):
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)
try:
logSys.error('json dumps failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
- except: pass
+ except: # pragma: no cover
+ pass
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)
try:
logSys.error('json loads failed: %r', e, exc_info=logSys.getEffectiveLevel() <= 4)
- except: pass
+ except: # pragma: no cover
+ pass
x = {}
return x
diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py
index 5f0e70e4..707b6423 100644
--- a/fail2ban/tests/misctestcase.py
+++ b/fail2ban/tests/misctestcase.py
@@ -33,8 +33,8 @@ from StringIO import StringIO
from utils import LogCaptureTestCase, logSys as DefLogSys
-from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger, uni_decode
-from ..helpers import splitwords
+from ..helpers import formatExceptionInfo, mbasename, TraceBack, FormatterWithTraceBack, getLogger, \
+ splitwords, uni_decode, uni_string
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"), '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):
# pretty much just a smoke test since tests runners swallow all the detail