Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin committed Aug 26, 2024
1 parent db453d8 commit 4cc9c55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_logic(self):
output = render(template, {}).strip()
assert_dom_equal(
output,
'<div class="test1 test2 test3 ring-slate-900/5 dark:bg-slate-800 %}"></div>',
'<div class="test1 test2 test3 ring-slate-900/5 dark:bg-slate-800"></div>',
)


Expand Down
14 changes: 14 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
from bs4 import BeautifulSoup


def normalize_classes(soup):
"""Normalize the order of CSS classes in the BeautifulSoup object."""
for tag in soup.find_all(class_=True):
classes = tag.get("class", [])
sorted_classes = sorted(classes)
tag["class"] = " ".join(sorted_classes)
return soup


def assert_dom_equal(expected_html, actual_html):
"""Assert that two HTML strings are equal, ignoring differences in class order."""
expected_soup = BeautifulSoup(expected_html, "html.parser")
actual_soup = BeautifulSoup(actual_html, "html.parser")

# Normalize the class attribute order
expected_soup = normalize_classes(expected_soup)
actual_soup = normalize_classes(actual_soup)

expected_str = expected_soup.prettify()
actual_str = actual_soup.prettify()

Expand Down

0 comments on commit 4cc9c55

Please sign in to comment.