"""Tests of the old-versus-new output comparison.""" import unittest import compare def page(body, footer="", head=""): return f"
{head}\n\nHello link.\n
') self.assertEqual(compare.compare_pages(html, html), []) def test_whitespace_and_attribute_order_do_not_matter(self): old = page('\nHello\n world l\n
') new = page('Hello world l
') self.assertEqual(compare.compare_pages(old, new), []) def test_a_changed_link_is_reported(self): old = page('\nx\n
') new = page('\nx\n
') diffs = compare.compare_pages(old, new) self.assertTrue(diffs) self.assertTrue(any("/a.html" in d or "/b.html" in d for d in diffs)) def test_changed_text_is_reported(self): self.assertTrue(compare.compare_pages(page("one
"), page("two
"))) def test_comments_are_compared(self): self.assertTrue(compare.compare_pages(page("x
"), page("x
"))) def test_the_footer_credit_and_generator_meta_are_ignored(self): old = page("x
", footer="\nlicense\n
") new = page("x
", footer='\nlicense\n
\n\nPowered by motorino.\n
', head='') self.assertEqual(compare.compare_pages(old, new), []) def test_post_byline_and_description_are_ignored_but_the_body_is_not(self): old = page('\n\n
\n\n\nBody.\n
', head='') new = page('\n · squid · News\n
\n\n\nBody.\n
', head='') self.assertEqual(compare.compare_pages(old, new, post=True), []) changed = new.replace("Body.", "Other body.") self.assertTrue(compare.compare_pages(old, changed, post=True)) class PostPaths(unittest.TestCase): def test_percent_encoded_addresses_are_moved_too(self): mapping = {"/news/shop.html": "/news/2026/11/shop.html"} html = "uri=https%3A%2F%2Fkmalloc.org%2Fnews%2Fshop.html" self.assertEqual(compare.remap(html, mapping), "uri=https%3A%2F%2Fkmalloc.org%2Fnews%2F2026%2F11%2Fshop.html") def test_old_post_links_are_moved_to_the_new_paths(self): mapping = {"/news/shop.html": "/news/2026/11/shop.html"} html = 'shop and https://kmalloc.org/news/shop.html' self.assertEqual(compare.remap(html, mapping), 'shop and https://kmalloc.org/news/2026/11/shop.html') if __name__ == "__main__": unittest.main()