From 11823fea7bbc2c1f874ba5ed2984c0e635166ffd Mon Sep 17 00:00:00 2001 From: Charles Merriam Date: Wed, 28 Jan 2015 22:25:19 -0800 Subject: [PATCH] Add tests to cover utils.py at 100% --- kivy/tests/test_utils.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/kivy/tests/test_utils.py b/kivy/tests/test_utils.py index 112ff333c..cb6bd6b31 100644 --- a/kivy/tests/test_utils.py +++ b/kivy/tests/test_utils.py @@ -12,7 +12,7 @@ except: from kivy.utils import (boundary, escape_markup, format_bytes_to_human, is_color_transparent, SafeList, get_random_color, get_hex_from_color, get_color_from_hex, strtotuple, QueryDict, intersection, difference, - interpolate, Platform) + interpolate, Platform, deprecated, reify) class UtilsTest(unittest.TestCase): @@ -45,6 +45,15 @@ class UtilsTest(unittest.TestCase): c = [1,1,1,0] self.assertTrue(is_color_transparent(c)) + @deprecated + def a_deprecated_function(self): + """ This one has doc string. """ + pass + + def test_deprecated(self): + self.a_deprecated_function() + + def test_SafeList_iterate(self): # deprecated sl = SafeList(['1', 2, 3.]) self.assertTrue(isinstance(sl, list)) @@ -120,6 +129,8 @@ class UtilsTest(unittest.TestCase): # __getattr__ toto = qd.toto self.assertEqual(toto, 1) + with self.assertRaises(AttributeError): + foo = qd.not_an_attribute def test_intersection(self): abcd = ['a', 'b', 'c', 'd'] @@ -149,6 +160,24 @@ class UtilsTest(unittest.TestCase): for i in range (0, 3): p = interpolate(p, [100, -100]) self.assertEqual(p, [x[i], y[i]]) + + @reify + def fib_100(self): + """ return 100th Fibonacci number + This uses modern view of F sub 1 = 0, F sub 2 = 1. """ + # print "calculating..." + a, b = 0, 1 + for n in range(2, 101): + a, b = b, a+b + return b + + def test_reify(self): + first = self.fib_100 # slow. self.fib_100 is a reify object making + # the lazy call. + second = self.fib_100 # fast, self.fib_100 is a long. + assert first == second + + def test_Platform(self): # Those calls do not have specific intent, no assertions