Fix empty docstring (close #24)
diff --git a/nose_parameterized/parameterized.py b/nose_parameterized/parameterized.py
index 295e7c8..ef751ab 100644
--- a/nose_parameterized/parameterized.py
+++ b/nose_parameterized/parameterized.py
@@ -187,20 +187,18 @@
all_args_with_values = parameterized_argument_value_pairs(func, p)
# Assumes that the function passed is a bound method.
- descs = [u"{0}={1}".format(n, short_repr(v)) for n, v in all_args_with_values]
+ descs = ["%s=%s" %(n, short_repr(v)) for n, v in all_args_with_values]
# The documentation might be a multiline string, so split it
# and just work with the first string, ignoring the period
# at the end if there is one.
- split_doc = func.__doc__.split("\n")
- first = split_doc[0]
- append = u""
- if first[-1] == ".":
- append = u"."
+ first, nl, rest = func.__doc__.partition("\n")
+ suffix = ""
+ if first.endswith("."):
+ suffix = "."
first = first[:-1]
-
- first = first + u" [with {0}]".format(", ".join(descs)) + append
- return u"\n".join([first] + split_doc[1:])
+ args = "%s[with %s]" %(len(first) and " " or "", ", ".join(descs))
+ return "".join([first, args, suffix, nl, rest])
class parameterized(object):
""" Parameterize a test case::
diff --git a/nose_parameterized/test.py b/nose_parameterized/test.py
index fc7fb0a..d463e08 100644
--- a/nose_parameterized/test.py
+++ b/nose_parameterized/test.py
@@ -86,8 +86,13 @@
from the test method. """
stack = inspect.stack()
f_locals = stack[3][0].f_locals
- actual_docstring = f_locals["testMethod"].__doc__
- assert_equal(actual_docstring, expected_docstring)
+ test_method = (
+ f_locals.get("testMethod") or # Py27
+ f_locals.get("function") # Py33
+ )
+ if test_method is None:
+ raise AssertionError("uh oh, unittest changed a local variable name")
+ assert_equal(test_method.__doc__, expected_docstring)
@parameterized.expand([param("foo")],
testcase_func_doc=lambda f, n, p: "stuff")
@@ -101,6 +106,11 @@
self._assert_docstring("Documentation [with foo=%r]." %(foo, ))
@parameterized.expand([param("foo")])
+ def test_empty_docstring(self, foo):
+ ""
+ self._assert_docstring("[with foo=%r]" %(foo, ))
+
+ @parameterized.expand([param("foo")])
def test_multiline_documentation(self, foo):
"""Documentation.