<s> from datetime import datetime <EOL> import doctest <EOL> from StringIO import StringIO <EOL> import unittest <EOL> import sys <EOL> from babel . messages . catalog import Catalog , Message <EOL> from babel . messages import pofile <EOL> from babel . util import FixedOffsetTimezone , LOCALTZ <EOL> class ReadPoTestCase ( unittest . TestCase ) : <EOL> def test_preserve_locale ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , locale = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , catalog . locale ) <EOL> def test_preserve_domain ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , domain = '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , catalog . domain ) <EOL> def test_read_multiline ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> message = list ( catalog ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> message . id ) <EOL> def test_fuzzy_header ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( list ( catalog ) ) ) <EOL> self . assertEqual ( True , list ( catalog ) [ <NUM_LIT:0> ] . fuzzy ) <EOL> def test_not_fuzzy_header ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( list ( catalog ) ) ) <EOL> self . assertEqual ( False , list ( catalog ) [ <NUM_LIT:0> ] . fuzzy ) <EOL> def test_header_entry ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( list ( catalog ) ) ) <EOL> self . assertEqual ( u'<STR_LIT>' , catalog . version ) <EOL> self . assertEqual ( u'<STR_LIT>' , <EOL> catalog . msgid_bugs_address ) <EOL> self . assertEqual ( datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:11> , <NUM_LIT> , <EOL> tzinfo = FixedOffsetTimezone ( <NUM_LIT:7> * <NUM_LIT> ) ) , <EOL> catalog . creation_date ) <EOL> self . assertEqual ( u'<STR_LIT>' , catalog . last_translator ) <EOL> self . assertEqual ( u'<STR_LIT>' , catalog . language_team ) <EOL> self . assertEqual ( u'<STR_LIT>' , catalog . charset ) <EOL> self . assertEqual ( True , list ( catalog ) [ <NUM_LIT:0> ] . fuzzy ) <EOL> def test_obsolete_message ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog . obsolete ) ) <EOL> message = catalog . obsolete [ u'<STR_LIT:foo>' ] <EOL> self . assertEqual ( u'<STR_LIT:foo>' , message . id ) <EOL> self . assertEqual ( u'<STR_LIT>' , message . string ) <EOL> self . assertEqual ( [ '<STR_LIT>' ] , message . user_comments ) <EOL> def test_obsolete_message_ignored ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , ignore_obsolete = True ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( catalog . obsolete ) ) <EOL> def test_single_plural_form ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , locale = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , catalog . num_plurals ) <EOL> message = catalog [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( <NUM_LIT:1> , len ( message . string ) ) <EOL> def test_singular_plural_form ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , locale = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , catalog . num_plurals ) <EOL> message = catalog [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( <NUM_LIT:2> , len ( message . string ) ) <EOL> def test_more_than_two_plural_forms ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , locale = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , catalog . num_plurals ) <EOL> message = catalog [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( <NUM_LIT:3> , len ( message . string ) ) <EOL> self . assertEqual ( u'<STR_LIT>' , message . string [ <NUM_LIT:2> ] ) <EOL> def test_plural_with_square_brackets ( self ) : <EOL> buf = StringIO ( r'''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf , locale = '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( catalog ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , catalog . num_plurals ) <EOL> message = catalog [ '<STR_LIT:foo>' ] <EOL> self . assertEqual ( <NUM_LIT:2> , len ( message . string ) ) <EOL> class WritePoTestCase ( unittest . TestCase ) : <EOL> def test_join_locations ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> catalog . add ( u'<STR_LIT:foo>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_duplicate_comments ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , auto_comments = [ '<STR_LIT>' ] ) <EOL> catalog . add ( u'<STR_LIT:foo>' , auto_comments = [ '<STR_LIT>' ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_wrap_long_lines ( self ) : <EOL> text = """<STR_LIT>""" <EOL> catalog = Catalog ( ) <EOL> catalog . add ( text , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , no_location = True , omit_header = True , <EOL> width = <NUM_LIT> ) <EOL> self . assertEqual ( r'''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_wrap_long_lines_with_long_word ( self ) : <EOL> text = """<STR_LIT>""" <EOL> catalog = Catalog ( ) <EOL> catalog . add ( text , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , no_location = True , omit_header = True , <EOL> width = <NUM_LIT:32> ) <EOL> self . assertEqual ( r'''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_wrap_long_lines_in_header ( self ) : <EOL> """<STR_LIT>""" <EOL> catalog = Catalog ( project = '<STR_LIT>' , <EOL> revision_date = datetime ( <NUM_LIT> , <NUM_LIT:4> , <NUM_LIT:1> ) ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog ) <EOL> self . assertEqual ( '''<STR_LIT>''' , '<STR_LIT:\n>' . join ( buf . getvalue ( ) . splitlines ( ) [ : <NUM_LIT:7> ] ) ) <EOL> def test_wrap_locations_with_hyphens ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , locations = [ <EOL> ( '<STR_LIT>' , <NUM_LIT> ) <EOL> ] ) <EOL> catalog . add ( u'<STR_LIT:foo>' , locations = [ <EOL> ( '<STR_LIT>' , <NUM_LIT> ) <EOL> ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_no_wrap_and_width_behaviour_on_comments ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> locations = [ ( "<STR_LIT>" , n ) for n in range ( <NUM_LIT:1> , <NUM_LIT:30> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , width = None , omit_header = True ) <EOL> self . assertEqual ( """<STR_LIT>""" , buf . getvalue ( ) . lower ( ) ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , width = <NUM_LIT:100> , omit_header = True ) <EOL> self . assertEqual ( """<STR_LIT>""" , buf . getvalue ( ) . lower ( ) ) <EOL> def test_pot_with_translator_comments ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] , <EOL> auto_comments = [ '<STR_LIT>' ] ) <EOL> catalog . add ( u'<STR_LIT:bar>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] , <EOL> user_comments = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_po_with_obsolete_message ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , u'<STR_LIT>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> catalog . obsolete [ '<STR_LIT:bar>' ] = Message ( u'<STR_LIT:bar>' , u'<STR_LIT>' , <EOL> locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] , <EOL> user_comments = [ '<STR_LIT>' ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_po_with_multiline_obsolete_message ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , u'<STR_LIT>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> msgid = r"""<STR_LIT>""" <EOL> msgstr = r"""<STR_LIT>""" <EOL> catalog . obsolete [ msgid ] = Message ( msgid , msgstr , <EOL> locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True ) <EOL> self . assertEqual ( r'''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_po_with_obsolete_message_ignored ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , u'<STR_LIT>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> catalog . obsolete [ '<STR_LIT:bar>' ] = Message ( u'<STR_LIT:bar>' , u'<STR_LIT>' , <EOL> locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] , <EOL> user_comments = [ '<STR_LIT>' ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True , ignore_obsolete = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_po_with_previous_msgid ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:foo>' , u'<STR_LIT>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] , <EOL> previous_id = u'<STR_LIT>' ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True , include_previous = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_po_with_previous_msgid_plural ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( ( u'<STR_LIT:foo>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] , previous_id = ( u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , omit_header = True , include_previous = True ) <EOL> self . assertEqual ( '''<STR_LIT>''' , buf . getvalue ( ) . strip ( ) ) <EOL> def test_sorted_po ( self ) : <EOL> catalog = Catalog ( ) <EOL> catalog . add ( u'<STR_LIT:bar>' , locations = [ ( '<STR_LIT>' , <NUM_LIT:3> ) ] , <EOL> user_comments = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> catalog . add ( ( u'<STR_LIT:foo>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) , <EOL> locations = [ ( '<STR_LIT>' , <NUM_LIT:1> ) ] ) <EOL> buf = StringIO ( ) <EOL> pofile . write_po ( buf , catalog , sort_output = True ) <EOL> value = buf . getvalue ( ) . strip ( ) <EOL> assert '''<STR_LIT>''' in value <EOL> assert value . find ( '<STR_LIT>' ) < value . find ( '<STR_LIT>' ) < value . find ( '<STR_LIT>' ) <EOL> def test_silent_location_fallback ( self ) : <EOL> buf = StringIO ( '''<STR_LIT>''' ) <EOL> catalog = pofile . read_po ( buf ) <EOL> self . assertEqual ( catalog [ '<STR_LIT>' ] . locations , [ ] ) <EOL> self . assertEqual ( catalog [ '<STR_LIT>' ] . locations , [ ] ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> is_py23 = sys . version_info [ <NUM_LIT:0> : <NUM_LIT:2> ] == ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> if not is_py23 : <EOL> suite . addTest ( doctest . DocTestSuite ( pofile ) ) <EOL> suite . addTest ( unittest . makeSuite ( ReadPoTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( WritePoTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
