<s> from __future__ import ( <EOL> absolute_import , <EOL> print_function , <EOL> unicode_literals , <EOL> ) <EOL> from unittest import TestCase <EOL> from pydocx . export . numbering_span import NumberingSpanBuilder <EOL> from pydocx . openxml . wordprocessing import ( <EOL> Break , <EOL> Paragraph , <EOL> Run , <EOL> TabChar , <EOL> Text , <EOL> ) <EOL> class NumberingSpanTestBase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . builder = NumberingSpanBuilder ( ) <EOL> class CleanParagraphTestCase ( NumberingSpanTestBase ) : <EOL> def test_empty_paragraph ( self ) : <EOL> paragraph = Paragraph ( ) <EOL> expected = Paragraph ( ) <EOL> self . builder . clean_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> class RemoveInitialTextFromParagraphTestCase ( NumberingSpanTestBase ) : <EOL> def test_empty_paragraph ( self ) : <EOL> paragraph = Paragraph ( ) <EOL> expected = Paragraph ( ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_single_run_single_text_node ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_only_removes_if_leading_text_matches ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_many_runs_many_text_nodes ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:c>' ) , <EOL> Text ( text = '<STR_LIT:d>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:e>' ) , <EOL> Text ( text = '<STR_LIT:f>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT:f>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_leading_non_text_is_ignored ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Break ( ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Break ( ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_all_text_is_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:c>' ) , <EOL> Text ( text = '<STR_LIT:d>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_longer_text_after_split_matching_text_is_preserved ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT:f>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_initial_text_is_split_across_multiple_text_nodes ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( paragraph , '<STR_LIT:abc>' ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_tabs_embedded_within_initial_text_can_be_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( <EOL> paragraph , <EOL> initial_text = '<STR_LIT>' , <EOL> tab_char = '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_tab_char_is_not_removed_when_tab_char_is_not_set ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( <EOL> paragraph , <EOL> initial_text = '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_tab_char_is_not_removed_when_tab_char_does_not_match_text ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( <EOL> paragraph , <EOL> initial_text = '<STR_LIT>' , <EOL> tab_char = '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_multiple_tab_chars_are_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT:a>' ) , <EOL> TabChar ( ) , <EOL> TabChar ( ) , <EOL> TabChar ( ) , <EOL> Text ( text = '<STR_LIT:b>' ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> Text ( text = '<STR_LIT>' ) , <EOL> Text ( text = '<STR_LIT>' ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_text_from_paragraph ( <EOL> paragraph , <EOL> initial_text = '<STR_LIT>' , <EOL> tab_char = '<STR_LIT>' , <EOL> ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> class RemoveInitialTabCharsFromParagraphTestCase ( NumberingSpanTestBase ) : <EOL> def test_empty_paragraph_nothing_changes ( self ) : <EOL> paragraph = Paragraph ( ) <EOL> expected = Paragraph ( ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_single_run_single_text_node_no_tabs_nothing_changes ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( children = [ Text ( text = '<STR_LIT>' ) ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_single_initial_tab_is_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ TabChar ( ) ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( ) , <EOL> ] ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_many_runs_many_tabs_are_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> ] ) , <EOL> Run ( ) , <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( ) , <EOL> Run ( ) , <EOL> Run ( ) , <EOL> Run ( ) , <EOL> ] ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_only_tabs_before_break_are_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> Break ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( ) , <EOL> Run ( children = [ <EOL> Break ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) <EOL> def test_only_tabs_before_first_text_are_removed ( self ) : <EOL> paragraph = Paragraph ( children = [ <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> ] ) , <EOL> Run ( children = [ <EOL> TabChar ( ) , <EOL> Text ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> ] ) <EOL> expected = Paragraph ( children = [ <EOL> Run ( ) , <EOL> Run ( children = [ <EOL> Text ( ) , <EOL> TabChar ( ) , <EOL> ] ) , <EOL> ] ) <EOL> self . builder . remove_initial_tab_chars_from_paragraph ( paragraph ) <EOL> self . assertEqual ( repr ( paragraph ) , repr ( expected ) ) </s>
