def testParsingIntoMessages(self): root = util.ParseGrdForUnittest(''' <messages> <message name="ID_MEGA">Fantastic!</message> <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message> </messages>''') msgs, = root.GetChildrenOfType(empty.MessagesNode) clique_mega = msgs.children[0].GetCliques()[0] msg_mega = clique_mega.GetMessage() clique_hello_user = msgs.children[1].GetCliques()[0] msg_hello_user = clique_hello_user.GetMessage() xtb_file = StringIO.StringIO('''<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE translationbundle> <translationbundle lang="is"> <translation id="%s">Meirihattar!</translation> <translation id="%s">Saelir <ph name="USERNAME"/></translation> </translationbundle>''' % (msg_mega.GetId(), msg_hello_user.GetId())) xtb_reader.Parse(xtb_file, msgs.UberClique().GenerateXtbParserCallback('is')) self.assertEqual('Meirihattar!', clique_mega.MessageForLanguage('is').GetRealContent()) self.failUnless( 'Saelir %s', clique_hello_user.MessageForLanguage('is').GetRealContent())
def testAcceptsResourcePath(self): root = util.ParseGrdForUnittest( ''' <outputs> <output filename="grit/test1_resources.h" type="rc_header"> <emit emit_type='prepend'></emit> </output> <output filename="grit/test1_resources_map.cc" type="resource_file_map_source" /> <output filename="grit/test1_resources_map.h" type="resource_map_header" /> </outputs> <release seq="3"> <includes> <include name="TEST1_TEXT" file="test1_text.txt" resource_path="foo/renamed1_text.txt" compress="false" type="BINDATA"/> </includes> </release>''', base_dir=util.PathFromRoot('grit/testdata')) inc, = root.GetChildrenOfType(include.IncludeNode) formatter = grit.format.resource_map.GetFormatter( 'resource_file_map_source') formatted = formatter(root, lang='en', output_dir=util.PathFromRoot('grit/testdata')) found = False for segment in formatted: found = found or 'foo/renamed1_text.txt' in segment self.assertNotIn('test1_text.txt', segment) self.assertTrue(found)
def testRcHeaderFormat(self): grd = util.ParseGrdForUnittest(''' <includes first_id="300" comment="bingo"> <include type="gif" name="IDR_LOGO" file="images/logo.gif" /> </includes> <messages first_id="10000"> <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? </message> <message name="IDS_BONGO"> Bongo! </message> </messages>''') # Using the default settings. output = rc_header.FormatDefines(grd) self.assertEqual(('#define IDR_LOGO 300\n' '#define IDS_GREETING 10000\n' '#define IDS_BONGO 10001\n'), ''.join(output)) # Using resource allowlist support. grd.SetAllowlistSupportEnabled(True) output = rc_header.FormatDefines(grd) self.assertEqual(('#define IDR_LOGO ' '(::ui::AllowlistedResource<300>(), 300)\n' '#define IDS_GREETING ' '(::ui::AllowlistedResource<10000>(), 10000)\n' '#define IDS_BONGO ' '(::ui::AllowlistedResource<10001>(), 10001)\n'), ''.join(output))
def testFormatResourceMapWithGeneratedFile(self): os.environ["root_gen_dir"] = "gen" grd = util.ParseGrdForUnittest('''\ <outputs> <output type="rc_header" filename="the_rc_header.h" /> <output type="resource_map_header" filename="resource_map_header.h" /> </outputs> <release seq="3"> <includes first_id="10000"> <include type="BINDATA" file="${root_gen_dir}/foo/bar/baz.js" name="IDR_FOO_BAR_BAZ_JS" use_base_dir="false" compress="gzip" /> </includes> </release>''', run_gatherers=True) with self.assertRaises(AssertionError) as assertion_error: formatter = resource_map.GetFormatter('resource_file_map_source') util.StripBlankLinesAndComments(''.join(formatter(grd, 'en', '.'))) self.assertTrue(str(assertion_error.exception). \ startswith('resource_path attribute missing for IDR_FOO_BAR_BAZ_JS'))
def testRcHeaderFormat(self): grd = util.ParseGrdForUnittest(''' <includes first_id="300" comment="bingo"> <include type="gif" name="IDR_LOGO" file="images/logo.gif" /> </includes> <messages first_id="10000"> <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? </message> <message name="IDS_BONGO"> Bongo! </message> </messages>''') # Using the default rc_header format string. output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(), grd.GetRcHeaderFormat()) self.assertEqual(('#define IDR_LOGO 300\n' '#define IDS_GREETING 10000\n' '#define IDS_BONGO 10001\n'), ''.join(output)) # Using a custom rc_header format string. grd.AssignRcHeaderFormat( '#define {textual_id} _Pragma("{textual_id}") {numeric_id}') output = rc_header.FormatDefines(grd, grd.ShouldOutputAllResourceDefines(), grd.GetRcHeaderFormat()) self.assertEqual( ('#define IDR_LOGO _Pragma("IDR_LOGO") 300\n' '#define IDS_GREETING _Pragma("IDS_GREETING") 10000\n' '#define IDS_BONGO _Pragma("IDS_BONGO") 10001\n'), ''.join(output))
def testFallbackToEnglish(self): root = util.ParseGrdForUnittest('''\ <structures fallback_to_english="True"> <structure type="dialog" name="IDD_ABOUTBOX" file="grit\\testdata\klonk.rc" encoding="utf-16" /> </structures>''', base_dir=util.PathFromRoot('.')) root.SetOutputLanguage('en') root.RunGatherers() buf = StringIO.StringIO() formatter = build.RcBuilder.ProcessNode( root, DummyOutput('rc_all', 'bingobongo'), buf) output = util.StripBlankLinesAndComments(buf.getvalue()) self.assertEqual( _PREAMBLE + '''\ IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU CAPTION "About" FONT 8, "System", 0, 0, 0x0 BEGIN ICON IDI_KLONK,IDC_MYICON,14,9,20,20 LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, SS_NOPREFIX LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", BS_AUTORADIOBUTTON,46,51,84,10 END''', output)
def testMessages(self): root = util.ParseGrdForUnittest(''' <messages> <message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message> <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? </message> <message name="BONGO" desc="Flippo nippo"> Howdie "Mr. Elephant", how are you doing? \'\'\' </message> <message name="IDS_WITH_LINEBREAKS"> Good day sir, I am a bee Sting sting </message> </messages> ''') buf = StringIO.StringIO() build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) output = util.StripBlankLinesAndComments(buf.getvalue()) self.assertEqual( _PREAMBLE + u'''\ STRINGTABLE BEGIN IDS_BTN_GO "Go!" IDS_GREETING "Hello %s, how are you doing today?" BONGO "Howdie ""Mr. Elephant"", how are you doing? " IDS_WITH_LINEBREAKS "Good day sir,\\nI am a bee\\nSting sting" END''', output)
def testBrotliLottie(self): test_data_root = util.PathFromRoot('grit/testdata') root = util.ParseGrdForUnittest(''' <structures> <structure name="TEST_LOTTIE" file="test_json.json" type="lottie" compress="brotli" /> </structures>''', base_dir=test_data_root) node, = root.GetChildrenOfType(structure.StructureNode) node.RunPreSubstitutionGatherer() # Using the mock brotli decompression executable. brotli_util.SetBrotliCommand([ sys.executable, os.path.join(os.path.dirname(__file__), 'mock_brotli.py') ]) data = node.GetDataPackValue(lang='en', encoding=util.BINARY) self.assertEqual('LOTTIE'.encode('utf-8'), data[0:6]) self.assertEqual(constants.BROTLI_CONST, data[6:8]) self.assertEqual( len( util.ReadFile(os.path.join(test_data_root, 'test_json.json'), util.BINARY)), struct.unpack('<i', data[8:12])[0] + (struct.unpack('<h', data[12:14])[0] << 4 * 8)) self.assertEqual(b'This has been mock compressed!', data[14:])
def testChromeHtmlNodeOutputfile(self): input_file = util.PathFromRoot('grit/testdata/chrome_html.html') output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir() root = util.ParseGrdForUnittest('''\ <structures> <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" /> </structures>''' % input_file) struct, = root.GetChildrenOfType(structure.StructureNode) struct.gatherer.SetDefines({'scale_factors': '2x'}) # We must run the gatherers since we'll be wanting the chrome_html output. # The file exists in the location pointed to. root.SetOutputLanguage('en') root.RunGatherers() buf = StringIO.StringIO() build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en', output_file), buf) output = util.StripBlankLinesAndComments(buf.getvalue()) expected = ( _PREAMBLE + u'HTML_FILE1 BINDATA "HTML_FILE1_chrome_html.html"' ) # hackety hack to work on win32&lin output = re.sub('"[c-zC-Z]:', '"', output) self.assertEqual(expected, output) file_contents = util.ReadFile(output_file, util.RAW_TEXT) # Check for the content added by the <include> tag. self.failUnless(file_contents.find('Hello Include!') != -1) # Check for inserted -webkit-image-set. self.failUnless(file_contents.find('content: -webkit-image-set') != -1)
def testOnlyDefineResourcesThatSatisfyOutputCondition(self): grd = util.ParseGrdForUnittest(''' <includes first_id="300" comment="bingo"> <include type="gif" name="ID_LOGO" file="images/logo.gif" /> </includes> <messages first_id="10000"> <message name="IDS_FIRSTPRESENTSTRING" desc="Present in .rc file."> I will appear in the .rc file. </message> <if expr="False"> <!--Do not include in the .rc files until used.--> <message name="IDS_MISSINGSTRING" desc="Not present in .rc file."> I will not appear in the .rc file. </message> </if> <if expr="lang != 'es'"> <message name="IDS_LANGUAGESPECIFICSTRING" desc="Present in .rc file."> Hello. </message> </if> <if expr="lang == 'es'"> <message name="IDS_LANGUAGESPECIFICSTRING" desc="Present in .rc file."> Hola. </message> </if> <message name="IDS_THIRDPRESENTSTRING" desc="Present in .rc file."> I will also appear in the .rc file. </message> </messages>''') output = self.FormatAll(grd) self.failUnless(output.count('IDS_FIRSTPRESENTSTRING10000')) self.failIf(output.count('IDS_MISSINGSTRING')) self.failUnless(output.count('IDS_LANGUAGESPECIFICSTRING10002')) self.failUnless(output.count('IDS_THIRDPRESENTSTRING10003'))
def testCompressBrotli(self): test_data_root = util.PathFromRoot('grit/testdata') root = util.ParseGrdForUnittest(''' <structures> <structure name="TEST_TXT" file="test_text.txt" compress="brotli" type="chrome_html" /> </structures>''', base_dir=test_data_root) node, = root.GetChildrenOfType(structure.StructureNode) node.RunPreSubstitutionGatherer() # Using the mock brotli decompression executable. brotli_util.SetBrotliCommand([ sys.executable, os.path.join(os.path.dirname(__file__), 'mock_brotli.py') ]) compressed = node.GetDataPackValue(lang='en', encoding=util.BINARY) # Assert that the first two bytes in compressed format is BROTLI_CONST. self.assertEqual(constants.BROTLI_CONST, compressed[0:2]) # Compare the actual size of the uncompressed test data with # the size appended during compression. actual_size = len( util.ReadFile(os.path.join(test_data_root, 'test_text.txt'), util.BINARY)) uncompress_size = struct.unpack('<i', compressed[2:6])[0] uncompress_size += struct.unpack('<h', compressed[6:8])[0] << 4 * 8 self.assertEqual(actual_size, uncompress_size) self.assertEqual(b'This has been mock compressed!', compressed[8:])
def testFormatResourceMapWithGeneratedFile(self): os.environ["root_gen_dir"] = "gen" grd = util.ParseGrdForUnittest('''\ <outputs> <output type="rc_header" filename="the_rc_header.h" /> <output type="resource_map_header" filename="resource_map_header.h" /> </outputs> <release seq="3"> <includes first_id="10000"> <include type="BINDATA" file="${root_gen_dir}/foo/bar/baz.js" name="IDR_FOO_BAR_BAZ_JS" use_base_dir="false" compress="gzip" /> </includes> </release>''', run_gatherers=True) formatter = resource_map.GetFormatter('resource_file_map_source') output = util.StripBlankLinesAndComments(''.join( formatter(grd, 'en', '.'))) expected = '''\ #include "resource_map_header.h" #include <stddef.h> #include "base/stl_util.h" #include "the_rc_header.h" const GritResourceMap kTheRcHeader[] = { {"@out_folder@/gen/foo/bar/baz.js", IDR_FOO_BAR_BAZ_JS}, }; const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''' self.assertEqual(expected, output)
def testConflictingPlurals(self): root = util.ParseGrdForUnittest(r""" <messages> <message name="IDS_PLURALS" desc="A string using the ICU plural format"> {NUM_THINGS, plural, =1 {Maybe I'll get one laser.} one {Maybe I'll get one laser.} other {Maybe I'll get # lasers.}} </message> </messages> """) buf = StringIO() build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) output = buf.getvalue() expected = r""" <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <plurals name="plurals"> <item quantity="one">"Maybe I\'ll get one laser."</item> <item quantity="other">"Maybe I\'ll get %d lasers."</item> </plurals> </resources> """ self.assertEqual(output.strip(), expected.strip())
def testTranslations(self): root = util.ParseGrdForUnittest(""" <messages> <message name="ID_HELLO">Hello!</message> <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex> Joi</ex></ph></message> </messages> """) buf = StringIO.StringIO() build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), buf) output = buf.getvalue() test = u""" { "ID_HELLO": { "message": "H\u00e9P\u00e9ll\u00f4P\u00f4!" }, "ID_HELLO_USER": { "message": "H\u00e9P\u00e9ll\u00f4P\u00f4 %s" } } """ self.assertEqual(json.loads(test), json.loads(output))
def testMessages(self): root = util.ParseGrdForUnittest(r""" <messages> <message name="IDS_SIMPLE" desc="A vanilla string"> Martha </message> <message name="IDS_ONE_LINE" desc="On one line">sat and wondered</message> <message name="IDS_QUOTES" desc="A string with quotation marks"> out loud, "Why don't I build a flying car?" </message> <message name="IDS_MULTILINE" desc="A string split over several lines"> She gathered wood, charcoal, and a sledge hammer. </message> <message name="IDS_WHITESPACE" desc="A string with extra whitespace."> ''' How old fashioned -- she thought. ''' </message> <message name="IDS_PLACEHOLDERS" desc="A string with placeholders"> I'll buy a <ph name="WAVELENGTH">%d<ex>200</ex></ph> nm laser at <ph name="STORE_NAME">%s<ex>the grocery store</ex></ph>. </message> <message name="IDS_PLURALS" desc="A string using the ICU plural format"> {NUM_THINGS, plural, =1 {Maybe I'll get one laser.} other {Maybe I'll get # lasers.}} </message> <message name="IDS_PLURALS_NO_SPACE" desc="A string using the ICU plural format with no space"> {NUM_MISSISSIPPIS, plural, =1{OneMississippi}other{ManyMississippis}} </message> </messages> """) buf = StringIO() build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) output = buf.getvalue() expected = r""" <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <string name="simple">"Martha"</string> <string name="one_line">"sat and wondered"</string> <string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string> <string name="multiline">"She gathered wood, charcoal, and a sledge hammer."</string> <string name="whitespace">" How old fashioned -- she thought. "</string> <string name="placeholders">"I\'ll buy a %d nm laser at %s."</string> <plurals name="plurals"> <item quantity="one">"Maybe I\'ll get one laser."</item> <item quantity="other">"Maybe I\'ll get %d lasers."</item> </plurals> <plurals name="plurals_no_space"> <item quantity="one">"OneMississippi"</item> <item quantity="other">"ManyMississippis"</item> </plurals> </resources> """ self.assertEqual(output.strip(), expected.strip())
def testValidAndroidIntegerWidthFormatInPhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_ANDROID_WIDTH"> <ph name="VALID">%2$3d<ex>042</ex></ph> </message> </messages>""") except: self.fail('Should not have gotten exception')
def testCompressGzip(self): root = util.ParseGrdForUnittest(''' <includes> <include name="TEST_TXT" file="test_text.txt" compress="gzip" type="BINDATA"/> </includes>''', base_dir = util.PathFromRoot('grit/testdata')) inc, = root.GetChildrenOfType(include.IncludeNode) compressed = inc.GetDataPackValue(lang='en', encoding=1) decompressed_data = zlib.decompress(compressed, 16 + zlib.MAX_WBITS)
def testRemoveByteOrderMark(self): root = util.ParseGrdForUnittest(u''' <messages> <message name="IDS_HAS_BOM" desc=""> \uFEFFThis\uFEFF i\uFEFFs OK\uFEFF </message> </messages>''') msg, = root.GetChildrenOfType(message.MessageNode) content = msg.Translate('en') self.failUnlessEqual(u'This is OK', content)
def testValidMultipleDollarFormatInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_DOLLARS" desc="l10n dollars format"> <ph name="VALID">$$1</ph> </message> </messages>""") except: self.fail('Should not have gotten exception')
def testValidHTMLEntityFormatInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_ENTITY"> <ph name="VALID">>%1$d<<ex>1</ex></ph> </message> </messages>""") except: self.fail('Should not have gotten exception')
def testValidHTMLWithAttributesFormatInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_HTML_ATTRIBUTE"> <ph name="VALID"><span attribute="js:$this %">$2</span><ex>2</ex></ph> </message> </messages>""") except: self.fail('Should not have gotten exception')
def testValidHTMLFormatInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_HTML"> <ph name="VALID"><span>$1</span><ex>1</ex></ph> </message> </messages>""") except: self.fail('Should not have gotten exception')
def testFormatStringResourceMap(self): grd = util.ParseGrdForUnittest(''' <outputs> <output type="rc_header" filename="the_rc_header.h" /> <output type="resource_map_header" filename="the_rc_map_header.h" /> <output type="resource_map_source" filename="the_rc_map_source.cc" /> </outputs> <release seq="1" allow_pseudo="false"> <messages fallback_to_english="true"> <message name="IDS_PRODUCT_NAME" desc="The application name"> Application </message> <if expr="True"> <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE" desc="In Title Case: The default title in a tab."> New Tab </message> </if> <if expr="False"> <message name="IDS_DEFAULT_TAB_TITLE" desc="The default title in a tab."> New tab </message> </if> </messages> </release>''', run_gatherers=True) grd.InitializeIds() output = util.StripBlankLinesAndComments(''.join( resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) self.assertEqual( '''\ #include <stddef.h> #ifndef GRIT_RESOURCE_MAP_STRUCT_ #define GRIT_RESOURCE_MAP_STRUCT_ struct GritResourceMap { const char* const name; int value; }; #endif // GRIT_RESOURCE_MAP_STRUCT_ extern const GritResourceMap kTheRcHeader[]; extern const size_t kTheRcHeaderSize;''', output) output = util.StripBlankLinesAndComments(''.join( resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) self.assertEqual( '''\ #include "the_rc_map_header.h" #include <stddef.h> #include "base/stl_util.h" #include "the_rc_header.h" const GritResourceMap kTheRcHeader[] = { {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME}, {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE}, }; const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
def testMultipleFormattersAreInsidePhNodes(self): failed = True try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_MULTIPLE_FORMATTERS"> %1$d error, %2$d warning </message> </messages>""") except exception.PlaceholderNotInsidePhNode: failed = False if failed: self.fail('Should have gotten exception') return failed = True try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_MULTIPLE_FORMATTERS"> <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, %2$d warning </message> </messages>""") except exception.PlaceholderNotInsidePhNode: failed = False if failed: self.fail('Should have gotten exception') return failed = True try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_MULTIPLE_FORMATTERS"> <ph name="INVALID">%1$d %2$d</ph> </message> </messages>""") except exception.InvalidCharactersInsidePhNode: failed = False if failed: self.fail('Should have gotten exception') return
def testNonDefaultEntry(self): grd = util.ParseGrdForUnittest(''' <messages> <message name="IDS_A" desc="foo">bar</message> <if expr="lang == 'fr'"> <message name="IDS_B" desc="foo">bar</message> </if> </messages>''') grd.SetOutputLanguage('fr') output = ''.join(rc_header.Format(grd, 'fr', '.')) self.assertIn('#define IDS_A 2378\n#define IDS_B 2379', output)
def testWindowsETWIntegerFormatIsInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_WINDOWS_ETW" desc="ETW tracing integer"> This message is missing the ph node: %1 </message> </messages>""") except exception.PlaceholderNotInsidePhNode: return self.fail('Should have gotten exception')
def testReplaceEllipsis(self): root = util.ParseGrdForUnittest(''' <messages> <message name="IDS_GREETING" desc=""> A...B.... <ph name="PH">%s<ex>A</ex></ph>... B... C... </message> </messages>''') msg, = root.GetChildrenOfType(message.MessageNode) msg.SetReplaceEllipsis(True) content = msg.Translate('en') self.failUnlessEqual(u'A...B.... %s\u2026 B\u2026 C\u2026', content)
def testInvalidMixedFormatCharactersInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_MIXED_FORMATS"> <ph name="INVALID">%1$2</ph> </message> </messages>""") except exception.InvalidCharactersInsidePhNode: return self.fail('Should have gotten exception')
def testInvalidPercentCharacterInsidePhNode(self): try: util.ParseGrdForUnittest("""\ <messages> <message name="IDS_BAD_PERCENT"> <ph name="INVALID">%1$d %</ph> </message> </messages>""") except exception.InvalidCharactersInsidePhNode: return self.fail('Should have gotten exception')
def testValidMultipleFormattersInsidePhNodes(self): root = util.ParseGrdForUnittest("""\ <messages> <message name="IDS_MULTIPLE_FORMATTERS"> <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNING_COUNT">%2$d<ex>1</ex></ph> warning </message> </messages>""") msg, = root.GetChildrenOfType(message.MessageNode) cliques = msg.GetCliques() content = cliques[0].GetMessage().GetPresentableContent() self.failUnless(content == 'ERROR_COUNT error, WARNING_COUNT warning')