From 13a7e10588d6174e08336c6e09197490b34df4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carles=20Barrob=C3=A9s?= Date: Mon, 25 Feb 2013 23:36:22 +0000 Subject: [PATCH] Better docstring, and a more distinctive example --- ddt.py | 13 +++++++++++-- test/mycode.py | 4 ++++ test/test_example.py | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ddt.py b/ddt.py index 1ee2894..025bf9e 100644 --- a/ddt.py +++ b/ddt.py @@ -30,9 +30,18 @@ def file_data(value): Should be added to methods of instances of ``unittest.TestCase``. - ``value`` should be a path relative to the directory that the file + ``value`` should be a path relative to the directory of the file containing the decorated ``unittest.TestCase``. The file - should contain a JSON encoded list of dicts with each dict containing a + should contain JSON encoded data, that can either be a list or a + dict. + + In case of a list, each value in the list will correspond to one + test case, and the value will be concatenated to the test method + name. + + In case of a dict, keys will be used as suffixes to the name of the + test case, and values will be fed as test data. + ``test_name`` and a ``data`` key. The ``test_name`` value should be the name of the test and the value for the ``data`` key should be a list of data values. diff --git a/test/mycode.py b/test/mycode.py index eb101b4..bd562c8 100644 --- a/test/mycode.py +++ b/test/mycode.py @@ -9,3 +9,7 @@ def larger_than_two(value): def has_three_elements(value): return len(value) == 3 + + +def is_a_greeting(value): + return value in ['Hello', 'Goodbye'] diff --git a/test/test_example.py b/test/test_example.py index a9841b7..1ea09bf 100644 --- a/test/test_example.py +++ b/test/test_example.py @@ -1,6 +1,6 @@ import unittest from ddt import ddt, data, file_data -from .mycode import larger_than_two, has_three_elements +from .mycode import larger_than_two, has_three_elements, is_a_greeting class mylist(list): @@ -38,4 +38,4 @@ class FooTestCase(unittest.TestCase): @file_data('test_data_list.json') def test_file_data_list(self, value): - self.assertTrue(has_three_elements(value)) + self.assertTrue(is_a_greeting(value))