Пример #1
0
def test_removeinvalidamp(recwarn):
    """tests the the removeinvalidamps function"""

    def tester(actual, expected):
        assert dtd.removeinvalidamps("test.name", actual) == expected
    tester("Valid &entity; included", "Valid &entity; included")
    tester("Valid &entity.name; included", "Valid &entity.name; included")
    tester("Valid Ӓ included", "Valid Ӓ included")
    tester("This &amp is broken", "This amp is broken")
    tester("Mad & &amp &", "Mad  amp &")
    dtd.removeinvalidamps("simple.warningtest", "Dimpled &Ring")
    assert recwarn.pop(UserWarning)
Пример #2
0
def applytranslation(entity, dtdunit, inputunit, mixedentities):
    """applies the translation for entity in the po unit to the dtd unit"""
    # this converts the po-style string to a dtd-style string
    unquotedstr = inputunit.target
    # check there aren't missing entities...
    if len(unquotedstr.strip()) == 0:
        return
    # handle mixed entities
    for labelsuffix in dtd.labelsuffixes:
        if entity.endswith(labelsuffix):
            if entity in mixedentities:
                unquotedstr, akey = accesskey.extract(unquotedstr)
                break
    else:
        for akeytype in dtd.accesskeysuffixes:
            if entity.endswith(akeytype):
                if entity in mixedentities:
                    label, unquotedstr = accesskey.extract(unquotedstr)
                    if not unquotedstr:
                        warnings.warn("Could not find accesskey for %s" % entity)
                    else:
                        original = dtd.unquotefromdtd(dtdunit.definition)
                        # For the sake of diffs we keep the case of the
                        # accesskey the same if we know the translation didn't
                        # change. Casing matters in XUL.
                        if unquotedstr == dtdunit.source and original.lower() == unquotedstr.lower():
                            if original.isupper():
                                unquotedstr = unquotedstr.upper()
                            elif original.islower():
                                unquotedstr = unquotedstr.lower()
    if len(unquotedstr) > 0:
        dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(entity, unquotedstr))
Пример #3
0
def test_removeinvalidamp(recwarn):
    """tests the the removeinvalidamps function"""

    def tester(actual, expected=None):
        if expected is None:
            expected = actual
        assert dtd.removeinvalidamps("test.name", actual) == expected
    # No errors
    tester("Valid &entity; included")
    tester("Valid &entity.name; included")
    tester("Valid Ӓ included")
    tester("Valid &entity_name;")
    # Errors that require & removal
    tester("This &amp is broken", "This amp is broken")
    tester("Mad & &amp &", "Mad  amp &")
    dtd.removeinvalidamps("simple.warningtest", "Dimpled &Ring")
    assert recwarn.pop(UserWarning)
Пример #4
0
 def convertstrings(self, inputunit, dtdunit):
     if inputunit.istranslated() or not bool(inputunit.source):
         unquoted = inputunit.target
     elif self.remove_untranslated:
         unquoted = None
     else:
         unquoted = inputunit.source
     dtdunit.source = dtd.removeinvalidamps(dtdunit.entity, unquoted)
Пример #5
0
 def convertstrings(self, inputunit, dtdunit):
     if inputunit.istranslated():
         unquoted = inputunit.target
     else:
         unquoted = inputunit.source
     dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(dtdunit.entity, unquoted))
Пример #6
0
 def tester(actual, expected=None):
     if expected is None:
         expected = actual
     assert dtd.removeinvalidamps("test.name", actual) == expected
Пример #7
0
 def tester(actual, expected):
     assert dtd.removeinvalidamps("test.name", actual) == expected
Пример #8
0
 def tester(actual, expected=None):
     if expected is None:
         expected = actual
     assert dtd.removeinvalidamps("test.name", actual) == expected
Пример #9
0
 def tester(actual, expected):
     assert dtd.removeinvalidamps("test.name", actual) == expected