Skip to content

Commit c4c8963

Browse files
Exclude base classes from code gen tests
1 parent 356f687 commit c4c8963

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/code_gen_test.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,34 @@
55
66
These don't regenerate the code, but rather test code that has been generated
77
"""
8+
89
import pytest
910

1011
import pyhtml
11-
from pyhtml import Comment, DangerousRawHtml, Tag, html
12+
from pyhtml import (
13+
Comment,
14+
DangerousRawHtml,
15+
SelfClosingTag,
16+
Tag,
17+
WhitespaceSensitiveTag,
18+
html,
19+
)
1220

1321
all_tags = [
1422
getattr(pyhtml, i)
1523
for i in dir(pyhtml)
1624
if (
1725
# Ignore __dunder__ items
18-
not i.startswith('__')
26+
not i.startswith("__")
1927
# Only look at classes
2028
and type(getattr(pyhtml, i)) is type
2129
# That are a kind of Tag
2230
and issubclass(getattr(pyhtml, i), Tag)
23-
# And aren't a PyHTML feature (since comments require named args)
31+
# Aren't a PyHTML-specific feature
2432
and not issubclass(getattr(pyhtml, i), Comment | DangerousRawHtml)
33+
# Aren't a base class
34+
and getattr(pyhtml, i)
35+
not in [Tag, SelfClosingTag, WhitespaceSensitiveTag]
2536
# And isn't <html> since it has pre-content
2637
and not issubclass(getattr(pyhtml, i), html)
2738
)
@@ -33,13 +44,10 @@ def test_num_exported_members():
3344
We don't want regenerating the code to produce any more (or fewer) members
3445
"""
3546
# Just update the number if you're expecting it to change
36-
assert len(all_tags) == 117
47+
assert len(all_tags) == 114
3748

3849

39-
@pytest.mark.parametrize(
40-
'tag',
41-
all_tags
42-
)
50+
@pytest.mark.parametrize("tag", all_tags)
4351
def test_tag_renders(tag: type[Tag]):
4452
"""
4553
Test that each tag correctly renders
@@ -49,10 +57,7 @@ def test_tag_renders(tag: type[Tag]):
4957
assert str(tag()).startswith(f"<{tag()._get_tag_name()}")
5058

5159

52-
@pytest.mark.parametrize(
53-
'tag',
54-
all_tags
55-
)
60+
@pytest.mark.parametrize("tag", all_tags)
5661
def test_tag_callable(tag: type[Tag]):
5762
"""
5863
Test that each tag correctly renders after calling itself

0 commit comments

Comments
 (0)