Better docstring, and a more distinctive example

This commit is contained in:
Carles Barrobés
2013-02-25 23:36:22 +00:00
parent a5149f3b9c
commit 13a7e10588
3 changed files with 17 additions and 4 deletions

13
ddt.py
View File

@@ -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.

View File

@@ -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']

View File

@@ -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))