Skip to content

Commit

Permalink
Add tests and update CHANGELOG for single-item list conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
pcraig3 committed Dec 17, 2024
1 parent c6693d4 commit ebed690
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve

### Changed

- Convert single-item lists to paragraphs inside of table cells

### Fixed

## [1.40.0] - 2023-12-16
Expand Down
62 changes: 61 additions & 1 deletion bloom_nofos/nofos/test_nofo.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_no_replacements_needed(self):
self.assertEqual(replace_chars(test_string), test_string)


class TestsCleanTableCells(TestCase):
class TestsCleanTableCellsSpans(TestCase):
def test_remove_span_keep_content(self):
html = "<table><tr><td><span>Content</span> and more <span>content</span></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
Expand Down Expand Up @@ -155,6 +155,66 @@ def test_multiple_spans_in_cell(self):
self.assertEqual(soup.td.text, "FirstSecond")


class TestsCleanTableCellsLists(TestCase):
def test_replace_single_item_ul_in_table_cell(self):
html = "<table><tr><td><ul><li>UL list item 1</li></ul></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(
str(soup), "<table><tr><td><p>UL list item 1</p></td></tr></table>"
)

def test_replace_single_item_ol_in_table_cell(self):
html = "<table><tr><td><ol><li>OL list item 1</li></ol></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(
str(soup), "<table><tr><td><p>OL list item 1</p></td></tr></table>"
)

def test_NO_replace_multiple_item_ul_in_table_cell(self):
html = "<table><tr><td><ul><li>UL list item 1</li><li>UL list item 2</li></ul></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_multiple_item_ol_in_table_cell(self):
html = "<table><tr><td><ol><li>OL list item 1</li><li>OL list item 2</li></ol></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_single_item_ul_in_table_cell_if_element_before(self):
html = "<table><tr><td><p>Paragraph 1 before ul</p><ul><li>UL list item 1</li></ul></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_single_item_ul_in_table_cell_if_element_after(self):
html = "<table><tr><td><ul><li>UL list item 1</li></ul><p>Paragraph 1 after ul</p></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_2_single_item_uls_in_table_cell(self):
html = "<table><tr><td><ul><li>UL list 1 item 1</li></ul><ul><li>UL list 2 item 1</li></ul></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_2_single_item_ols_in_table_cell(self):
html = "<table><tr><td><ol><li>OL list 1 item 1</li></ol><ol><li>OL list 2 item 1</li></ol></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)

def test_NO_replace_single_item_ul_and_single_item_ol_in_table_cell(self):
html = "<table><tr><td><ul><li>UL list 1 item 1</li></ul><ol><li>OL list 1 item 1</li></ol></td></tr></table>"
soup = BeautifulSoup(html, "html.parser")
clean_table_cells(soup)
self.assertEqual(str(soup), html)


class TableConvertFirstRowToHeaderRowTests(TestCase):
def setUp(self):
self.caption_text = "Physician Assistant Training Chart"
Expand Down

0 comments on commit ebed690

Please sign in to comment.