From aa04b3fdddf1eb8f50c8ceae50fb24f2497e3606 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Fri, 2 May 2014 18:16:02 -0400 Subject: [PATCH 1/3] Add `cytoolz.utils.dev_skip_test` decorator to skip tests for dev versions. These tests depend on `toolz`, and it is annoying when `toolz` changes in the middle of a PR. Now, the things these tests check for only need to be updated before being uploaded to PyPI. --- cytoolz/tests/test_curried_toolzlike.py | 4 ++++ cytoolz/tests/test_docstrings.py | 3 ++- cytoolz/tests/test_embedded_sigs.py | 3 +++ cytoolz/utils.py | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cytoolz/tests/test_curried_toolzlike.py b/cytoolz/tests/test_curried_toolzlike.py index b45e3f7..3019bc2 100644 --- a/cytoolz/tests/test_curried_toolzlike.py +++ b/cytoolz/tests/test_curried_toolzlike.py @@ -3,16 +3,19 @@ import toolz import toolz.curried import types +from cytoolz.utils import dev_skip_test # Note that the tests in this file assume `toolz.curry` is a class, but we # may some day make `toolz.curry` a function and `toolz.Curry` a class. +@dev_skip_test def test_toolzcurry_is_class(): assert isinstance(toolz.curry, type) is True assert isinstance(toolz.curry, types.FunctionType) is False +@dev_skip_test def test_cytoolz_like_toolz(): for key, val in toolz.curried.__dict__.items(): if isinstance(val, toolz.curry): @@ -22,6 +25,7 @@ def test_cytoolz_like_toolz(): 'cytoolz.curried.%s should be curried' % key) +@dev_skip_test def test_toolz_like_cytoolz(): for key, val in cytoolz.curried.__dict__.items(): if isinstance(val, cytoolz.curry): diff --git a/cytoolz/tests/test_docstrings.py b/cytoolz/tests/test_docstrings.py index 18cdd93..11623c1 100644 --- a/cytoolz/tests/test_docstrings.py +++ b/cytoolz/tests/test_docstrings.py @@ -3,7 +3,7 @@ import toolz from cytoolz import curry, identity, keyfilter, valfilter, merge_with -from cytoolz.utils import raises +from cytoolz.utils import raises, dev_skip_test # `cytoolz` functions for which "# doctest: +SKIP" were added. @@ -30,6 +30,7 @@ def convertdoc(doc): return doc +@dev_skip_test def test_docstrings_uptodate(): differ = difflib.Differ() diff --git a/cytoolz/tests/test_embedded_sigs.py b/cytoolz/tests/test_embedded_sigs.py index 07fbb1b..a52e7e5 100644 --- a/cytoolz/tests/test_embedded_sigs.py +++ b/cytoolz/tests/test_embedded_sigs.py @@ -4,6 +4,7 @@ from types import BuiltinFunctionType from cytoolz import curry, identity, keyfilter, valfilter, merge_with +from cytoolz.utils import dev_skip_test @curry @@ -12,6 +13,7 @@ def isfrommod(modname, func): return modname in mod +@dev_skip_test def test_class_sigs(): """ Test that all ``cdef class`` extension types in ``cytoolz`` have correctly embedded the function signature as done in ``toolz``. @@ -54,6 +56,7 @@ def test_class_sigs(): aliases = {'comp': 'compose'} +@dev_skip_test def test_sig_at_beginning(): """ Test that the function signature is at the beginning of the docstring and is followed by exactly one blank line. diff --git a/cytoolz/utils.py b/cytoolz/utils.py index 2d1f6e7..1d04349 100644 --- a/cytoolz/utils.py +++ b/cytoolz/utils.py @@ -1,5 +1,6 @@ import doctest import inspect +import nose.tools import os.path import cytoolz @@ -104,3 +105,10 @@ def module_doctest(m, *args, **kwargs): """ fix_module_doctest(m) return doctest.testmod(m, *args, **kwargs).failed == 0 + + +# Decorator used to skip tests for developmental versions of CyToolz +if 'dev' in cytoolz.__version__: + dev_skip_test = nose.tools.nottest +else: + dev_skip_test = nose.tools.istest From 2022459b6530bbb7d0dd6aaa55349b0e3995a185 Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Sat, 3 May 2014 16:58:32 -0400 Subject: [PATCH 2/3] Move `dev_skip_test` into a module in "tests/" directory. It was in `cytoolz.utils`, which added `nose` as a dependency. --- Makefile | 2 +- cytoolz/tests/dev_skip_test.py | 8 ++++++++ cytoolz/tests/test_curried_toolzlike.py | 2 +- cytoolz/tests/test_docstrings.py | 3 ++- cytoolz/tests/test_embedded_sigs.py | 2 +- cytoolz/utils.py | 8 -------- 6 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 cytoolz/tests/dev_skip_test.py diff --git a/Makefile b/Makefile index 69a668e..413fc46 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PYTHON ?= python inplace: - $(PYTHON) setup.py build_ext --inplace + $(PYTHON) setup.py build_ext --inplace --cython test: inplace nosetests -s --with-doctest cytoolz/ diff --git a/cytoolz/tests/dev_skip_test.py b/cytoolz/tests/dev_skip_test.py new file mode 100644 index 0000000..da07cc3 --- /dev/null +++ b/cytoolz/tests/dev_skip_test.py @@ -0,0 +1,8 @@ +import nose.tools +import cytoolz + +# Decorator used to skip tests for developmental versions of CyToolz +if 'dev' in cytoolz.__version__: + dev_skip_test = nose.tools.nottest +else: + dev_skip_test = nose.tools.istest diff --git a/cytoolz/tests/test_curried_toolzlike.py b/cytoolz/tests/test_curried_toolzlike.py index 3019bc2..333e229 100644 --- a/cytoolz/tests/test_curried_toolzlike.py +++ b/cytoolz/tests/test_curried_toolzlike.py @@ -3,7 +3,7 @@ import toolz import toolz.curried import types -from cytoolz.utils import dev_skip_test +from dev_skip_test import dev_skip_test # Note that the tests in this file assume `toolz.curry` is a class, but we diff --git a/cytoolz/tests/test_docstrings.py b/cytoolz/tests/test_docstrings.py index 11623c1..4be663c 100644 --- a/cytoolz/tests/test_docstrings.py +++ b/cytoolz/tests/test_docstrings.py @@ -3,7 +3,8 @@ import toolz from cytoolz import curry, identity, keyfilter, valfilter, merge_with -from cytoolz.utils import raises, dev_skip_test +from cytoolz.utils import raises +from dev_skip_test import dev_skip_test # `cytoolz` functions for which "# doctest: +SKIP" were added. diff --git a/cytoolz/tests/test_embedded_sigs.py b/cytoolz/tests/test_embedded_sigs.py index a52e7e5..d2cd69f 100644 --- a/cytoolz/tests/test_embedded_sigs.py +++ b/cytoolz/tests/test_embedded_sigs.py @@ -4,7 +4,7 @@ from types import BuiltinFunctionType from cytoolz import curry, identity, keyfilter, valfilter, merge_with -from cytoolz.utils import dev_skip_test +from dev_skip_test import dev_skip_test @curry diff --git a/cytoolz/utils.py b/cytoolz/utils.py index 1d04349..2d1f6e7 100644 --- a/cytoolz/utils.py +++ b/cytoolz/utils.py @@ -1,6 +1,5 @@ import doctest import inspect -import nose.tools import os.path import cytoolz @@ -105,10 +104,3 @@ def module_doctest(m, *args, **kwargs): """ fix_module_doctest(m) return doctest.testmod(m, *args, **kwargs).failed == 0 - - -# Decorator used to skip tests for developmental versions of CyToolz -if 'dev' in cytoolz.__version__: - dev_skip_test = nose.tools.nottest -else: - dev_skip_test = nose.tools.istest From af3eaafe3ddcfd1065ceaa10faef8025b33a1cad Mon Sep 17 00:00:00 2001 From: Erik Welch Date: Mon, 5 May 2014 12:18:32 -0400 Subject: [PATCH 3/3] Add test for `dev_skip_test` --- cytoolz/tests/dev_skip_test.py | 6 +++--- cytoolz/tests/test_dev_skip_test.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 cytoolz/tests/test_dev_skip_test.py diff --git a/cytoolz/tests/dev_skip_test.py b/cytoolz/tests/dev_skip_test.py index da07cc3..3546f8a 100644 --- a/cytoolz/tests/dev_skip_test.py +++ b/cytoolz/tests/dev_skip_test.py @@ -1,8 +1,8 @@ -import nose.tools import cytoolz +from nose.tools import nottest, istest # Decorator used to skip tests for developmental versions of CyToolz if 'dev' in cytoolz.__version__: - dev_skip_test = nose.tools.nottest + dev_skip_test = nottest else: - dev_skip_test = nose.tools.istest + dev_skip_test = istest diff --git a/cytoolz/tests/test_dev_skip_test.py b/cytoolz/tests/test_dev_skip_test.py new file mode 100644 index 0000000..0c25271 --- /dev/null +++ b/cytoolz/tests/test_dev_skip_test.py @@ -0,0 +1,21 @@ +from dev_skip_test import istest, nottest, dev_skip_test + +d = {} + + +@istest +def test_passes(): + d['istest'] = True + assert True + + +@nottest +def test_fails(): + d['nottest'] = True + assert False + + +def test_dev_skip_test(): + assert dev_skip_test is istest or dev_skip_test is nottest + assert d.get('istest', False) is True + assert d.get('nottest', False) is False