def test_nested_sublist_parent_contains_child_and_child_parent(self): components = [ self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('2', '2'), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() parent_items = { ('1', '0'): [ {'num_id': '2', 'level': '1'}, ] } child_item = { '2': {'num_id': '1', 'level': '0'}, } self.assertDictEqual(builder.parent_child_num_map, parent_items) self.assertDictEqual(builder.child_parent_num_map, child_item) self.assertTrue(result)
def test_no_components_on_init(self): builder = NumberingSpanBuilder() result = builder.detect_parent_child_map_for_items() self.assertEqual(builder.child_parent_num_map, {}) self.assertEqual(builder.parent_child_num_map, {}) self.assertFalse(result)
def test_nested_sublist_not_wrapped_in_parent_item(self): components = [ self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('1', '0'), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() parent_items = { ('1', '0'): [ {'num_id': '2', 'level': '0'}, {'num_id': '3', 'level': '0'}, ] } child_item = { '2': {'num_id': '1', 'level': '0'}, '3': {'num_id': '1', 'level': '0'}, } list_start_stop_index = { '1': {'start': 0, 'stop': 4}, '2': {'start': 1, 'stop': 1}, '3': {'start': 2, 'stop': 3}, } self.assertDictEqual(builder.parent_child_num_map, parent_items) self.assertDictEqual(builder.child_parent_num_map, child_item) self.assertDictEqual(builder.list_start_stop_index, list_start_stop_index) self.assertTrue(result)
def test_invalid_input_components(self): components = [ Paragraph(), Paragraph(children=[ Run(children=[ TabChar(), ]) ]), Paragraph( properties=ParagraphProperties() ), Paragraph( properties=ParagraphProperties( numbering_properties=NumberingProperties() ) ), self.create_numbering_paragraph('1', '0', container=False), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() self.assertEqual(builder.parent_child_num_map, {}) self.assertEqual(builder.child_parent_num_map, {}) self.assertFalse(result)
def test_nested_sublist_parent_contains_child_and_child_parent(self): components = [ self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '1'), self.create_numbering_paragraph('2', '2'), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() parent_items = { ('1', '0'): [ { 'num_id': '2', 'level': '1' }, ] } child_item = { '2': { 'num_id': '1', 'level': '0' }, } self.assertDictEqual(builder.parent_child_num_map, parent_items) self.assertDictEqual(builder.child_parent_num_map, child_item) self.assertTrue(result)
def test_valid_input_components_but_no_sublists_found(self): components = [ Paragraph(), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('3', '0'), ] list_start_stop_index = { '1': { 'start': 1, 'stop': 2 }, '2': { 'start': 3, 'stop': 4 }, '3': { 'start': 5, 'stop': 6 }, } builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() self.assertDictEqual(builder.parent_child_num_map, {}) self.assertDictEqual(builder.child_parent_num_map, {}) self.assertDictEqual(builder.list_start_stop_index, list_start_stop_index) self.assertTrue(result)
def test_nested_sublist_not_wrapped_in_parent_item(self): components = [ self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('1', '0'), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() parent_items = { ('1', '0'): [ { 'num_id': '2', 'level': '0' }, { 'num_id': '3', 'level': '0' }, ] } child_item = { '2': { 'num_id': '1', 'level': '0' }, '3': { 'num_id': '1', 'level': '0' }, } list_start_stop_index = { '1': { 'start': 0, 'stop': 4 }, '2': { 'start': 1, 'stop': 1 }, '3': { 'start': 2, 'stop': 3 }, } self.assertDictEqual(builder.parent_child_num_map, parent_items) self.assertDictEqual(builder.child_parent_num_map, child_item) self.assertDictEqual(builder.list_start_stop_index, list_start_stop_index) self.assertTrue(result)
def test_invalid_input_components(self): components = [ Paragraph(), Paragraph(children=[Run(children=[ TabChar(), ])]), Paragraph(properties=ParagraphProperties()), Paragraph(properties=ParagraphProperties( numbering_properties=NumberingProperties())), self.create_numbering_paragraph('1', '0', container=False), ] builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() self.assertEqual(builder.parent_child_num_map, {}) self.assertEqual(builder.child_parent_num_map, {}) self.assertFalse(result)
def test_valid_input_components_but_no_sublists_found(self): components = [ Paragraph(), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('1', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('2', '0'), self.create_numbering_paragraph('3', '0'), self.create_numbering_paragraph('3', '0'), ] list_start_stop_index = { '1': {'start': 1, 'stop': 2}, '2': {'start': 3, 'stop': 4}, '3': {'start': 5, 'stop': 6}, } builder = NumberingSpanBuilder(components) result = builder.detect_parent_child_map_for_items() self.assertDictEqual(builder.parent_child_num_map, {}) self.assertDictEqual(builder.child_parent_num_map, {}) self.assertDictEqual(builder.list_start_stop_index, list_start_stop_index) self.assertTrue(result)
def setUp(self): self.builder = NumberingSpanBuilder()