def test_write_incorrect_plural(): """Test what happens when the .po catalog contains the wrong plural information. """ catalog = Catalog() catalog.language = Language('lt') # Lithuanian # Lithuanian has four plurals, we define 2. catalog._num_plurals, catalog._plural_expr = 2, '(n != 1)' catalog.add(('foo', 'foos'), ( 'a', 'b', ), context='foo') wfunc = TestWarnFunc() xml = po2xml(catalog, warnfunc=wfunc) # A warning was written assert_equal(len(wfunc.logs), 1) assert '2 plurals, we expect 4' in wfunc.logs[0] # The missing plural is empty assert_equal( xml, {'foo': { 'one': 'a', 'other': None, 'few': 'b', 'many': None }})
def test_write_incomplete_plural(): """Test behaviour with incompletely translated plurals in .po.""" catalog = Catalog() catalog.language = Language('bs') # Bosnian catalog.add(('foo', 'foos'), ('one', '', 'many', ''), context='foo') assert po2xml(catalog) == {'foo': { 'few': '', 'many': 'many', 'other': '', 'one': 'one'}}
def test_write(): """Test a basic po2xml() call. (what the import command does). """ catalog = Catalog() catalog.language = Language('bs') # Bosnian catalog.add(('foo', 'foos'), ('few', 'many', 'one', 'other'), context='foo') assert po2xml(catalog) == {'foo': { 'few': 'few', 'many': 'many', 'one': 'one', 'other': 'other'}}
def test_write_ignore_untranslated_plural(): """An untranslated plural is not included in the XML. """ catalog = Catalog() catalog.language = Language('en') catalog.add(('foo', 'foos'), context='foo') assert po2xml(catalog) == {} # Even with ``with_untranslated``, we still do not include # empty plural (they would just block access to the untranslated # master version, which we cannot copy into the target). assert po2xml(catalog) == {}
def test_write_incorrect_plural(): """Test what happens when the .po catalog contains the wrong plural information. """ catalog = Catalog() catalog.language = Language('lt') # Lithuanian # Lithuanian has three plurals, we define 2. catalog._num_plurals, catalog._plural_expr = 2, '(n != 1)' catalog.add(('foo', 'foos'), ('a', 'b',), context='foo') wfunc = TestWarnFunc() xml = po2xml(catalog, warnfunc=wfunc) # A warning was written assert len(wfunc.logs) == 1 assert '2 plurals, we expect 3' in wfunc.logs[0] # The missing plural is empty assert xml == {'foo': {'few': 'a', 'other': None, 'one': 'b'}}