<s> import doctest <EOL> import gettext <EOL> import os <EOL> import unittest <EOL> from StringIO import StringIO <EOL> from babel . messages import mofile , Catalog <EOL> class ReadMoTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . datadir = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:data>' ) <EOL> def test_basics ( self ) : <EOL> mo_file = open ( os . path . join ( self . datadir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> try : <EOL> catalog = mofile . read_mo ( mo_file ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( catalog ) ) <EOL> self . assertEqual ( '<STR_LIT>' , catalog . project ) <EOL> self . assertEqual ( '<STR_LIT>' , catalog . version ) <EOL> self . assertEqual ( '<STR_LIT>' , catalog [ '<STR_LIT:bar>' ] . string ) <EOL> self . assertEqual ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> catalog [ '<STR_LIT>' ] . string ) <EOL> finally : <EOL> mo_file . close ( ) <EOL> class WriteMoTestCase ( unittest . TestCase ) : <EOL> def test_sorting ( self ) : <EOL> catalog = Catalog ( locale = '<STR_LIT>' ) <EOL> catalog . add ( u'<STR_LIT>' , '''<STR_LIT>''' ) <EOL> catalog . add ( u'<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> catalog . add ( ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> catalog . add ( u'<STR_LIT>' , '<STR_LIT>' ) <EOL> catalog . add ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> buf = StringIO ( ) <EOL> mofile . write_mo ( buf , catalog ) <EOL> buf . seek ( <NUM_LIT:0> ) <EOL> translations = gettext . GNUTranslations ( fp = buf ) <EOL> self . assertEqual ( u'<STR_LIT>' , translations . ugettext ( '<STR_LIT:foo>' ) ) <EOL> assert isinstance ( translations . ugettext ( '<STR_LIT:foo>' ) , unicode ) <EOL> self . assertEqual ( u'<STR_LIT>' , translations . ungettext ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> assert isinstance ( translations . ungettext ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) , unicode ) <EOL> self . assertEqual ( u'<STR_LIT>' , translations . ugettext ( '<STR_LIT>' ) ) <EOL> assert isinstance ( translations . ugettext ( '<STR_LIT>' ) , unicode ) <EOL> self . assertEqual ( u'<STR_LIT>' , translations . ugettext ( '<STR_LIT>' ) ) <EOL> assert isinstance ( translations . ugettext ( '<STR_LIT>' ) , unicode ) <EOL> self . assertEqual ( u'<STR_LIT>' , translations . ugettext ( '<STR_LIT>' ) ) <EOL> assert isinstance ( translations . ugettext ( '<STR_LIT>' ) , unicode ) <EOL> def test_more_plural_forms ( self ) : <EOL> catalog2 = Catalog ( locale = '<STR_LIT>' ) <EOL> catalog2 . add ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> buf = StringIO ( ) <EOL> mofile . write_mo ( buf , catalog2 ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( doctest . DocTestSuite ( mofile ) ) <EOL> suite . addTest ( unittest . makeSuite ( ReadMoTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( WriteMoTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
