Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if self.negative:
assert matched is None, (
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
this = AssertionBuilder('this')
the = AssertionBuilder('the')
it = AssertionBuilder('it')
these = AssertionBuilder('these')
those = AssertionBuilder('those')
expect = AssertionBuilder('expect')
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
def chain(func):
"""Extend sure with a custom chaining method."""
setattr(AssertionBuilder, func.__name__, func)
return func
def __getattr__(self, attr):
special_case = False
special_case = attr in (POSITIVES + NEGATIVES)
negative = attr in NEGATIVES
if special_case:
return AssertionBuilder(attr, negative=negative, obj=self.obj,
callable_args=self._callable_args, callable_kw=self._callable_kw)
return super(AssertionBuilder, self).__getattribute__(attr)
def method(self):
# check if the given object already has an attribute with the
# given name. If yes return it instead of patching it.
try:
if name in self.__dict__:
return self.__dict__[name]
except AttributeError:
# we do not have an object with __dict__, thus
# it's safe to just continue and patch the `name`.
pass
overwritten_object_handler = overwritten_object_handlers.get((id(self), name), None)
if overwritten_object_handler:
return overwritten_object_handler
builder = AssertionBuilder(name, negative=is_negative)
instance = builder(self)
callable_args = getattr(self, '_callable_args', ())
if callable_args:
instance._callable_args = callable_args
callable_kw = getattr(self, '_callable_kw', {})
if callable_kw:
instance._callable_kw = callable_kw
return instance
def _new_dir(*obj):
if not obj:
frame = inspect.currentframe()
return sorted(frame.f_back.f_locals.keys())
if len(obj) > 1:
raise TypeError('dir expected at most 1 arguments, got {0}'.format(len(obj)))
patched = [x for x in old_dir(obj[0]) if isinstance(getattr(obj[0], x, None), AssertionBuilder)]
return sorted(set(old_dir(obj[0])).difference(patched))
modifiers = "".join([modifiers_map.get(x, "") for x in args])
regex_representation = '/{0}/{1}'.format(regex, modifiers)
if self.negative:
assert matched is None, (
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
this = AssertionBuilder('this')
the = AssertionBuilder('the')
it = AssertionBuilder('it')
these = AssertionBuilder('these')
those = AssertionBuilder('those')
expect = AssertionBuilder('expect')
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
def chain(func):
"""Extend sure with a custom chaining method."""
regex_representation = '/{0}/{1}'.format(regex, modifiers)
if self.negative:
assert matched is None, (
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
this = AssertionBuilder('this')
the = AssertionBuilder('the')
it = AssertionBuilder('it')
these = AssertionBuilder('these')
those = AssertionBuilder('those')
expect = AssertionBuilder('expect')
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
def chain(func):
"""Extend sure with a custom chaining method."""
setattr(AssertionBuilder, func.__name__, func)
def __getattr__(self, attr):
special_case = False
special_case = attr in (POSITIVES + NEGATIVES)
negative = attr in NEGATIVES
if special_case:
return AssertionBuilder(attr, negative=negative, obj=self.obj,
callable_args=self._callable_args, callable_kw=self._callable_kw)
return super(AssertionBuilder, self).__getattribute__(attr)
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
this = AssertionBuilder('this')
the = AssertionBuilder('the')
it = AssertionBuilder('it')
these = AssertionBuilder('these')
those = AssertionBuilder('those')
expect = AssertionBuilder('expect')
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
def chain(func):
"""Extend sure with a custom chaining method."""
setattr(AssertionBuilder, func.__name__, func)
return func
def chainproperty(func):
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
if self.negative:
assert matched is None, (
"{0} should not match the regular expression {1}".format(
obj_repr, regex_representation))
else:
assert matched is not None, (
"{0} doesn't match the regular expression {1}".format(
obj_repr, regex_representation))
return True
this = AssertionBuilder('this')
the = AssertionBuilder('the')
it = AssertionBuilder('it')
these = AssertionBuilder('these')
those = AssertionBuilder('those')
expect = AssertionBuilder('expect')
def assertion(func):
"""Extend sure with a custom assertion method."""
func = assertionmethod(func)
setattr(AssertionBuilder, func.__name__, func)
return func
def chain(func):
"""Extend sure with a custom chaining method."""
setattr(AssertionBuilder, func.__name__, func)
return func