def test_validate_attrs(): from xoutil.objects import validate_attrs class Person(object): def __init__(self, **kwargs): for which in kwargs: setattr(self, which, kwargs[which]) source = Person(name='Manuel', age=33, sex='male') target = {'name': 'Manuel', 'age': 4, 'sex': 'male'} assert validate_attrs(source, target, force_equals=('sex',), force_differents=('age',)) assert not validate_attrs(source, target, force_equals=('age',))
def __eq__(self, other): ''' >>> with context(UNPROXIFING_CONTEXT): ... this('parent') == this('parent') True >>> from xotl.ql.expressions import _true >>> (this('parent') == this('parent')) is _true True ''' from xotl.ql.expressions import eq with context(UNPROXIFING_CONTEXT): if isinstance(other, Term): res = validate_attrs(self, other, ('name', 'parent')) else: res = False if context[UNPROXIFING_CONTEXT]: return res else: if not res: return eq(self, other) else: # In logic A == A is always true so we don't produce nothing # for it. return _true
def __ne__(self, other): ''' >>> with context(UNPROXIFING_CONTEXT): ... this('parent') != this('parent') False >>> from xotl.ql.expressions import _false >>> (this('parent') != this('parent')) is _false True ''' from xotl.ql.expressions import ne with context(UNPROXIFING_CONTEXT): if isinstance(other, Term): res = validate_attrs(self, other, ('name', 'parent')) else: res = False if context[UNPROXIFING_CONTEXT]: return not res else: if not res: return ne(self, other) else: return _false
def __eq__(self, other): from xoutil.objects import validate_attrs return validate_attrs(self, other, force_equals=BaseInstruction._fields)