summaryrefslogtreecommitdiff
path: root/lib/ansible/plugins/test
diff options
context:
space:
mode:
authorDag Wieers <dag@wieers.com>2017-06-02 13:14:11 +0200
committerJohn R Barker <john@johnrbarker.com>2017-06-02 12:14:11 +0100
commit5553b208281d723ead1e61be5c37227ec2b2736e (patch)
tree2f81e684e9f4451a3b1b58b95e1d00125b34e439 /lib/ansible/plugins/test
parent2f33c1a1a1d0c74d31445984fd85d877f0d8ab59 (diff)
downloadansible-5553b208281d723ead1e61be5c37227ec2b2736e.tar.gz
Collated PEP8 fixes (#25293)
- Make PEP8 compliant
Diffstat (limited to 'lib/ansible/plugins/test')
-rw-r--r--lib/ansible/plugins/test/core.py37
-rw-r--r--lib/ansible/plugins/test/files.py17
-rw-r--r--lib/ansible/plugins/test/mathstuff.py4
3 files changed, 37 insertions, 21 deletions
diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py
index 59244dc8c1..7440b2197f 100644
--- a/lib/ansible/plugins/test/core.py
+++ b/lib/ansible/plugins/test/core.py
@@ -26,38 +26,44 @@ from distutils.version import LooseVersion, StrictVersion
from ansible import errors
+
def failed(*a, **kw):
''' Test if task result yields failed '''
item = a[0]
if not isinstance(item, MutableMapping):
raise errors.AnsibleFilterError("|failed expects a dictionary")
- rc = item.get('rc',0)
- failed = item.get('failed',False)
+ rc = item.get('rc', 0)
+ failed = item.get('failed', False)
if rc != 0 or failed:
return True
else:
return False
+
def success(*a, **kw):
''' Test if task result yields success '''
return not failed(*a, **kw)
+
def changed(*a, **kw):
''' Test if task result yields changed '''
item = a[0]
if not isinstance(item, MutableMapping):
raise errors.AnsibleFilterError("|changed expects a dictionary")
- if not 'changed' in item:
+ if 'changed' not in item:
changed = False
- if ('results' in item # some modules return a 'results' key
- and isinstance(item['results'], MutableSequence)
- and isinstance(item['results'][0], MutableMapping)):
+ if (
+ 'results' in item and # some modules return a 'results' key
+ isinstance(item['results'], MutableSequence) and
+ isinstance(item['results'][0], MutableMapping)
+ ):
for result in item['results']:
changed = changed or result.get('changed', False)
else:
changed = item.get('changed', False)
return changed
+
def skipped(*a, **kw):
''' Test if task result yields skipped '''
item = a[0]
@@ -66,6 +72,7 @@ def skipped(*a, **kw):
skipped = item.get('skipped', False)
return skipped
+
def regex(value='', pattern='', ignorecase=False, multiline=False, match_type='search'):
''' Expose `re` as a boolean filter using the `search` method by default.
This is likely only useful for `search` and `match` which already
@@ -80,21 +87,24 @@ def regex(value='', pattern='', ignorecase=False, multiline=False, match_type='s
_bool = __builtins__.get('bool')
return _bool(getattr(_re, match_type, 'search')(value))
+
def match(value, pattern='', ignorecase=False, multiline=False):
''' Perform a `re.match` returning a boolean '''
return regex(value, pattern, ignorecase, multiline, 'match')
+
def search(value, pattern='', ignorecase=False, multiline=False):
''' Perform a `re.search` returning a boolean '''
return regex(value, pattern, ignorecase, multiline, 'search')
+
def version_compare(value, version, operator='eq', strict=False):
''' Perform a version comparison on a value '''
op_map = {
- '==': 'eq', '=': 'eq', 'eq': 'eq',
- '<': 'lt', 'lt': 'lt',
+ '==': 'eq', '=': 'eq', 'eq': 'eq',
+ '<': 'lt', 'lt': 'lt',
'<=': 'le', 'le': 'le',
- '>': 'gt', 'gt': 'gt',
+ '>': 'gt', 'gt': 'gt',
'>=': 'ge', 'ge': 'ge',
'!=': 'ne', '<>': 'ne', 'ne': 'ne'
}
@@ -115,20 +125,21 @@ def version_compare(value, version, operator='eq', strict=False):
except Exception as e:
raise errors.AnsibleFilterError('Version comparison: %s' % e)
+
class TestModule(object):
''' Ansible core jinja2 tests '''
def tests(self):
return {
# failure testing
- 'failed' : failed,
- 'succeeded' : success,
+ 'failed': failed,
+ 'succeeded': success,
# changed testing
- 'changed' : changed,
+ 'changed': changed,
# skip testing
- 'skipped' : skipped,
+ 'skipped': skipped,
# regex
'match': match,
diff --git a/lib/ansible/plugins/test/files.py b/lib/ansible/plugins/test/files.py
index 5ab5788e01..9d6695fc5e 100644
--- a/lib/ansible/plugins/test/files.py
+++ b/lib/ansible/plugins/test/files.py
@@ -22,20 +22,21 @@ __metaclass__ = type
from os.path import isdir, isfile, isabs, exists, lexists, islink, samefile, ismount
from ansible import errors
+
class TestModule(object):
''' Ansible file jinja2 tests '''
def tests(self):
return {
# file testing
- 'is_dir' : isdir,
- 'is_file' : isfile,
- 'is_link' : islink,
- 'exists' : exists,
- 'link_exists' : lexists,
+ 'is_dir': isdir,
+ 'is_file': isfile,
+ 'is_link': islink,
+ 'exists': exists,
+ 'link_exists': lexists,
# path testing
- 'is_abs' : isabs,
- 'is_same_file' : samefile,
- 'is_mount' : ismount,
+ 'is_abs': isabs,
+ 'is_same_file': samefile,
+ 'is_mount': ismount,
}
diff --git a/lib/ansible/plugins/test/mathstuff.py b/lib/ansible/plugins/test/mathstuff.py
index c736bbe6b6..0a64f52674 100644
--- a/lib/ansible/plugins/test/mathstuff.py
+++ b/lib/ansible/plugins/test/mathstuff.py
@@ -20,18 +20,22 @@ __metaclass__ = type
import math
+
def issubset(a, b):
return set(a) <= set(b)
+
def issuperset(a, b):
return set(a) >= set(b)
+
def isnotanumber(x):
try:
return math.isnan(x)
except TypeError:
return False
+
class TestModule:
''' Ansible math jinja2 tests '''