How to use build_assertion_property method in Sure

Best Python code snippet using sure_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...858 fget=method,859 fset=partial(setter, method),860 fdel=partial(deleter, method),861 )862 def build_assertion_property(name, is_negative, prop=True):863 """Build assertion property864 This is the assertion property which is usually patched865 to the built-in ``object`` and ``NoneType``.866 """867 def method(self):868 # check if the given object already has an attribute with the869 # given name. If yes return it instead of patching it.870 try:871 if name in self.__dict__:872 return self.__dict__[name]873 except AttributeError:874 # we do not have an object with __dict__, thus875 # it's safe to just continue and patch the `name`.876 pass877 overwritten_object_handler = overwritten_object_handlers.get(878 (id(self), name), None879 )880 if overwritten_object_handler:881 return overwritten_object_handler882 builder = AssertionBuilder(name, negative=is_negative)883 instance = builder(self)884 callable_args = getattr(self, "_callable_args", ())885 if callable_args:886 instance._callable_args = callable_args887 callable_kw = getattr(self, "_callable_kw", {})888 if callable_kw:889 instance._callable_kw = callable_kw890 return instance891 method.__name__ = str(name)892 return make_safe_property(method, name, prop)893 object_handler = patchable_builtin(object)894 # We have to keep track of all objects which895 # should overwrite a ``POSITIVES`` or ``NEGATIVES``896 # property. If we wouldn't do that in the897 # make_safe_property.setter method we would loose898 # the newly assigned object reference.899 overwritten_object_handlers = {}900 # None does not have a tp_dict associated to its PyObject, so this901 # is the only way we could make it work like we expected.902 none = patchable_builtin(None.__class__)903 for name in POSITIVES:904 object_handler[name] = build_assertion_property(name, is_negative=False)905 none[name] = build_assertion_property(name, is_negative=False, prop=False)906 for name in NEGATIVES:907 object_handler[name] = build_assertion_property(name, is_negative=True)908 none[name] = build_assertion_property(name, is_negative=True, prop=False)909old_dir = dir910def enable():911 @wraps(builtins.dir)912 def _new_dir(*obj):913 if not obj:914 frame = inspect.currentframe()915 return sorted(frame.f_back.f_locals.keys())916 if len(obj) > 1:917 raise TypeError(918 "dir expected at most 1 arguments, got {0}".format(len(obj))919 )920 patched = []921 try:922 import pytest...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful