def __unicode__(self): if self._undefined_name is None: return '' missing.append(self._undefined_name) if kwargs['debug']: return '[Undefined] %s' % self._undefined_name return DebugUndefined.__unicode__(self)
def test_debug_undefined(self): env = Environment(undefined=DebugUndefined) assert env.from_string('{{ missing }}').render() == '{{ missing }}' pytest.raises(UndefinedError, env.from_string('{{ missing.attribute }}').render) assert env.from_string('{{ missing|list }}').render() == '[]' assert env.from_string('{{ missing is not defined }}').render() \ == 'True' assert env.from_string('{{ foo.missing }}').render(foo=42) \ == u"{{ no such element: int object['missing'] }}" assert env.from_string('{{ not missing }}').render() == 'True' undefined_hint = 'this is testing undefined hint of DebugUndefined' assert str(DebugUndefined(hint=undefined_hint)) == u'{{ undefined value printed: %s }}' % undefined_hint with pytest.raises(AttributeError): getattr(DebugUndefined, '__slots__')
def test_debug_undefined(self): env = Environment(undefined=DebugUndefined) assert env.from_string("{{ missing }}").render() == "{{ missing }}" pytest.raises(UndefinedError, env.from_string("{{ missing.attribute }}").render) assert env.from_string("{{ missing|list }}").render() == "[]" assert env.from_string( "{{ missing is not defined }}").render() == "True" assert (env.from_string("{{ foo.missing }}").render( foo=42) == "{{ no such element: int object['missing'] }}") assert env.from_string("{{ not missing }}").render() == "True" undefined_hint = "this is testing undefined hint of DebugUndefined" assert (str(DebugUndefined(hint=undefined_hint)) == f"{{{{ undefined value printed: {undefined_hint} }}}}") with pytest.raises(AttributeError): getattr(DebugUndefined, "__slots__") # noqa: B009
def __getattribute__(self, name): if name[0] == '_': return DebugUndefined.__getattribute__(self, name) missing.append(self._undefined_name) return MissingUndefined(name=name)
def __getattribute__(self, name): if name[0] == '_': return DebugUndefined.__getattribute__(self, name) info.undefined.append(self._undefined_name) return MissingUndefined(name=name)