From e0b318e83dfbd6f1773bca57f0d166b4b853b7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carles=20Barrob=C3=A9s?= Date: Tue, 14 Feb 2012 22:03:28 +0000 Subject: [PATCH] Added test of fed data, achieve 100% coverage --- test/test_functional.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/test/test_functional.py b/test/test_functional.py index 20033ce..240c72e 100644 --- a/test/test_functional.py +++ b/test/test_functional.py @@ -2,11 +2,13 @@ from ddt import ddt, data from nose.tools import assert_equal +@ddt class Dummy(object): """Dummy class to test decorators on""" + @data(1, 2, 3, 4) - def test_something(self): - pass + def test_something(self, value): + return value def test_data_decorator(): @@ -28,12 +30,24 @@ def test_data_decorator(): assert_equal(getattr(data_hello, extra_attr), (1, 2)) +is_test = lambda x: x.startswith('test_') + + def test_ddt(): """Test the ``ddt`` class decorator""" - is_test = lambda x: x.startswith('test_') tests = len(filter(is_test, Dummy.__dict__)) - assert_equal(tests, 1) - post_dummy = ddt(Dummy) - post_tests = len(filter(is_test, post_dummy.__dict__)) - assert_equal(post_tests, 4) + assert_equal(tests, 4) + + +def test_feed_data(): + """Test that data is fed to the decorated tests""" + + tests = filter(is_test, Dummy.__dict__) + values = [] + obj = Dummy() + for test in tests: + method = getattr(obj, test) + values.append(method()) + + assert_equal(set(values), set([1, 2, 3, 4]))