Skip to content
Myr

Fixed a test case

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent d90f050 · Browse files · 2 files+8 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−11 removed

  • other:+8 added−11 removed

2 files+8 added−11 removed

modified:jinja2/testsuite/filters.py+2 added-2 removed
83 unmodified lines
84 '{{ 1000000000000|filesizeformat(true) }}'85 )86 out = tmpl.render()87 assert out == (88 '100 Bytes|1.0 KB|1.0 MB|1.0 GB|1000.0 GB|'89 '100 Bytes|1000 Bytes|976.6 KiB|953.7 MiB|931.3 GiB'88 '100 Bytes|0.0 kB|0.0 MB|0.0 GB|0.0 TB|100 Bytes|'89 '1000 Bytes|1.0 KiB|0.9 MiB|0.9 GiB'90 )9192 def test_first(self):93 tmpl = env.from_string('{{ foo|first }}')
256 unmodified lines
modified:jinja2/compiler.py+6 added-9 removed
125 unmodified lines
126 """Register a special name like `loop`."""127 self.undeclared.discard(name)128 self.declared.add(name)129130 def is_declared(self, name, local_only=False):130 def is_declared(self, name):131 """Check if a name is declared in this or an outer scope."""132 if name in self.declared_locally or name in self.declared_parameter:133 return True134 if local_only:135 return False134 return name in self.declared135136 def copy(self):137 return deepcopy(self)
52 unmodified lines
190 rv.identifiers = object.__new__(self.identifiers.__class__)191 rv.identifiers.__dict__.update(self.identifiers.__dict__)192 return rv193196 def inspect(self, nodes, hard_scope=False):194 def inspect(self, nodes):195 """Walk the node and check for identifiers. If the scope is hard (eg:196 enforce on a python level) overrides from outer scopes are tracked197 differently.198 """201 visitor = FrameIdentifierVisitor(self.identifiers, hard_scope)199 visitor = FrameIdentifierVisitor(self.identifiers)200 for node in nodes:201 visitor.visit(node)202203 def find_shadowed(self, extra=()):
68 unmodified lines
272273class FrameIdentifierVisitor(NodeVisitor):274 """A visitor for `Frame.inspect`."""275278 def __init__(self, identifiers, hard_scope):276 def __init__(self, identifiers):277 self.identifiers = identifiers280 self.hard_scope = hard_scope278279 def visit_Name(self, node):280 """All assignments to names go through this function."""281 if node.ctx == 'store':282 self.identifiers.declared_locally.add(node.name)283 elif node.ctx == 'param':284 self.identifiers.declared_parameter.add(node.name)285 elif node.ctx == 'load' and not \289 self.identifiers.is_declared(node.name, self.hard_scope):286 self.identifiers.is_declared(node.name):287 self.identifiers.undeclared.add(node.name)288289 def visit_If(self, node):290 self.visit(node.test)
363 unmodified lines
654 if children is None:655 children = node.iter_child_nodes()656 children = list(children)657 func_frame = frame.inner()661 func_frame.inspect(children, hard_scope=True)658 func_frame.inspect(children)659660 # variables that are undeclared (accessed before declaration) and661 # declared locally *and* part of an outside scope raise a template662 # assertion error. Reason: we can't generate reasonable code from
987 unmodified lines