def test_unicode_output(self): elm = BarElement() elm.update = lambda: u'garçon' try: self.assertEqual(elm.next(), u'garçon'.encode('utf-8')) except UnicodeError: self.fail('error in unicode handling')
def test_update(self): def updatefunc(static=[0]): static[0] += 1 return "update("+str(static[0])+")" elm = BarElement() elm.update = Mock(wraps=updatefunc) self.assertEqual(elm.next(),"update(1)") self.assertEqual(elm.next(),"update(2)") self.assertEqual(elm.next(),"update(3)")
def test_graceful_fail(self): def wrongfunc(): raise StandardError elm = BarElement() elm.update = wrongfunc try: failed_update = elm.next() except StandardError: self.fail("uncaught error, no graceful fail") else: self.assertTrue("Error" in failed_update)
def test_iterable(self): elm = BarElement() def multi_iter(static=["1", "2", "3", None]): return static.pop(0) elm.update = multi_iter self.assertEqual(list(elm), ["1", "2", "3"])
def test_fixed_size(self): elm = BarElement(size=10) elm.update = Mock(return_value="testresult123456") self.assertEqual(elm.next(),"testresult")
def test_scrolling(self): elm = BarElement(size=3, scroll=1) elm.update = lambda: "1234" self.assertEqual(elm.next(), "123") self.assertEqual(elm.next(), "234")