<s> from __future__ import unicode_literals , print_function , division <EOL> __author__ = "<STR_LIT>" <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> from ezodf . xmlns import etree , CN <EOL> from ezodf . base import GenericWrapper <EOL> from ezodf . text import Paragraph , Span , Heading , NumberedParagraph , Hyperlink <EOL> SPANDATA = '<STR_LIT>' '<STR_LIT>' <EOL> SPANDATA_SPC = '<STR_LIT>' '<STR_LIT>' <EOL> SPANDATA_BRK = '<STR_LIT>' '<STR_LIT>' <EOL> SPANDATA_TAB = '<STR_LIT>' '<STR_LIT>' <EOL> SPANDATA_ALL = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> class TestSpan ( unittest . TestCase ) : <EOL> def test_bare_init ( self ) : <EOL> span = Span ( ) <EOL> self . assertTrue ( isinstance ( span , GenericWrapper ) ) <EOL> self . assertEqual ( span . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> def test_init_xmlroot ( self ) : <EOL> node = etree . Element ( CN ( '<STR_LIT>' ) , test = "<STR_LIT>" ) <EOL> span = Span ( xmlnode = node ) <EOL> self . assertTrue ( isinstance ( span , GenericWrapper ) ) <EOL> self . assertEqual ( span . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span . xmlnode . get ( '<STR_LIT:test>' ) , "<STR_LIT>" ) <EOL> def test_init_XML ( self ) : <EOL> node = etree . XML ( SPANDATA ) <EOL> span = Span ( xmlnode = node ) <EOL> self . assertTrue ( isinstance ( span , GenericWrapper ) ) <EOL> self . assertEqual ( span . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> def test_textlen ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA ) ) <EOL> self . assertEqual ( span . textlen , <NUM_LIT:8> ) <EOL> def test_textlen_with_spaces ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_SPC ) ) <EOL> self . assertEqual ( span . textlen , <NUM_LIT:12> ) <EOL> def test_textlen_with_line_break ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_BRK ) ) <EOL> self . assertEqual ( span . textlen , <NUM_LIT:11> ) <EOL> def test_textlen_with_tab ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_TAB ) ) <EOL> self . assertEqual ( span . textlen , <NUM_LIT:11> ) <EOL> def test_textlen_with_all ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_ALL ) ) <EOL> self . assertEqual ( span . textlen , <NUM_LIT> ) <EOL> def test_plaintext ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA ) ) <EOL> self . assertEqual ( span . plaintext ( ) , '<STR_LIT>' ) <EOL> def test_plaintext_with_spaces ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_SPC ) ) <EOL> self . assertEqual ( span . plaintext ( ) , '<STR_LIT>' ) <EOL> def test_plaintext_with_line_break ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_BRK ) ) <EOL> self . assertEqual ( span . plaintext ( ) , '<STR_LIT>' ) <EOL> def test_plaintext_with_tab ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_TAB ) ) <EOL> self . assertEqual ( span . plaintext ( ) , '<STR_LIT>' ) <EOL> def test_plaintext_with_all ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA_ALL ) ) <EOL> self . assertEqual ( span . plaintext ( ) , '<STR_LIT>' ) <EOL> def test_get_style_name ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA ) ) <EOL> self . assertEqual ( span . style_name , '<STR_LIT>' ) <EOL> def test_set_style_name ( self ) : <EOL> span = Span ( xmlnode = etree . XML ( SPANDATA ) ) <EOL> span . style_name = "<STR_LIT>" <EOL> self . assertEqual ( span . style_name , '<STR_LIT>' ) <EOL> def test_append_text ( self ) : <EOL> txt = "<STR_LIT>" <EOL> span = Span ( text = txt ) <EOL> self . assertEqual ( span . text , txt ) <EOL> self . assertEqual ( span . plaintext ( ) , txt ) <EOL> def test_append_text_2 ( self ) : <EOL> txt = "<STR_LIT>" <EOL> span = Span ( text = txt ) <EOL> self . assertEqual ( span . text , "<STR_LIT>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . tail , "<STR_LIT>" ) <EOL> self . assertEqual ( span . plaintext ( ) , txt ) <EOL> def test_append_text_3 ( self ) : <EOL> txt = "<STR_LIT>" <EOL> span = Span ( text = txt ) <EOL> self . assertEqual ( span . text , "<STR_LIT>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . tail , "<STR_LIT>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:1> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:1> ] . tail , "<STR_LIT:U+0020>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:2> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:2> ] . tail , None ) <EOL> self . assertEqual ( span [ <NUM_LIT:3> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:3> ] . tail , "<STR_LIT:U+0020>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:4> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:4> ] . count , <NUM_LIT:3> ) <EOL> self . assertEqual ( span . plaintext ( ) , txt ) <EOL> def test_append_text_4 ( self ) : <EOL> span = Span ( text = "<STR_LIT>" ) <EOL> span . append_text ( "<STR_LIT>" ) <EOL> self . assertEqual ( span . text , "<STR_LIT>" ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . TAG , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( span [ <NUM_LIT:0> ] . tail , "<STR_LIT>" ) <EOL> DATA1 = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> class TestParagraph ( unittest . TestCase ) : <EOL> def test_bare_init ( self ) : <EOL> p = Paragraph ( ) <EOL> self . assertTrue ( isinstance ( p , GenericWrapper ) ) <EOL> self . assertEqual ( p . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> def test_init_xmlroot ( self ) : <EOL> node = etree . Element ( CN ( '<STR_LIT>' ) , test = "<STR_LIT>" ) <EOL> p = Paragraph ( xmlnode = node ) <EOL> self . assertTrue ( isinstance ( p , GenericWrapper ) ) <EOL> self . assertEqual ( p . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( p . xmlnode . get ( '<STR_LIT:test>' ) , "<STR_LIT>" ) <EOL> def test_cond_style_name ( self ) : <EOL> p = Paragraph ( ) <EOL> p . cond_style_name = "<STR_LIT>" <EOL> self . assertEqual ( p . cond_style_name , "<STR_LIT>" ) <EOL> self . assertIsNotNone ( p . xmlnode . get ( CN ( '<STR_LIT>' ) ) ) <EOL> def test_ID ( self ) : <EOL> p = Paragraph ( ) <EOL> p . ID = "<STR_LIT>" <EOL> self . assertEqual ( p . ID , "<STR_LIT>" ) <EOL> self . assertIsNotNone ( p . xmlnode . get ( CN ( '<STR_LIT>' ) ) ) <EOL> class TestNumberedParagraph ( unittest . TestCase ) : <EOL> def test_init_1 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> self . assertEqual ( np . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> def test_init_type_error ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> np = NumberedParagraph ( '<STR_LIT:text>' ) <EOL> def test_paragraph_content ( self ) : <EOL> np = NumberedParagraph ( Paragraph ( '<STR_LIT:text>' ) ) <EOL> res = np . content <EOL> self . assertEqual ( res . plaintext ( ) , '<STR_LIT:text>' ) <EOL> def test_heading_content ( self ) : <EOL> np = NumberedParagraph ( Heading ( '<STR_LIT:text>' ) ) <EOL> res = np . content <EOL> self . assertEqual ( res . plaintext ( ) , '<STR_LIT:text>' ) <EOL> def test_no_content ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> newp = np . content <EOL> self . assertEqual ( newp . kind , '<STR_LIT>' ) <EOL> newp . append_text ( '<STR_LIT:text>' ) <EOL> self . assertEqual ( np . content . plaintext ( ) , '<STR_LIT:text>' ) <EOL> def test_level_0 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . level = <NUM_LIT:0> <EOL> self . assertEqual ( np . level , <NUM_LIT:1> ) <EOL> def test_level_1 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . level = '<STR_LIT:1>' <EOL> self . assertEqual ( np . level , <NUM_LIT:1> ) <EOL> def test_level_2 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . level = <NUM_LIT> <EOL> self . assertEqual ( np . level , <NUM_LIT:2> ) <EOL> class TestNumberingMixin ( unittest . TestCase ) : <EOL> def test_unset_start_value ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> self . assertIsNone ( np . start_value ) <EOL> def test_start_value_0 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . start_value = <NUM_LIT:0> <EOL> self . assertEqual ( np . start_value , <NUM_LIT:1> ) <EOL> def test_start_value_1 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . start_value = '<STR_LIT:1>' <EOL> self . assertEqual ( np . start_value , <NUM_LIT:1> ) <EOL> def test_start_value_2 ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . start_value = <NUM_LIT> <EOL> self . assertEqual ( np . start_value , <NUM_LIT:2> ) <EOL> def test_unset_formatted_number ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> self . assertIsNone ( np . formatted_number ) <EOL> def test_formatted_value ( self ) : <EOL> np = NumberedParagraph ( ) <EOL> np . formatted_number = '<STR_LIT>' <EOL> self . assertEqual ( np . formatted_number , '<STR_LIT>' ) <EOL> class TestHeading ( unittest . TestCase ) : <EOL> def test_bare_init ( self ) : <EOL> h = Heading ( ) <EOL> self . assertTrue ( isinstance ( h , GenericWrapper ) ) <EOL> self . assertEqual ( h . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> def test_init_xmlroot ( self ) : <EOL> node = etree . Element ( CN ( '<STR_LIT>' ) , test = "<STR_LIT>" ) <EOL> h = Heading ( xmlnode = node ) <EOL> self . assertTrue ( isinstance ( h , GenericWrapper ) ) <EOL> self . assertEqual ( h . xmlnode . tag , CN ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( h . xmlnode . get ( '<STR_LIT:test>' ) , "<STR_LIT>" ) <EOL> def test_outline_level_0 ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' , outline_level = <NUM_LIT:0> ) <EOL> self . assertEqual ( h . outline_level , <NUM_LIT:1> ) <EOL> def test_outline_level_1 ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> self . assertEqual ( h . outline_level , <NUM_LIT:1> ) <EOL> def test_outline_level_2 ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> h . outline_level = <NUM_LIT> <EOL> self . assertEqual ( h . outline_level , <NUM_LIT:2> ) <EOL> def test_unset_restart_numbering ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> self . assertFalse ( h . restart_numbering ) <EOL> def test_restart_numbering_true ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> h . restart_numbering = True <EOL> self . assertTrue ( h . restart_numbering ) <EOL> def test_restart_numbering_true ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> h . restart_numbering = False <EOL> self . assertFalse ( h . restart_numbering ) <EOL> def test_unset_suppress_numbering ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> self . assertFalse ( h . suppress_numbering ) <EOL> def test_suppress_numbering_true ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> h . suppress_numbering = True <EOL> self . assertTrue ( h . suppress_numbering ) <EOL> def test_suppress_numbering_false ( self ) : <EOL> h = Heading ( '<STR_LIT:text>' ) <EOL> h . suppress_numbering = False <EOL> self . assertFalse ( h . suppress_numbering ) <EOL> class TestHyperlink ( unittest . TestCase ) : <EOL> def test_init ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> self . assertIsNotNone ( h ) <EOL> def test_unset_name ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> self . assertIsNone ( h . name ) <EOL> def test_name ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> h . name = '<STR_LIT:test>' <EOL> self . assertEqual ( h . name , '<STR_LIT:test>' ) <EOL> def test_unset_href ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> self . assertIsNone ( h . href ) <EOL> def test_href ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> h . href = '<STR_LIT>' <EOL> self . assertEqual ( h . href , '<STR_LIT>' ) <EOL> def test_target_frame ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> h . target_frame = '<STR_LIT>' <EOL> self . assertEqual ( h . target_frame , '<STR_LIT>' ) <EOL> self . assertEqual ( h . get_attr ( CN ( '<STR_LIT>' ) ) , '<STR_LIT:replace>' ) <EOL> def test_target_frame_blank ( self ) : <EOL> h = Hyperlink ( xmlnode = None ) <EOL> h . target_frame = '<STR_LIT>' <EOL> self . assertEqual ( h . target_frame , '<STR_LIT>' ) <EOL> self . assertEqual ( h . get_attr ( CN ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
