Esempio n. 1
0
class Linter(object):
    def __init__(self, var_types):
        # FIXME - this is a horrible name
        self.vartok = VariableTokenizer(var_types)

    def verify_file(self, filename_or_string):
        """Verifies strings in file.

        :arg filename_or_string: filename to verify or the contents of
            a pofile as a string

        :returns: for each string in the pofile, this returns a None
            if there were no issues or a LintError if there were
            issues

        :raises IOError: if the file is not a valid .po file or
            doesn't exist
        """
        po = polib.pofile(filename_or_string)

        results = []

        for entry in po:
            if not entry.msgid_plural:
                if not entry.msgid and entry.msgstr:
                    continue
                id_tokens = self.vartok.extract_tokens(entry.msgid)
                str_tokens = self.vartok.extract_tokens(entry.msgstr)

                results.append(
                    LintItem(entry, entry.msgid, entry.msgid,
                             id_tokens, entry.msgstr,
                             str_tokens, None))

            else:
                for key in sorted(entry.msgstr_plural.keys()):
                    if key == '0':
                        # This is the 1 case.
                        text = entry.msgid
                    else:
                        text = entry.msgid_plural
                    id_tokens = self.vartok.extract_tokens(text)

                    str_tokens = self.vartok.extract_tokens(
                        entry.msgstr_plural[key])
                    results.append(
                        LintItem(entry, entry.msgid, text, id_tokens,
                                 entry.msgstr_plural[key],
                                 str_tokens, key))

        return results
Esempio n. 2
0
def test_empty_tokenizer():
    vartok = VariableTokenizer([])
    assert vartok.contains('python-format') is False
    assert vartok.tokenize('a b c d e') == ['a b c d e']
    assert vartok.extract_tokens('a b c d e') == set()
    assert vartok.is_token('{0}') is False
    assert vartok.extract_variable_name('{0}') is None
Esempio n. 3
0
def test_empty_tokenizer():
    vartok = VariableTokenizer([])
    assert vartok.contains("python-format") is False
    assert vartok.tokenize("a b c d e") == ["a b c d e"]
    assert vartok.extract_tokens("a b c d e") == set()
    assert vartok.is_token("{0}") is False
    assert vartok.extract_variable_name("{0}") is None
Esempio n. 4
0
def test_empty_tokenizer():
    vartok = VariableTokenizer([])
    assert vartok.contains('python-format') is False
    assert vartok.tokenize('a b c d e') == ['a b c d e']
    assert vartok.extract_tokens('a b c d e') == set()
    assert vartok.is_token('{0}') is False
    assert vartok.extract_variable_name('{0}') is None