class CellRenderer(object): def __init__(self): self.renderer_left = DefaultCellRenderer("left") self.renderer_right = DefaultCellRenderer("right") def estimate_width(self, value): return self.renderer_left.estimate_width(value) def render(self, value, width): color = None renderer = self.renderer_left if value is None: value = u("NULL") color = partial(red, style="italic") renderer = self.renderer_right elif isinstance(value, integer_types + (float,)): color = green renderer = self.renderer_right for line in renderer.render(value, width): if color is not None: line = color(line) yield line
def test_render_empty_value(self): width = 5 expected = [" " * width] renderer = DefaultCellRenderer("left") lines = list(renderer.render("", width)) self.assertEqual(lines, expected)
def __init__(self): self.renderer_left = DefaultCellRenderer("left") self.renderer_right = DefaultCellRenderer("right")