From f00249db9d1ea051d29aa1bcca869fc4b88e83eb Mon Sep 17 00:00:00 2001 From: historia Date: Mon, 24 Aug 2026 02:59:26 -0400 Subject: refactor: add app directory, dir structure change --- app/tests/test_cleaning.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/tests/test_cleaning.py (limited to 'app/tests/test_cleaning.py') diff --git a/app/tests/test_cleaning.py b/app/tests/test_cleaning.py new file mode 100644 index 0000000..41f4ed7 --- /dev/null +++ b/app/tests/test_cleaning.py @@ -0,0 +1,54 @@ +"""Tests for text and HTML cleaning.""" + +import unittest + +from converter.extractors import clean_html, clean_text + + +class CleanTextTests(unittest.TestCase): + def test_empty_input(self): + self.assertEqual(clean_text(""), "") + self.assertEqual(clean_text(None), "") + + def test_collapses_whitespace(self): + self.assertEqual(clean_text("a\n\n b \t c"), "a b c") + + def test_preserves_inline_numbers(self): + self.assertEqual(clean_text("He was 42 years old."), "He was 42 years old.") + + def test_preserves_grouped_and_decimal_numbers(self): + self.assertEqual( + clean_text("Over 1,000 pages and 3.5 stars."), + "Over 1,000 pages and 3.5 stars.", + ) + + def test_removes_standalone_page_numbers(self): + self.assertEqual( + clean_text("End of page.\n7\nNext page text."), + "End of page. Next page text.", + ) + + def test_page_number_removal_leaves_single_spacing(self): + result = clean_text("Chapter one\n\n12\n\nChapter two") + self.assertEqual(result, "Chapter one Chapter two") + self.assertNotIn(" ", result) + + +class CleanHtmlTests(unittest.TestCase): + def test_strips_tags(self): + self.assertEqual(clean_html("

Hello world

"), "Hello world") + + def test_removes_script_and_style(self): + html = "

Text

" + self.assertEqual(clean_html(html), "Text") + + def test_unescapes_entities(self): + self.assertEqual(clean_html("Tom & Jerry"), "Tom & Jerry") + + def test_empty(self): + self.assertEqual(clean_html(""), "") + self.assertEqual(clean_html(None), "") + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3