Ejemplo n.º 1
0
 def testHtmlPlaceholderize(self):
   tool = rc2grd.Rc2Grd()
   original = "Hello <b>[USERNAME]</b>, how are you? I'm [AGE] years old!"
   msg = tool.Placeholderize(original)
   self.failUnless(msg.GetPresentableContent() ==
                   "Hello BEGIN_BOLDX_USERNAME_XEND_BOLD, how are you? I'm X_AGE_X years old!")
   self.failUnless(msg.GetRealContent() == original)
Ejemplo n.º 2
0
 def testPlaceholderize(self):
     tool = rc2grd.Rc2Grd()
     original = "Hello %s, how are you? I'm $1 years old!"
     msg = tool.Placeholderize(original)
     self.failUnless(msg.GetPresentableContent(
     ) == "Hello TODO_0001, how are you? I'm TODO_0002 years old!")
     self.failUnless(msg.GetRealContent() == original)
Ejemplo n.º 3
0
  def testPreProcessing(self):
    tool = rc2grd.Rc2Grd()
    class DummyOpts(object):
      verbose = False
      extra_verbose = False
    tool.o = DummyOpts()
    tool.pre_process = 'grit.tool.preprocess_unittest.DummyPreProcessor'
    result = tool.Process('', '.\resource.rc')

    self.failUnless(
      result.children[2].children[2].children[0].attrs['name'] == 'DUMMY_STRING_1')
Ejemplo n.º 4
0
 def Setup(self, globopt, args):
     '''Sets the instance up for use.
 '''
     self.SetOptions(globopt)
     self.rc2grd = rc2grd.Rc2Grd()
     self.rc2grd.SetOptions(globopt)
     self.limits = None
     if len(args) and args[0] == '-l':
         self.limits = util.ReadFile(args[1], util.RAW_TEXT).split('\n')
         args = args[2:]
     return self.rc2grd.ParseOptions(args)
Ejemplo n.º 5
0
    def testRoleModel(self):
        rc_text = (
            'STRINGTABLE\n'
            'BEGIN\n'
            '  // This should not show up\n'
            '  IDS_BINGO "Hello %s, how are you?"\n'
            '  // The first description\n'
            '  IDS_BONGO "Hello %s, my name is %s, and yours?"\n'
            '  IDS_PROGRAMS_SHUTDOWN_TEXT      "Google Desktop Search needs to close the following programs:\\n\\n$1\\nThe installation will not proceed if you choose to cancel."\n'
            'END\n')
        tool = rc2grd.Rc2Grd()
        tool.role_model = grd_reader.Parse(
            StringIO('''<?xml version="1.0" encoding="UTF-8"?>
      <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir=".">
        <release seq="3">
          <messages>
            <message name="IDS_BINGO">
              Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you?
            </message>
            <message name="IDS_BONGO" desc="The other description">
              Hello <ph name="USERNAME">%s<ex>Jakob</ex></ph>, my name is <ph name="ADMINNAME">%s<ex>Joi</ex></ph>, and yours?
            </message>
            <message name="IDS_PROGRAMS_SHUTDOWN_TEXT" desc="LIST_OF_PROGRAMS is replaced by a bulleted list of program names.">
              Google Desktop Search needs to close the following programs:

<ph name="LIST_OF_PROGRAMS">$1<ex>Program 1, Program 2</ex></ph>
The installation will not proceed if you choose to cancel.
            </message>
          </messages>
        </release>
      </grit>'''),
            dir='.')

        # test rig
        class DummyOpts(object):
            verbose = False
            extra_verbose = False

        tool.o = DummyOpts()
        result = tool.Process(rc_text, '.\resource.rc')
        self.failUnless(
            result.children[2].children[2].children[0].attrs['desc'] == '')
        self.failUnless(result.children[2].children[2].children[0].children[0].
                        attrs['name'] == 'USERNAME')
        self.failUnless(result.children[2].children[2].children[1].
                        attrs['desc'] == 'The other description')
        self.failUnless(
            result.children[2].children[2].children[1].attrs['meaning'] == '')
        self.failUnless(result.children[2].children[2].children[1].children[0].
                        attrs['name'] == 'USERNAME')
        self.failUnless(result.children[2].children[2].children[1].children[1].
                        attrs['name'] == 'ADMINNAME')
        self.failUnless(result.children[2].children[2].children[2].children[0].
                        attrs['name'] == 'LIST_OF_PROGRAMS')
Ejemplo n.º 6
0
    def testMissingOutput(self):
        """Verify failure with no args."""
        tool = rc2grd.Rc2Grd()

        class DummyOpts(object):
            verbose = False
            extra_verbose = False

        ret = tool.Run(DummyOpts(), [])
        self.assertIsNotNone(ret)
        self.assertGreater(ret, 0)
Ejemplo n.º 7
0
 def Setup(self, globopt, args):
     '''Sets the instance up for use.
 '''
     self.SetOptions(globopt)
     self.rc2grd = rc2grd.Rc2Grd()
     self.rc2grd.SetOptions(globopt)
     self.limits = None
     if len(args) and args[0] == '-l':
         self.limits = util.ReadFile(args[1], 'utf-8').splitlines()
         args = args[2:]
     return self.rc2grd.ParseOptions(args, help_func=self.ShowUsage)
Ejemplo n.º 8
0
 def Setup(self, globopt, args):
     '''Sets the instance up for use.
 '''
     self.SetOptions(globopt)
     self.rc2grd = rc2grd.Rc2Grd()
     self.rc2grd.SetOptions(globopt)
     self.limits = None
     if len(args) and args[0] == '-l':
         limit_file = file(args[1])
         self.limits = limit_file.read().split('\n')
         limit_file.close()
         args = args[2:]
     return self.rc2grd.ParseOptions(args)
Ejemplo n.º 9
0
    def testRunOutput(self):
        """Verify basic correct Run behavior."""
        tool = rc2grd.Rc2Grd()

        class DummyOpts(object):
            verbose = False
            extra_verbose = False

        with util.TempDir({}) as output_dir:
            rcfile = os.path.join(output_dir.GetPath(), 'foo.rc')
            open(rcfile, 'w').close()
            self.assertIsNone(tool.Run(DummyOpts(), [rcfile]))
            self.assertTrue(
                os.path.exists(os.path.join(output_dir.GetPath(), 'foo.grd')))
Ejemplo n.º 10
0
  def testRegressionScriptWithTranslateable(self):
    tool = rc2grd.Rc2Grd()

    # test rig
    class DummyNode(base.Node):
      def AddChild(self, item):
        self.node = item
      verbose = False
      extra_verbose = False
    tool.not_localizable_re = re.compile('')
    tool.o = DummyNode()

    rc_text = '''STRINGTABLE\nBEGIN\nID_BINGO "<SPAN id=hp style='BEHAVIOR: url(#default#homepage)'></SPAN><script>if (!hp.isHomePage('[$~HOMEPAGE~$]')) {document.write(""<a href=\\""[$~SETHOMEPAGEURL~$]\\"" >Set As Homepage</a> - "");}</script>"\nEND\n'''
    tool.AddMessages(rc_text, tool.o)
    self.failUnless(tool.o.node.GetCdata().find('Set As Homepage') != -1)

    # TODO(joi) Improve the HTML parser to support translateables inside
    # <script> blocks?
    self.failUnless(tool.o.node.attrs['translateable'] == 'false')
Ejemplo n.º 11
0
  def testPostProcessing(self):
    rctext = '''STRINGTABLE
BEGIN
  DUMMY_STRING_1         "String 1"
  // Some random description
  DUMMY_STRING_2        "This text was added during preprocessing"
END
    '''
    tool = rc2grd.Rc2Grd()
    class DummyOpts(object):
      verbose = False
      extra_verbose = False
    tool.o = DummyOpts()
    tool.post_process = 'grit.tool.postprocess_unittest.DummyPostProcessor'
    result = tool.Process(rctext, '.\resource.rc')

    self.failUnless(
      result.children[2].children[2].children[0].attrs['name'] == 'SMART_STRING_1')
    self.failUnless(
      result.children[2].children[2].children[1].attrs['name'] == 'SMART_STRING_2')