Skip to content

Commit b1ab4cd

Browse files
committed
python27 compatibility + representation
1 parent b9d9ba3 commit b1ab4cd

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

gladiator/commons.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def __init__(self, type_, validator, obj, selector, ctx, **kw):
2222
self.results = kw.pop('results', [])
2323
self.kw = kw
2424

25+
def __nonzero__(self):
26+
return self.__bool__()
27+
2528
def __bool__(self):
2629
raise NotImplemented
2730

@@ -53,12 +56,23 @@ def _error_list(self):
5356
err_list = []
5457
for r in self.results:
5558
if not r.success:
56-
if r.type_ == 'primitive':
59+
if r.type_ == ValidatorType.primitive:
5760
err_list.append((selector_as_string(r.selector), r.error))
58-
elif r.type_ == 'composite':
61+
elif r.type_ == ValidatorType.composite:
5962
err_list += r._error_list()
6063
return err_list
6164

65+
def __repr__(self):
66+
if self.type_ == ValidatorType.primitive:
67+
return "{0}[{1}]".format(
68+
self.__class__.__name__,
69+
selector_as_string(self.selector))
70+
elif self.type_ == ValidatorType.composite:
71+
return '{0}({1}{2})'.format(
72+
self.__class__.__name__,
73+
'',
74+
', '.join([repr(r) for r in self.results]))
75+
6276

6377
class Success(ValidationResult):
6478

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py34
2+
envlist = py34,py27,py26,pypy3
33
[testenv]
44
deps=pytest # install pytest in the venvs
55
commands=py.test -s tests/ # or 'nosetests' or ...

0 commit comments

Comments
 (0)