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...'
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
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='')
def test_text_truncated_at_end(): truncated_text = truncated(TEXT, length=LENGTH, options=Ellipsize.options(Ellipsize.end)) assert truncated_text == 'a trunc...'
def test_text_truncated_at_middle(): truncated_text = truncated(TEXT, length=LENGTH, options=Ellipsize.options(Ellipsize.middle)) assert truncated_text == 'a tr...ext'
def test_text_truncated_at_start(): truncated_text = truncated(TEXT, length=LENGTH, options=Ellipsize.options(Ellipsize.start)) assert truncated_text == '...of text'