Esempio n. 1
0
 def _test(self, content, refWarnOrErrors):
     p = getParser(self.file.file)
     p.readContents(content)
     l10n = [e for e in p]
     checks = getChecks(self.file)
     found = tuple(checks(self.refs[0], l10n[0]))
     self.assertEqual(found, refWarnOrErrors)
Esempio n. 2
0
 def _test(self, content, refWarnOrErrors):
     p = getParser(self.file.file)
     p.readContents(content)
     l10n = [e for e in p]
     assert len(l10n) == 1
     l10n = l10n[0]
     checks = getChecks(self.file)
     ref = self.refList[self.refMap[l10n.key]]
     found = tuple(checks(ref, l10n))
     self.assertEqual(found, refWarnOrErrors)
Esempio n. 3
0
 def _test(self, content, refWarnOrErrors):
     p = getParser(self.file.file)
     p.readContents(content)
     l10n = [e for e in p]
     assert len(l10n) == 1
     l10n = l10n[0]
     checks = getChecks(self.file)
     ref = self.refList[self.refMap[l10n.key]]
     found = tuple(checks(ref, l10n))
     self.assertEqual(found, refWarnOrErrors)
Esempio n. 4
0
 def test_non_android_dtd(self):
     f = File("browser/strings.dtd", "strings.dtd", "browser")
     checks = getChecks(f)
     # good string
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
     # dtd warning
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string &ref;")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('warning', (0, 0), 'Referencing unknown entity `ref`', 'xmlparse'),))
     # no report on stray ampersand
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string with apos: '")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
Esempio n. 5
0
 def test_non_android_dtd(self):
     f = File("browser/strings.dtd", "strings.dtd", "browser")
     checks = getChecks(f)
     # good string
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string")
     self.assertEqual(tuple(checks(ref, l10n)), ())
     # dtd warning
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string &ref;")
     self.assertEqual(
         tuple(checks(ref, l10n)),
         (('warning',
           (0, 0), 'Referencing unknown entity `ref`', 'xmlparse'), ))
     # no report on stray ampersand
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string with apos: '")
     self.assertEqual(tuple(checks(ref, l10n)), ())
Esempio n. 6
0
 def test_android_prop(self):
     f = File("embedding/android/strings.properties", "strings.properties",
              "embedding/android")
     checks = getChecks(f)
     # good plain string
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string")
     self.assertEqual(tuple(checks(ref, l10n)), ())
     # no dtd warning
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string &ref;")
     self.assertEqual(tuple(checks(ref, l10n)), ())
     # no report on stray ampersand
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string with apos: '")
     self.assertEqual(tuple(checks(ref, l10n)), ())
     # report on bad printf
     ref = self.getEntity("string with %s")
     l10n = self.getEntity("string with %S")
     self.assertEqual(
         tuple(checks(ref, l10n)),
         (('error', 0, 'argument 1 `S` should be `s`', 'printf'), ))
Esempio n. 7
0
 def test_android_prop(self):
     f = File("embedding/android/strings.properties", "strings.properties", "embedding/android")
     checks = getChecks(f)
     # good plain string
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
     # no dtd warning
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string &ref;")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
     # no report on stray ampersand
     ref = self.getEntity("plain string")
     l10n = self.getEntity("plain localized string with apos: '")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
     # report on bad printf
     ref = self.getEntity("string with %s")
     l10n = self.getEntity("string with %S")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 0, 'argument 1 `S` should be `s`', 'printf'),))
Esempio n. 8
0
 def test_android_dtd(self):
     """Testing the actual android checks. The logic is involved, so this is a lot
     of nitty gritty detail tests.
     """
     f = File("embedding/android/strings.dtd", "strings.dtd", "embedding/android")
     checks = getChecks(f)
     # good string
     ref = self.getDTDEntity("plain string")
     l10n = self.getDTDEntity("plain localized string")
     self.assertEqual(tuple(checks(ref, l10n)),
                      ())
     # dtd warning
     l10n = self.getDTDEntity("plain localized string &ref;")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('warning', (0, 0), 'Referencing unknown entity `ref`', 'xmlparse'),))
     # no report on stray ampersand or quote, if not completely quoted
     for i in xrange(3):
         # make sure we're catching unescaped apostrophes, try 0..5 backticks
         l10n = self.getDTDEntity("\\"*(2*i) + "'")
         self.assertEqual(tuple(checks(ref, l10n)),
                          (('error', 2*i, self.apos_msg, 'android'),))
         l10n = self.getDTDEntity("\\"*(2*i + 1) + "'")
         self.assertEqual(tuple(checks(ref, l10n)),
                          ())
         # make sure we don't report if apos string is quoted
         l10n = self.getDTDEntity('"' + "\\"*(2*i) + "'\"")
         tpl = tuple(checks(ref, l10n))
         self.assertEqual(tpl, (), "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
         l10n = self.getDTDEntity('"' + "\\"*(2*i+1) + "'\"")
         tpl = tuple(checks(ref, l10n))
         self.assertEqual(tpl, (), "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
         # make sure we're catching unescaped quotes, try 0..5 backticks
         l10n = self.getDTDEntity("\\"*(2*i) + "\"")
         self.assertEqual(tuple(checks(ref, l10n)),
                          (('error', 2*i, self.quot_msg, 'android'),))
         l10n = self.getDTDEntity("\\"*(2*i + 1) + "'")
         self.assertEqual(tuple(checks(ref, l10n)),
                          ())
         # make sure we don't report if quote string is single quoted
         l10n = self.getDTDEntity("'" + "\\"*(2*i) + "\"'")
         tpl = tuple(checks(ref, l10n))
         self.assertEqual(tpl, (), "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
         l10n = self.getDTDEntity('"' + "\\"*(2*i+1) + "'\"")
         tpl = tuple(checks(ref, l10n))
         self.assertEqual(tpl, (), "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
     # check for mixed quotes and ampersands
     l10n = self.getDTDEntity("'\"")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 0, self.apos_msg, 'android'),
                       ('error', 1, self.quot_msg, 'android')))
     l10n = self.getDTDEntity("''\"'")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 1, self.apos_msg, 'android'),))
     l10n = self.getDTDEntity('"\'""')
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 2, self.quot_msg, 'android'),))
     
     # broken unicode escape
     l10n = self.getDTDEntity("Some broken \u098 unicode")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 12, 'truncated \\uXXXX escape', 'android'),))
     # broken unicode escape, try to set the error off
     l10n = self.getDTDEntity(u"\u9690"*14+"\u006"+"  "+"\u0064")
     self.assertEqual(tuple(checks(ref, l10n)),
                      (('error', 14, 'truncated \\uXXXX escape', 'android'),))
Esempio n. 9
0
    def test_android_dtd(self):
        """Testing the actual android checks. The logic is involved, so this is a lot
        of nitty gritty detail tests.
        """
        f = File("embedding/android/strings.dtd", "strings.dtd",
                 "embedding/android")
        checks = getChecks(f)
        # good string
        ref = self.getDTDEntity("plain string")
        l10n = self.getDTDEntity("plain localized string")
        self.assertEqual(tuple(checks(ref, l10n)), ())
        # dtd warning
        l10n = self.getDTDEntity("plain localized string &ref;")
        self.assertEqual(
            tuple(checks(ref, l10n)),
            (('warning',
              (0, 0), 'Referencing unknown entity `ref`', 'xmlparse'), ))
        # no report on stray ampersand or quote, if not completely quoted
        for i in xrange(3):
            # make sure we're catching unescaped apostrophes, try 0..5 backticks
            l10n = self.getDTDEntity("\\" * (2 * i) + "'")
            self.assertEqual(tuple(checks(ref, l10n)),
                             (('error', 2 * i, self.apos_msg, 'android'), ))
            l10n = self.getDTDEntity("\\" * (2 * i + 1) + "'")
            self.assertEqual(tuple(checks(ref, l10n)), ())
            # make sure we don't report if apos string is quoted
            l10n = self.getDTDEntity('"' + "\\" * (2 * i) + "'\"")
            tpl = tuple(checks(ref, l10n))
            self.assertEqual(
                tpl, (),
                "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
            l10n = self.getDTDEntity('"' + "\\" * (2 * i + 1) + "'\"")
            tpl = tuple(checks(ref, l10n))
            self.assertEqual(
                tpl, (),
                "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
            # make sure we're catching unescaped quotes, try 0..5 backticks
            l10n = self.getDTDEntity("\\" * (2 * i) + "\"")
            self.assertEqual(tuple(checks(ref, l10n)),
                             (('error', 2 * i, self.quot_msg, 'android'), ))
            l10n = self.getDTDEntity("\\" * (2 * i + 1) + "'")
            self.assertEqual(tuple(checks(ref, l10n)), ())
            # make sure we don't report if quote string is single quoted
            l10n = self.getDTDEntity("'" + "\\" * (2 * i) + "\"'")
            tpl = tuple(checks(ref, l10n))
            self.assertEqual(
                tpl, (),
                "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
            l10n = self.getDTDEntity('"' + "\\" * (2 * i + 1) + "'\"")
            tpl = tuple(checks(ref, l10n))
            self.assertEqual(
                tpl, (),
                "`%s` shouldn't fail but got %s" % (l10n.val, str(tpl)))
        # check for mixed quotes and ampersands
        l10n = self.getDTDEntity("'\"")
        self.assertEqual(tuple(checks(ref, l10n)),
                         (('error', 0, self.apos_msg, 'android'),
                          ('error', 1, self.quot_msg, 'android')))
        l10n = self.getDTDEntity("''\"'")
        self.assertEqual(tuple(checks(ref, l10n)),
                         (('error', 1, self.apos_msg, 'android'), ))
        l10n = self.getDTDEntity('"\'""')
        self.assertEqual(tuple(checks(ref, l10n)),
                         (('error', 2, self.quot_msg, 'android'), ))

        # broken unicode escape
        l10n = self.getDTDEntity("Some broken \u098 unicode")
        self.assertEqual(
            tuple(checks(ref, l10n)),
            (('error', 12, 'truncated \\uXXXX escape', 'android'), ))
        # broken unicode escape, try to set the error off
        l10n = self.getDTDEntity(u"\u9690" * 14 + "\u006" + "  " + "\u0064")
        self.assertEqual(
            tuple(checks(ref, l10n)),
            (('error', 14, 'truncated \\uXXXX escape', 'android'), ))