def update(self): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer, maxsteps=20) widget = StepWidget() widget.init(progressbar, writer.get_width()) for i in xrange(1, 21): progressbar.step += 1 result = widget.update(progressbar, writer.get_width()) Assert(len(result)) == widget.size_hint(progressbar) Assert(result) == '%i of 20' % i
def init(self): writer = TerminalWriter(StringIO()) progressbar = ProgressBar([], writer, maxsteps=20) widget = StepWidget() Assert(widget.init(progressbar, writer.get_width())) == '0 of 20' Assert(widget.size_hint(progressbar)) == 7 with Assert.raises(ValueError): StepWidget('foo') with Assert.not_raising(ValueError): StepWidget('bytes')