Skip to content

Commit

Permalink
fix STRICT_MODE control in render
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jan 27, 2024
1 parent e141ad6 commit e0fa946
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions htag/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ def __str__(self):

if self.root.STRICT_MODE: # added at htag > 0.72.0
# in STRICT_MODE: will control that the render method is not called at each interaction
current_children = [id(i) for i in self._childs]
current_children = [id(i) for i in self._childs if isinstance(i,Tag)]
render()
if current_children != [id(i) for i in self._childs]:
if current_children != [id(i) for i in self._childs if isinstance(i,Tag)]:
# the rendering is done at each interaction (bad practice)
raise HTagException(f"[STRICT_MODE] In {repr(self)}, the render() method has changed its children!")
else:
Expand Down
9 changes: 4 additions & 5 deletions test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,12 @@ def render(self):
with pytest.raises(HTagException):
print( Bad() )

#--------------------------------- a bad case
class Bad2(Tag.div):
#--------------------------------- a good case
class Good2(Tag.div):
def render(self):
self += "simple text is enough"
self += "simple text is not enough !!!"

with pytest.raises(HTagException):
print( Bad2() )
print( Good2() )

finally:
Tag.STRICT_MODE = False
Expand Down

0 comments on commit e0fa946

Please sign in to comment.