[Python-modules-commits] [python-parameterized] 01/03: New upstream version 0.6.1

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sat Jul 29 12:38:18 UTC 2017


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository python-parameterized.

commit e7baf456d2ddc060693d3146b7223cd639efeef8
Author: Ghislain Antony Vaillant <ghisvail at gmail.com>
Date:   Thu Jul 27 21:14:09 2017 +0100

    New upstream version 0.6.1
---
 .gitignore                                    |  21 ++
 .hgignore                                     |  19 ++
 .travis.yml                                   |  25 ++
 CHANGELOG.txt                                 |  63 ++++
 LICENSE.txt                                   |  29 ++
 PKG-INFO                                      | 403 +++++++++++++++++++++++++
 README.rst                                    | 390 ++++++++++++++++++++++++
 misspelling-helper/nose-parametrized/MANIFEST |   2 +
 misspelling-helper/nose-parametrized/setup.py |  11 +
 parameterized.egg-info/PKG-INFO               | 403 +++++++++++++++++++++++++
 parameterized.egg-info/SOURCES.txt            |  18 ++
 parameterized.egg-info/dependency_links.txt   |   1 +
 parameterized.egg-info/top_level.txt          |   1 +
 parameterized/__init__.py                     |   1 +
 parameterized/parameterized.py                | 410 ++++++++++++++++++++++++++
 parameterized/test.py                         | 281 ++++++++++++++++++
 setup.cfg                                     |   7 +
 setup.py                                      |  30 ++
 tox.ini                                       |  15 +
 19 files changed, 2130 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b16f7cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+*.class
+*.o
+*.pyc
+*.sqlite3
+*.sw[op]
+*~
+.DS_Store
+bin-debug/*
+bin-release/*
+bin/*
+tags
+*.beam
+*.dump
+env/
+.env/
+*egg-info*
+misc/
+dist/
+Icon?
+.tox
+build/
diff --git a/.hgignore b/.hgignore
new file mode 100644
index 0000000..2162790
--- /dev/null
+++ b/.hgignore
@@ -0,0 +1,19 @@
+syntax: glob
+*.class
+*.o
+*.pyc
+*.sqlite3
+*.sw[op]
+*~
+.DS_Store
+bin-debug/*
+bin-release/*
+bin/*
+tags
+*.beam
+*.dump
+env/
+*egg-info*
+dist/
+.tox
+.env32
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f872f70
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,25 @@
+language: python
+sudo: false
+env:
+  - TOXENV=py26-nose
+  - TOXENV=py26-nose2
+  - TOXENV=py26-pytest
+  - TOXENV=py26-unit
+  - TOXENV=py26-unit2
+  - TOXENV=py27-nose
+  - TOXENV=py27-nose2
+  - TOXENV=py27-pytest
+  - TOXENV=py27-unit
+  - TOXENV=py27-unit2
+  - TOXENV=py33-nose
+  - TOXENV=py33-nose2
+  - TOXENV=py33-pytest
+  - TOXENV=py33-unit
+  - TOXENV=py33-unit2
+  - TOXENV=pypy-nose
+  - TOXENV=pypy-nose2
+  - TOXENV=pypy-pytest
+  - TOXENV=pypy-unit
+  - TOXENV=pypy-unit2
+install: pip install tox
+script: tox
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
new file mode 100644
index 0000000..3fcfd79
--- /dev/null
+++ b/CHANGELOG.txt
@@ -0,0 +1,63 @@
+0.6.1 (2017-03-21)
+    * Rename package from nose-parameterized to parameterized. A
+      nose-parameterized package will be released with a deprecation warning.
+    * Rename testcase_func_doc and testcase_func_name methods to doc_func and
+      name_func (a DeprecationWarning will be issued, to be removed in 1.0).
+    * Include parameters in all docstrings, not just `parameterized.expand`
+      docstrings.
+    * Explicitly unwrap iterators and generators before the test run (thanks
+      @chornsby; https://github.com/wolever/nose-parameterized/pull/31)
+    * 0.6.1 instead of 0.6.0 because I'm a dumb and accidentally uploaded
+      the wrong thing to PyPI under version 0.6.0.
+
+0.5.0 (2015-06-09)
+    * Support for nose2, py.test, unittest, and unittest2
+      (nose2 support thanks to @marek-mazur;
+      https://github.com/wolever/nose-parameterized/pull/26)
+
+0.4.2 (2015-05-18)
+    * Fix bug with expand + empty arguments (thanks @jikamens;
+      https://github.com/wolever/nose-parameterized/pull/25)
+
+0.4.1 (2015-05-17)
+    * Fix bug with expand + empty docstring (thanks @jikamens;
+      https://github.com/wolever/nose-parameterized/pull/24)
+
+0.4.0 (2015-05-11)
+    * Include parameters in ``parameterized.expand`` function docstrings
+      (https://github.com/wolever/nose-parameterized/pull/22; thanks
+      @smspillaz)
+    * Drop Python 3.2 support
+
+0.3.5 (2014-11-05)
+    * Allow the names of test cases generated by ``parameterized.expand`` to
+      be customized.
+      (https://github.com/wolever/nose-parameterized/pull/19;
+      thanks @curtissiemens) 
+
+0.3.4 (2014-10-03)
+    * Use ``functools.wraps`` to wrap expanded functions
+      (https://github.com/wolever/nose-parameterized/pull/17;
+      thanks @toumorokoshi) 
+
+0.3.3 (2014-01-03)
+    * Replace unsafe characters with "_" in names generated by
+      ``@parameterized.expand``.
+
+0.3.2 (2014-01-02)
+    * Add helpful error message when used with old-style classes.
+
+0.3.1 (2013-08-01)
+    * Fix bug: `nose_parameterized.param` wasn't being imported.
+
+0.3 (2013-05-18)
+    * Add `param` class.
+    * Add explicit support for callable inputs.
+    * Update readme to more throughly describe useage.
+    * Remove un-used test helpers (`setup_logging`, `teardown_logging`,
+     `logged_messages`, `assert_logged`, `assert_no_errors_logged`,
+     `assert_contains`, `assert_not_contains`, `assert_raises`,
+     `imported_from_test`).
+
+0.2 (2013-01-15)
+    * Add Python 3 support
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..f3eb683
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,29 @@
+tl;dr: all code code is licensed under simplified BSD, unless stated otherwise.
+
+Unless stated otherwise in the source files, all code is copyright 2010 David
+Wolever <david at wolever.net>. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+   2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of David Wolever.
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..f067cf1
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,403 @@
+Metadata-Version: 1.1
+Name: parameterized
+Version: 0.6.1
+Summary: Parameterized testing with any Python test framework
+Home-page: https://github.com/wolever/parameterized
+Author: David Wolever
+Author-email: david at wolever.net
+License: FreeBSD
+Description: Parameterized testing with any Python test framework
+        ====================================================
+        
+        .. image:: https://travis-ci.org/wolever/parameterized.svg?branch=master
+            :target: https://travis-ci.org/wolever/parameterized
+        
+        Parameterized testing in Python sucks.
+        
+        ``parameterized`` fixes that. For everything. Parameterized testing for nose,
+        parameterized testing for py.test, parameterized testing for unittest.
+        
+        .. code:: python
+        
+            # test_math.py
+            from nose.tools import assert_equal
+            from parameterized import parameterized
+        
+            import unittest
+            import math
+        
+            @parameterized([
+                (2, 2, 4),
+                (2, 3, 8),
+                (1, 9, 1),
+                (0, 9, 0),
+            ])
+            def test_pow(base, exponent, expected):
+                assert_equal(math.pow(base, exponent), expected)
+        
+            class TestMathUnitTest(unittest.TestCase):
+                @parameterized.expand([
+                    ("negative", -1.5, -2.0),
+                    ("integer", 1, 1.0),
+                    ("large fraction", 1.6, 1),
+                ])
+                def test_floor(self, name, input, expected):
+                    assert_equal(math.floor(input), expected)
+        
+        With nose (and nose2)::
+        
+            $ nosetests -v test_math.py
+            test_math.test_pow(2, 2, 4) ... ok
+            test_math.test_pow(2, 3, 8) ... ok
+            test_math.test_pow(1, 9, 1) ... ok
+            test_math.test_pow(0, 9, 0) ... ok
+            test_floor_0_negative (test_math.TestMathUnitTest) ... ok
+            test_floor_1_integer (test_math.TestMathUnitTest) ... ok
+            test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
+        
+            ----------------------------------------------------------------------
+            Ran 7 tests in 0.002s
+        
+            OK
+        
+        As the package name suggests, nose is best supported and will be used for all
+        further examples.
+        
+        With py.test (version 2.0 and above)::
+        
+            $ py.test -v test_math.py
+            ============================== test session starts ==============================
+            platform darwin -- Python 2.7.2 -- py-1.4.30 -- pytest-2.7.1
+            collected 7 items
+        
+            test_math.py::test_pow::[0] PASSED
+            test_math.py::test_pow::[1] PASSED
+            test_math.py::test_pow::[2] PASSED
+            test_math.py::test_pow::[3] PASSED
+            test_math.py::TestMathUnitTest::test_floor_0_negative
+            test_math.py::TestMathUnitTest::test_floor_1_integer
+            test_math.py::TestMathUnitTest::test_floor_2_large_fraction
+        
+            =========================== 7 passed in 0.10 seconds ============================
+        
+        With unittest (and unittest2)::
+        
+            $ python -m unittest -v test_math
+            test_floor_0_negative (test_math.TestMathUnitTest) ... ok
+            test_floor_1_integer (test_math.TestMathUnitTest) ... ok
+            test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
+        
+            ----------------------------------------------------------------------
+            Ran 3 tests in 0.000s
+        
+            OK
+        
+        (note: because unittest does not support test decorators, only tests created
+        with ``@parameterized.expand`` will be executed)
+        
+        Installation
+        ------------
+        
+        ::
+        
+            $ pip install parameterized
+        
+        
+        Compatibility
+        -------------
+        
+        `Yes`__.
+        
+        __ https://travis-ci.org/wolever/parameterized
+        
+        .. list-table::
+           :header-rows: 1
+           :stub-columns: 1
+        
+           * -
+             - Py2.6
+             - Py2.7
+             - Py3.3
+             - Py3.4
+             - PyPy
+           * - nose
+             - yes
+             - yes
+             - yes
+             - yes
+             - yes
+           * - nose2
+             - yes
+             - yes
+             - yes
+             - yes
+             - yes
+           * - py.test
+             - yes
+             - yes
+             - yes
+             - yes
+             - yes
+           * - | unittest
+               | (``@parameterized.expand``)
+             - yes
+             - yes
+             - yes
+             - yes
+             - yes
+           * - | unittest2
+               | (``@parameterized.expand``)
+             - yes
+             - yes
+             - yes
+             - yes
+             - yes
+        
+        Dependencies
+        ------------
+        
+        (this section left intentionally blank)
+        
+        
+        Exhaustive Usage Examples
+        --------------------------
+        
+        The ``@parameterized`` and ``@parameterized.expand`` decorators accept a list
+        or iterable of tuples or ``param(...)``, or a callable which returns a list or
+        iterable:
+        
+        .. code:: python
+        
+            from parameterized import parameterized, param
+        
+            # A list of tuples
+            @parameterized([
+                (2, 3, 5),
+                (3, 5, 8),
+            ])
+            def test_add(a, b, expected):
+                assert_equal(a + b, expected)
+        
+            # A list of params
+            @parameterized([
+                param("10", 10),
+                param("10", 16, base=16),
+            ])
+            def test_int(str_val, expected, base=10):
+                assert_equal(int(str_val, base=base), expected)
+        
+            # An iterable of params
+            @parameterized(
+                param.explicit(*json.loads(line))
+                for line in open("testcases.jsons")
+            )
+            def test_from_json_file(...):
+                ...
+        
+            # A callable which returns a list of tuples
+            def load_test_cases():
+                return [
+                    ("test1", ),
+                    ("test2", ),
+                ]
+            @parameterized(load_test_cases)
+            def test_from_function(name):
+                ...
+        
+        .. **
+        
+        Note that, when using an iterator or a generator, all the items will be loaded
+        into memory before the start of the test run (we do this explicitly to ensure
+        that generators are exhausted exactly once in multi-process or multi-threaded
+        testing environments).
+        
+        The ``@parameterized`` decorator can be used test class methods, and standalone
+        functions:
+        
+        .. code:: python
+        
+            from parameterized import parameterized
+        
+            class AddTest(object):
+                @parameterized([
+                    (2, 3, 5),
+                ])
+                def test_add(self, a, b, expected):
+                    assert_equal(a + b, expected)
+        
+            @parameterized([
+                (2, 3, 5),
+            ])
+            def test_add(a, b, expected):
+                assert_equal(a + b, expected)
+        
+        
+        And ``@parameterized.expand`` can be used to generate test methods in
+        situations where test generators cannot be used (for example, when the test
+        class is a subclass of ``unittest.TestCase``):
+        
+        .. code:: python
+        
+            import unittest
+            from parameterized import parameterized
+        
+            class AddTestCase(unittest.TestCase):
+                @parameterized.expand([
+                    ("2 and 3", 2, 3, 5),
+                    ("3 and 5", 2, 3, 5),
+                ])
+                def test_add(self, _, a, b, expected):
+                    assert_equal(a + b, expected)
+        
+        Will create the test cases::
+        
+            $ nosetests example.py
+            test_add_0_2_and_3 (example.AddTestCase) ... ok
+            test_add_1_3_and_5 (example.AddTestCase) ... ok
+        
+            ----------------------------------------------------------------------
+            Ran 2 tests in 0.001s
+        
+            OK
+        
+        Note that ``@parameterized.expand`` works by creating new methods on the test
+        class. If the first parameter is a string, that string will be added to the end
+        of the method name. For example, the test case above will generate the methods
+        ``test_add_0_2_and_3`` and ``test_add_1_3_and_5``.
+        
+        The names of the test cases generated by ``@parameterized.expand`` can be
+        customized using the ``testcase_func_name`` keyword argument. The value should
+        be a function which accepts three arguments: ``testcase_func``, ``param_num``,
+        and ``params``, and it should return the name of the test case.
+        ``testcase_func`` will be the function to be tested, ``param_num`` will be the
+        index of the test case parameters in the list of parameters, and ``param``
+        (an instance of ``param``) will be the parameters which will be used.
+        
+        .. code:: python
+        
+            import unittest
+            from parameterized import parameterized
+        
+            def custom_name_func(testcase_func, param_num, param):
+                return "%s_%s" %(
+                    testcase_func.__name__,
+                    parameterized.to_safe_name("_".join(str(x) for x in param.args)),
+                )
+        
+            class AddTestCase(unittest.TestCase):
+                @parameterized.expand([
+                    (2, 3, 5),
+                    (2, 3, 5),
+                ], testcase_func_name=custom_name_func)
+                def test_add(self, a, b, expected):
+                    assert_equal(a + b, expected)
+        
+        Will create the test cases::
+        
+            $ nosetests example.py
+            test_add_1_2_3 (example.AddTestCase) ... ok
+            test_add_2_3_5 (example.AddTestCase) ... ok
+        
+            ----------------------------------------------------------------------
+            Ran 2 tests in 0.001s
+        
+            OK
+        
+        
+        The ``param(...)`` helper class stores the parameters for one specific test
+        case.  It can be used to pass keyword arguments to test cases:
+        
+        .. code:: python
+        
+            from parameterized import parameterized, param
+        
+            @parameterized([
+                param("10", 10),
+                param("10", 16, base=16),
+            ])
+            def test_int(str_val, expected, base=10):
+                assert_equal(int(str_val, base=base), expected)
+        
+        
+        If test cases have a docstring, the parameters for that test case will be
+        appended to the first line of the docstring. This behavior can be controlled
+        with the ``doc_func`` argument:
+        
+        .. code:: python
+        
+            from parameterized import parameterized
+        
+            @parameterized([
+                (1, 2, 3),
+                (4, 5, 9),
+            ])
+            def test_add(a, b, expected):
+                """ Test addition. """
+                assert_equal(a + b, expected)
+        
+            def my_doc_func(func, num, param):
+                return "%s: %s with %s" %(num, func.__name__, param)
+        
+            @parameterized([
+                (5, 4, 1),
+                (9, 6, 3),
+            ], doc_func=my_doc_func)
+            def test_subtraction(a, b, expected):
+                assert_equal(a - b, expected)
+        
+        ::
+        
+            $ nosetests example.py
+            Test addition. [with a=1, b=2, expected=3] ... ok
+            Test addition. [with a=4, b=5, expected=9] ... ok
+            0: test_subtraction with param(*(5, 4, 1)) ... ok
+            1: test_subtraction with param(*(9, 6, 3)) ... ok
+        
+            ----------------------------------------------------------------------
+            Ran 4 tests in 0.001s
+        
+            OK
+        
+        
+        Migrating from ``nose-parameterized`` to ``parameterized``
+        ----------------------------------------------------------
+        
+        To migrate a codebase from ``nose-parameterized`` to ``parameterized``:
+        
+        1. Update your requirements file, replacing ``nose-parameterized`` with
+           ``parameterized``.
+        
+        2. Replace all references to ``nose_parameterized`` with ``parameterized``::
+        
+            $ perl -pi -e 's/nose_parameterized/parameterized/g' your-codebase/
+        
+        3. You're done!
+        
+        
+        FAQ
+        ---
+        
+        What happened to ``nose-parameterized``?
+            Originally only nose was supported. But now everything is supported, and it
+            only made sense to change the name!
+        
+        What do you mean when you say "nose is best supported"?
+            There are small caveates with ``py.test`` and ``unittest``: ``py.test``
+            does not show the parameter values (ex, it will show ``test_add[0]``
+            instead of ``test_add[1, 2, 3]``), and ``unittest``/``unittest2`` do not
+            support test generators so ``@parameterized.expand`` must be used.
+        
+        Why not use ``@pytest.mark.parametrize``?
+            Because spelling is difficult. Also, ``parameterized`` doesn't require you
+            to repeat argument names, and (using ``param``) it supports optional
+            keyword arguments.
+        
+        Why do I get an ``AttributeError: 'function' object has no attribute 'expand'`` with ``@parameterized.expand``?
+            You've likely installed the ``parametrized`` (note the missing *e*)
+            package. Use ``parameterized`` (with the *e*) instead and you'll be all
+            set.
+        
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3
+Classifier: License :: OSI Approved :: BSD License
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..42f295e
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,390 @@
+Parameterized testing with any Python test framework
+====================================================
+
+.. image:: https://travis-ci.org/wolever/parameterized.svg?branch=master
+    :target: https://travis-ci.org/wolever/parameterized
+
+Parameterized testing in Python sucks.
+
+``parameterized`` fixes that. For everything. Parameterized testing for nose,
+parameterized testing for py.test, parameterized testing for unittest.
+
+.. code:: python
+
+    # test_math.py
+    from nose.tools import assert_equal
+    from parameterized import parameterized
+
+    import unittest
+    import math
+
+    @parameterized([
+        (2, 2, 4),
+        (2, 3, 8),
+        (1, 9, 1),
+        (0, 9, 0),
+    ])
+    def test_pow(base, exponent, expected):
+        assert_equal(math.pow(base, exponent), expected)
+
+    class TestMathUnitTest(unittest.TestCase):
+        @parameterized.expand([
+            ("negative", -1.5, -2.0),
+            ("integer", 1, 1.0),
+            ("large fraction", 1.6, 1),
+        ])
+        def test_floor(self, name, input, expected):
+            assert_equal(math.floor(input), expected)
+
+With nose (and nose2)::
+
+    $ nosetests -v test_math.py
+    test_math.test_pow(2, 2, 4) ... ok
+    test_math.test_pow(2, 3, 8) ... ok
+    test_math.test_pow(1, 9, 1) ... ok
+    test_math.test_pow(0, 9, 0) ... ok
+    test_floor_0_negative (test_math.TestMathUnitTest) ... ok
+    test_floor_1_integer (test_math.TestMathUnitTest) ... ok
+    test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
+
+    ----------------------------------------------------------------------
+    Ran 7 tests in 0.002s
+
+    OK
+
+As the package name suggests, nose is best supported and will be used for all
+further examples.
+
+With py.test (version 2.0 and above)::
+
+    $ py.test -v test_math.py
+    ============================== test session starts ==============================
+    platform darwin -- Python 2.7.2 -- py-1.4.30 -- pytest-2.7.1
+    collected 7 items
+
+    test_math.py::test_pow::[0] PASSED
+    test_math.py::test_pow::[1] PASSED
+    test_math.py::test_pow::[2] PASSED
+    test_math.py::test_pow::[3] PASSED
+    test_math.py::TestMathUnitTest::test_floor_0_negative
+    test_math.py::TestMathUnitTest::test_floor_1_integer
+    test_math.py::TestMathUnitTest::test_floor_2_large_fraction
+
+    =========================== 7 passed in 0.10 seconds ============================
+
+With unittest (and unittest2)::
+
+    $ python -m unittest -v test_math
+    test_floor_0_negative (test_math.TestMathUnitTest) ... ok
+    test_floor_1_integer (test_math.TestMathUnitTest) ... ok
+    test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
+
+    ----------------------------------------------------------------------
+    Ran 3 tests in 0.000s
+
+    OK
+
+(note: because unittest does not support test decorators, only tests created
+with ``@parameterized.expand`` will be executed)
+
+Installation
+------------
+
+::
+
+    $ pip install parameterized
+
+
+Compatibility
+-------------
+
+`Yes`__.
+
+__ https://travis-ci.org/wolever/parameterized
+
+.. list-table::
+   :header-rows: 1
+   :stub-columns: 1
+
+   * -
+     - Py2.6
+     - Py2.7
+     - Py3.3
+     - Py3.4
+     - PyPy
+   * - nose
+     - yes
+     - yes
+     - yes
+     - yes
+     - yes
+   * - nose2
+     - yes
+     - yes
+     - yes
+     - yes
+     - yes
+   * - py.test
+     - yes
+     - yes
+     - yes
+     - yes
+     - yes
+   * - | unittest
+       | (``@parameterized.expand``)
+     - yes
+     - yes
+     - yes
+     - yes
+     - yes
+   * - | unittest2
+       | (``@parameterized.expand``)
+     - yes
+     - yes
+     - yes
+     - yes
+     - yes
+
+Dependencies
+------------
+
+(this section left intentionally blank)
+
+
+Exhaustive Usage Examples
+--------------------------
+
+The ``@parameterized`` and ``@parameterized.expand`` decorators accept a list
+or iterable of tuples or ``param(...)``, or a callable which returns a list or
+iterable:
+
+.. code:: python
+
+    from parameterized import parameterized, param
+
+    # A list of tuples
+    @parameterized([
+        (2, 3, 5),
+        (3, 5, 8),
+    ])
+    def test_add(a, b, expected):
+        assert_equal(a + b, expected)
+
+    # A list of params
+    @parameterized([
+        param("10", 10),
+        param("10", 16, base=16),
+    ])
+    def test_int(str_val, expected, base=10):
+        assert_equal(int(str_val, base=base), expected)
+
+    # An iterable of params
+    @parameterized(
+        param.explicit(*json.loads(line))
+        for line in open("testcases.jsons")
+    )
+    def test_from_json_file(...):
+        ...
+
+    # A callable which returns a list of tuples
+    def load_test_cases():
+        return [
+            ("test1", ),
+            ("test2", ),
+        ]
+    @parameterized(load_test_cases)
+    def test_from_function(name):
+        ...
+
+.. **
+
+Note that, when using an iterator or a generator, all the items will be loaded
+into memory before the start of the test run (we do this explicitly to ensure
+that generators are exhausted exactly once in multi-process or multi-threaded
+testing environments).
+
+The ``@parameterized`` decorator can be used test class methods, and standalone
+functions:
+
+.. code:: python
+
+    from parameterized import parameterized
+
+    class AddTest(object):
+        @parameterized([
+            (2, 3, 5),
+        ])
+        def test_add(self, a, b, expected):
+            assert_equal(a + b, expected)
+
+    @parameterized([
+        (2, 3, 5),
+    ])
+    def test_add(a, b, expected):
+        assert_equal(a + b, expected)
+
+
+And ``@parameterized.expand`` can be used to generate test methods in
+situations where test generators cannot be used (for example, when the test
+class is a subclass of ``unittest.TestCase``):
+
+.. code:: python
+
+    import unittest
+    from parameterized import parameterized
+
+    class AddTestCase(unittest.TestCase):
+        @parameterized.expand([
+            ("2 and 3", 2, 3, 5),
+            ("3 and 5", 2, 3, 5),
+        ])
+        def test_add(self, _, a, b, expected):
+            assert_equal(a + b, expected)
+
+Will create the test cases::
+
+    $ nosetests example.py
+    test_add_0_2_and_3 (example.AddTestCase) ... ok
+    test_add_1_3_and_5 (example.AddTestCase) ... ok
+
+    ----------------------------------------------------------------------
+    Ran 2 tests in 0.001s
+
+    OK
+
+Note that ``@parameterized.expand`` works by creating new methods on the test
+class. If the first parameter is a string, that string will be added to the end
+of the method name. For example, the test case above will generate the methods
+``test_add_0_2_and_3`` and ``test_add_1_3_and_5``.
+
+The names of the test cases generated by ``@parameterized.expand`` can be
+customized using the ``testcase_func_name`` keyword argument. The value should
+be a function which accepts three arguments: ``testcase_func``, ``param_num``,
+and ``params``, and it should return the name of the test case.
+``testcase_func`` will be the function to be tested, ``param_num`` will be the
+index of the test case parameters in the list of parameters, and ``param``
+(an instance of ``param``) will be the parameters which will be used.
+
+.. code:: python
+
+    import unittest
+    from parameterized import parameterized
+
+    def custom_name_func(testcase_func, param_num, param):
+        return "%s_%s" %(
+            testcase_func.__name__,
+            parameterized.to_safe_name("_".join(str(x) for x in param.args)),
+        )
+
+    class AddTestCase(unittest.TestCase):
+        @parameterized.expand([
+            (2, 3, 5),
+            (2, 3, 5),
+        ], testcase_func_name=custom_name_func)
+        def test_add(self, a, b, expected):
+            assert_equal(a + b, expected)
+
+Will create the test cases::
+
+    $ nosetests example.py
+    test_add_1_2_3 (example.AddTestCase) ... ok
+    test_add_2_3_5 (example.AddTestCase) ... ok
+
+    ----------------------------------------------------------------------
+    Ran 2 tests in 0.001s
+
+    OK
+
+
+The ``param(...)`` helper class stores the parameters for one specific test
+case.  It can be used to pass keyword arguments to test cases:
+
+.. code:: python
+
+    from parameterized import parameterized, param
+
+    @parameterized([
+        param("10", 10),
+        param("10", 16, base=16),
+    ])
+    def test_int(str_val, expected, base=10):
+        assert_equal(int(str_val, base=base), expected)
+
+
+If test cases have a docstring, the parameters for that test case will be
+appended to the first line of the docstring. This behavior can be controlled
+with the ``doc_func`` argument:
+
+.. code:: python
+
+    from parameterized import parameterized
+
+    @parameterized([
+        (1, 2, 3),
+        (4, 5, 9),
+    ])
+    def test_add(a, b, expected):
+        """ Test addition. """
+        assert_equal(a + b, expected)
+
+    def my_doc_func(func, num, param):
+        return "%s: %s with %s" %(num, func.__name__, param)
+
+    @parameterized([
+        (5, 4, 1),
+        (9, 6, 3),
+    ], doc_func=my_doc_func)
+    def test_subtraction(a, b, expected):
+        assert_equal(a - b, expected)
+
+::
+
+    $ nosetests example.py
+    Test addition. [with a=1, b=2, expected=3] ... ok
+    Test addition. [with a=4, b=5, expected=9] ... ok
+    0: test_subtraction with param(*(5, 4, 1)) ... ok
+    1: test_subtraction with param(*(9, 6, 3)) ... ok
+
+    ----------------------------------------------------------------------
+    Ran 4 tests in 0.001s
+
+    OK
+
+
+Migrating from ``nose-parameterized`` to ``parameterized``
+----------------------------------------------------------
+
+To migrate a codebase from ``nose-parameterized`` to ``parameterized``:
+
+1. Update your requirements file, replacing ``nose-parameterized`` with
+   ``parameterized``.
+
+2. Replace all references to ``nose_parameterized`` with ``parameterized``::
+
+    $ perl -pi -e 's/nose_parameterized/parameterized/g' your-codebase/
+
+3. You're done!
+
+
+FAQ
+---
+
... 1272 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-parameterized.git



More information about the Python-modules-commits mailing list