def test_complex(self): data = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo: {bar} {baz}"\n' 'msgstr "Oof: {foo} {bar}"\n') linter = Linter(['python']) results = linter.verify_file(data) eq_(len(results), 1) eq_(results[0].missing, [u'{baz}']) eq_(results[0].invalid, [u'{foo}'])
def test_linter_untranslated_strings(self): pofile = build_po_string( '#, fuzzy\n' '#~ msgid "Most Recent Message"\n' '#~ msgid_plural "Last %(count)s Messages"\n' '#~ msgstr[0] ""\n' '#~ msgstr[1] ""\n') linter = Linter(['pysprintf', 'pyformat'], ['E201', 'W202']) results = linter.verify_file(pofile) # There were no translated strings, so nothing to lint. eq_(len(results), 0)
def test_linter_fuzzy_strings(self): pofile = build_po_string( '#, fuzzy\n' '#~ msgid "Most Recent Message"\n' '#~ msgid_plural "Last %(count)s Messages"\n' '#~ msgstr[0] "Les {count} derniers messages"\n' '#~ msgstr[1] "Les {count} derniers messages"\n') linter = Linter(['python'], ['mismatched']) results = linter.verify_file(pofile) # There were no non-fuzzy strings, so nothing to lint. eq_(len(results), 0)
def test_basic_pot(self): with tempdir() as dir_: pofile = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo: %(l)s"\n' 'msgstr ""\n') fn = os.path.join(dir_, 'messages.pot') with open(fn, 'w') as fp: fp.write(pofile) res = CliRunner().invoke(lint, [fn]) assert '>>> Working on:' in res.output
def test_linter(self): pofile = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo"\n' 'msgstr "Oof"\n') linter = Linter( ['python-format', 'python-brace-format'], ['E201', 'W202'] ) msgs = linter.verify_file(pofile) # No warnings or errors, so there are no messages. eq_(len(msgs), 0)
def test_linter(self): pofile = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo"\n' 'msgstr "Oof"\n') linter = Linter(['pysprintf', 'pyformat'], ['E201', 'W202']) results = linter.verify_file(pofile) # This should give us one linted entry with no errors # and no warnings in it. eq_(len(results), 1) eq_(len(results[0].errors), 0) eq_(len(results[0].warnings), 0)
def test_fine(self): po_string = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo"\n' 'msgstr "Oof"\n') linter = Linter(['python']) results = linter.verify_file(po_string) eq_(len(results), 1) eq_(results[0].missing, []) eq_(results[0].invalid, []) po_string = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo: {foo}"\n' 'msgstr "Oof: {foo}"\n') linter = Linter(['python']) results = linter.verify_file(po_string) eq_(len(results), 1) eq_(results[0].missing, []) eq_(results[0].invalid, [])
def test_linter_untranslated_strings(self): pofile = build_po_string( '#, fuzzy\n' '#~ msgid "Most Recent Message"\n' '#~ msgid_plural "Last %(count)s Messages"\n' '#~ msgstr[0] ""\n' '#~ msgstr[1] ""\n') linter = Linter( ['python-format', 'python-brace-format'], ['E201', 'W202'] ) msgs = linter.verify_file(pofile) # There were no translated strings, so nothing to lint. eq_(len(msgs), 0)
def test_basic(self): with tempdir() as dir_: pofile = build_po_string( '#: foo/foo.py:5\n' 'msgid "Foo: %(l)s"\n' 'msgstr "Gmorp!"\n') fn = os.path.join(dir_, 'messages.po') with open(fn, 'w') as fp: fp.write(pofile) res = CliRunner().invoke(lint, ['--no-color', fn]) # The dennis version will change and the temp directory # we're using will change, so we're lenient when checking # the first two lines. line, output = res.output.split('\n', 1) assert line.startswith('dennis version') line, output = output.split('\n', 1) assert line.startswith('>>> Working on') # Note: This test will fail if we ever tweak the # output. That's ok--just verify the new output and update # the test. eq_(output, textwrap.dedent(u"""\ W202: missing variables: %(l)s 15:#: foo/foo.py:5 16:msgid "Foo: %(l)s" 17:msgstr "Gmorp!" Totals Warnings: 1 Errors: 0 """))
def build_linted_entry(po_data): po = polib.pofile(build_po_string(po_data)) poentry = list(po)[0] return LintedEntry(poentry)