File: test_tools.py

package info (click to toggle)
python3-proselint 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,220 kB
  • sloc: python: 7,173; sh: 6; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Test the tools module."""


from proselint.config import default
from proselint.tools import lint as proselint, load_options

from .check import Check


def lint(text):
    return proselint(text, config=load_options(conf_default=default))


class TestLint(Check):
    """The test class for tools.lint."""

    __test__ = True

    def setUp(self):
        """setUp method creating text fixtures."""
        self.text = """But this is a very bad sentence.
This is also a no-good sentence.

"""
        self.text_with_no_newline = """A very bad sentence."""

    def extract_line_col(self, error):
        """Extract the line and column number from an error tuple."""
        _, _, line, column, _, _, _, _, _ = error
        return line, column

    def test_errors_sorted(self):
        """Test that errors are sorted by line and column number."""
        lines_and_cols = [self.extract_line_col(e) for e in lint(self.text)]
        assert sorted(lines_and_cols) == lines_and_cols

    def test_on_no_newlines(self):
        """Test that lint works on text without a terminal newline."""
        assert len(lint(self.text_with_no_newline)) == 1