Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lazy_item_access__should_fail_with_unknown_module(self):
lazy_dict = LazyDict({"bob": LazyObject("__unknown_module__", "xxx")})
item_access = lambda key: lazy_dict[key]
assert_raises(ImportError, item_access, "bob")
def test_get__should_succeed_for_known_object(self):
lazy = LazyObject("behave.importer", "LazyObject")
value = lazy.get()
assert value is LazyObject
lazy2 = LazyObject("behave.importer:LazyObject")
value2 = lazy2.get()
assert value2 is LazyObject
lazy3 = LazyObject("behave.formatter.steps", "StepsFormatter")
value3 = lazy3.get()
assert issubclass(value3, Formatter)
def test_get__should_succeed_for_known_object(self):
lazy = LazyObject("behave.importer", "LazyObject")
value = lazy.get()
assert value is LazyObject
lazy2 = LazyObject("behave.importer:LazyObject")
value2 = lazy2.get()
assert value2 is LazyObject
lazy3 = LazyObject("behave.formatter.steps", "StepsFormatter")
value3 = lazy3.get()
assert issubclass(value3, Formatter)
def test_get__should_succeed_for_known_object(self):
lazy = LazyObject("behave.importer", "LazyObject")
value = lazy.get()
assert value is LazyObject
lazy2 = LazyObject("behave.importer:LazyObject")
value2 = lazy2.get()
assert value2 is LazyObject
lazy3 = LazyObject("behave.formatter.steps", "StepsFormatter")
value3 = lazy3.get()
assert issubclass(value3, Formatter)
def assert_is_not_lazy_object(obj):
assert not isinstance(obj, LazyObject)
def test_get__should_succeed_for_known_object(self):
lazy = LazyObject("behave.importer", "LazyObject")
value = lazy.get()
assert value is LazyObject
lazy2 = LazyObject("behave.importer:LazyObject")
value2 = lazy2.get()
assert value2 is LazyObject
lazy3 = LazyObject("behave.formatter.steps", "StepsFormatter")
value3 = lazy3.get()
assert issubclass(value3, Formatter)
def test_lazy_item_access__should_fail_with_unknown_object(self):
lazy_dict = LazyDict({
"bob": LazyObject("behave.importer", "XUnknown")
})
item_access = lambda key: lazy_dict[key]
assert_raises(ImportError, item_access, "bob")
def test_get__should_fail_for_unknown_object_in_module(self):
lazy = LazyObject("behave.textutil", "xxx")
assert_raises(ImportError, lazy.get)
.. since:: 1.2.5
Parameter ordering starts with name.
"""
if not isinstance(name, six.string_types):
# -- REORDER-PARAMS: Used old ordering before behave-1.2.5 (2015).
warnings.warn("Use parameter ordering: name, formatter_class (for: %s)"\
% formatter_class)
_formatter_class = name
name = formatter_class
formatter_class = _formatter_class
if isinstance(formatter_class, six.string_types):
# -- SPEEDUP-STARTUP: Only import formatter_class when used.
scoped_formatter_class_name = formatter_class
formatter_class = LazyObject(scoped_formatter_class_name)
assert (isinstance(formatter_class, LazyObject) or
issubclass(formatter_class, Formatter))
_formatter_registry[name] = formatter_class