示例#1
0
    def test_linting_non_ascii_filename(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(foo)s bar baz"\n'
                                  'msgstr "Foo %(bar)s"\n')
        fn = tmpdir.join('T\xc3\xa9l\xc3\xa9chargements', 'messages.po')
        fn.write(po_file, ensure=True)

        result = runner.invoke(cli, ('lint', str(tmpdir)))
        assert result.exit_code == 1
示例#2
0
    def test_quiet(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo bar baz"\n'
                                  'msgstr "Foo"\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', '--quiet', str(fn)))
        assert result.exit_code == 0
        assert result.output == ''
示例#3
0
    def test_rules(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(bar)s baz"\n'
                                  'msgstr "FOO %(bar) BAZ"\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', '--rules', 'E101', str(fn)))
        assert result.exit_code == 1
        assert 'E101: type missing: %(bar)' in result.output
示例#4
0
    def test_template_rules(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(o)s baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.pot')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', '--rules', 'W501', str(fn)))
        assert result.exit_code == 0
        assert 'W501: one character variable name "o"' in result.output
示例#5
0
    def test_nonexisting_rule(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(o)s baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.pot')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', '--rules', 'foo', str(fn)))
        assert result.exit_code == 2
        assert 'Error: invalid rules: foo.' in result.output
示例#6
0
    def test_nonexisting_rule(self, runner, tmpdir):
        po_file = build_po_string("#: foo/foo.py:5\n"
                                  'msgid "Foo %(o)s baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join("messages.pot")
        fn.write(po_file)

        result = runner.invoke(cli, ("lint", "--rules", "foo", str(fn)))
        assert result.exit_code == 2
        assert "Error: invalid rules: foo." in result.output
示例#7
0
    def test_rules(self, runner, tmpdir):
        po_file = build_po_string("#: foo/foo.py:5\n"
                                  'msgid "Foo %(bar)s baz"\n'
                                  'msgstr "FOO %(bar) BAZ"\n')
        fn = tmpdir.join("messages.po")
        fn.write(po_file)

        result = runner.invoke(cli, ("lint", "--rules", "E101", str(fn)))
        assert result.exit_code == 1
        assert "E101: type missing: %(bar)" in result.output
示例#8
0
    def test_bad_pipeline(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo bar baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('translate', '-p', 'triangle', str(fn)))
        assert result.exit_code == 2
        last_line = result.output.splitlines()[-1]
        assert last_line == 'Error: pipeline "triangle" is not valid'
示例#9
0
    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.
        assert len(msgs) == 0
示例#10
0
    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.
        assert len(msgs) == 0
示例#11
0
    def test_basic_linting(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo bar baz"\n'
                                  'msgstr "Foo"\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', str(fn)))
        assert result.exit_code == 0
        output_lines = result.output.splitlines()
        assert len(output_lines) == 1
        assert output_lines[0].startswith('dennis version')
示例#12
0
    def test_linting_fail(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(foo)s bar baz"\n'
                                  'msgstr "Foo %(bar)s"\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', str(fn)))
        assert result.exit_code == 1
        output_lines = result.output.splitlines()
        assert len(output_lines) == 16
        assert 'E201: invalid variables: %(bar)s' in result.output
示例#13
0
    def test_excludes(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(o)s baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.pot')
        fn.write(po_file)

        result = runner.invoke(cli,
                               ('lint', '--excluderules', 'W501', str(fn)))
        assert result.exit_code == 0
        # The rule that generates this error is excluded, so this error shouldn't show up.
        assert 'W501: one character variable name "o"' not in result.output
示例#14
0
    def test_varformat_no_value(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo %(o)s baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.pot')
        fn.write(po_file)

        result = runner.invoke(cli, ('lint', '--varformat', '', str(fn)))

        assert result.exit_code == 0
        # We're not looking at any variables, so we should never have a variable related warning.
        assert 'W501: one character variable name "o"' not in result.output
示例#15
0
    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.
        assert len(msgs) == 0
示例#16
0
    def test_pipeline(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo bar baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)
        # Verify the last line is untranslated
        assert po_file.endswith('msgstr ""\n')

        result = runner.invoke(cli, ('translate', '-p', 'shouty', str(fn)))
        assert result.exit_code == 0
        last_line = fn.read().splitlines()[-1]
        # Verify the last line is now translated
        assert last_line == 'msgstr "FOO BAR BAZ"'
示例#17
0
    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.
        assert len(msgs) == 0
示例#18
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-format", "python-brace-format"],
                        ["E201", "W202"])
        msgs = linter.verify_file(pofile)

        # There were no non-fuzzy strings, so nothing to lint.
        assert len(msgs) == 0
示例#19
0
    def test_status_untranslated(self, runner, tmpdir):
        po_file = build_po_string("#: foo/foo.py:5\n"
                                  'msgid "Foo bar baz"\n'
                                  'msgstr ""\n')
        fn = tmpdir.join("messages.po")
        fn.write(po_file)

        result = runner.invoke(cli, ("status", str(fn)))
        assert result.exit_code == 0

        # FIXME: This would be a lot easier if the status was structured and parseable.
        pairs = build_key_val(result.output)
        assert pairs["Total strings"] == "1"
        assert pairs["Total translateable words"] == "3"
        assert pairs["Percentage"] == "0%"
示例#20
0
    def test_status_translated(self, runner, tmpdir):
        po_file = build_po_string('#: foo/foo.py:5\n'
                                  'msgid "Foo bar baz"\n'
                                  'msgstr "Feh"\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('status', str(fn)))
        assert result.exit_code == 0

        # FIXME: This would be a lot easier if the status was structured and parseable.
        pairs = build_key_val(result.output)
        assert pairs['Total strings'] == '1'
        assert pairs['Total translateable words'] == '3'
        assert pairs['Percentage'] == '100% COMPLETE!'
示例#21
0
    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.
        assert len(msgs) == 0
示例#22
0
    def test_plurals(self, runner, tmpdir):
        po_file = build_po_string(
            '#: test_project/base/views.py:12 test_project/base/views.py:22\n'
            '#, python-format\n'
            'msgid "%(num)s apple"\n'
            'msgid_plural "%(num)s apples"\n'
            'msgstr[0] ""\n'
            'msgstr[1] ""\n')
        fn = tmpdir.join('messages.po')
        fn.write(po_file)

        result = runner.invoke(cli, ('translate', '-p', 'shouty', str(fn)))
        assert result.exit_code == 0
        pot_file = nix_header(fn.read())
        # FIXME: This has the wrong variables, too. We need to fix that, too.
        assert (pot_file == dedent("""\
            #: test_project/base/views.py:12 test_project/base/views.py:22
            #, python-format
            msgid "%(num)s apple"
            msgid_plural "%(num)s apples"
            msgstr[0] "%(NUM)S APPLE"
            msgstr[1] "%(NUM)S APPLES"
            """))
示例#23
0
def build_linted_entry(po_data):
    po = polib.pofile(build_po_string(po_data))
    poentry = list(po)[0]
    return LintedEntry(poentry)
示例#24
0
def build_linted_entry(po_data):
    po = polib.pofile(build_po_string(po_data))
    poentry = list(po)[0]
    return LintedEntry(poentry)