def horizontal_border(self, _, outer_widths): """Handle the GitHub heading border. E.g.: |:---|:---:|---:|----| :param _: Unused. :param iter outer_widths: List of widths (with padding) for each column. :return: Prepared border strings in a generator. :rtype: iter """ horizontal = str(self.CHAR_INNER_HORIZONTAL) left = self.CHAR_OUTER_LEFT_VERTICAL intersect = self.CHAR_INNER_VERTICAL right = self.CHAR_OUTER_RIGHT_VERTICAL columns = list() for i, width in enumerate(outer_widths): justify = self.justify_columns.get(i) width = max( 3, width ) # Width should be at least 3 so justification can be applied. if justify == 'left': columns.append(':' + horizontal * (width - 1)) elif justify == 'right': columns.append(horizontal * (width - 1) + ':') elif justify == 'center': columns.append(':' + horizontal * (width - 2) + ':') else: columns.append(horizontal * width) return combine(columns, left, intersect, right)
def test_no_items(generator): """Test with empty list. :param bool generator: Test with generator instead of list. """ actual = list(combine(iter([]) if generator else [], '>', '|', '<')) assert actual == ['>', '<']
def horizontal_border(self, _, outer_widths): """Handle the GitHub heading border. E.g.: |:---|:---:|---:|----| :param _: Unused. :param iter outer_widths: List of widths (with padding) for each column. :return: Prepared border strings in a generator. :rtype: iter """ horizontal = str(self.CHAR_INNER_HORIZONTAL) left = self.CHAR_OUTER_LEFT_VERTICAL intersect = self.CHAR_INNER_VERTICAL right = self.CHAR_OUTER_RIGHT_VERTICAL columns = list() for i, width in enumerate(outer_widths): justify = self.justify_columns.get(i) width = max(3, width) # Width should be at least 3 so justification can be applied. if justify == 'left': columns.append(':' + horizontal * (width - 1)) elif justify == 'right': columns.append(horizontal * (width - 1) + ':') elif justify == 'center': columns.append(':' + horizontal * (width - 2) + ':') else: columns.append(horizontal * width) return combine(columns, left, intersect, right)
def test_borders(generator): """Test with borders. :param bool generator: Test with generator instead of list. """ line = ['One', 'Two', 'Three'] actual = list(combine(iter(line) if generator else line, '>', '|', '<')) assert actual == ['>', 'One', '|', 'Two', '|', 'Three', '<']