コード例 #1
0
ファイル: test_truncation.py プロジェクト: jhauberg/comply
def test_text_truncated_at_ends():
    middle_index = int(len(TEXT) / 2)

    truncated_text = truncated(TEXT,
                               length=LENGTH,
                               options=Ellipsize.options(Ellipsize.ends, index=middle_index))

    assert truncated_text == '...d pi...'
コード例 #2
0
    def collect(self, file: CheckFile):
        offenders = []

        for match in self.pattern.finditer(file.original):
            message = match.group(1)
            message = truncated(message.strip(),
                                length=60,
                                options=Ellipsize.options(at=Ellipsize.end))

            offender = self.violate_at_match(file, at=match)
            offender.meta = {'todo': message}

            offenders.append(offender)

        return offenders
コード例 #3
0
ファイル: base.py プロジェクト: jhauberg/comply
    def report_before_checking(self,
                               path: str,
                               encoding: str = None,
                               show_progress: bool = True):
        """ Print a diagnostic before initiating a check on a given file. """

        if self.is_verbose:
            normalized_path = os.path.normpath(path)

            encoding = (' ({0})'.format(encoding.upper())
                        if encoding is not None else '')

            progress = (' [{n:0{width}d}/{total}]'.format(
                n=self.files_encountered,
                width=len(str(self.files_total)),
                total=self.files_total)
                        if self.files_total > 1 and show_progress else '')

            diag = 'Checking \'{path}\'{enc}{progress} '.format(
                path=truncated(normalized_path),
                enc=encoding,
                progress=progress)

            printdiag(diag, end='')
コード例 #4
0
ファイル: test_truncation.py プロジェクト: jhauberg/comply
def test_text_truncated_at_end():
    truncated_text = truncated(TEXT,
                               length=LENGTH,
                               options=Ellipsize.options(Ellipsize.end))

    assert truncated_text == 'a trunc...'
コード例 #5
0
ファイル: test_truncation.py プロジェクト: jhauberg/comply
def test_text_truncated_at_middle():
    truncated_text = truncated(TEXT,
                               length=LENGTH,
                               options=Ellipsize.options(Ellipsize.middle))

    assert truncated_text == 'a tr...ext'
コード例 #6
0
ファイル: test_truncation.py プロジェクト: jhauberg/comply
def test_text_truncated_at_start():
    truncated_text = truncated(TEXT,
                               length=LENGTH,
                               options=Ellipsize.options(Ellipsize.start))

    assert truncated_text == '...of text'