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 & is broken", "This amp is broken") tester("Mad & & &", "Mad amp &") dtd.removeinvalidamps("simple.warningtest", "Dimpled &Ring") assert recwarn.pop(UserWarning)
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))
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 & is broken", "This amp is broken") tester("Mad & & &", "Mad amp &") dtd.removeinvalidamps("simple.warningtest", "Dimpled &Ring") assert recwarn.pop(UserWarning)
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)
def convertstrings(self, inputunit, dtdunit): if inputunit.istranslated(): unquoted = inputunit.target else: unquoted = inputunit.source dtdunit.definition = dtd.quotefordtd(dtd.removeinvalidamps(dtdunit.entity, unquoted))
def tester(actual, expected=None): if expected is None: expected = actual assert dtd.removeinvalidamps("test.name", actual) == expected
def tester(actual, expected): assert dtd.removeinvalidamps("test.name", actual) == expected