def _trim_docstring(docstring):
lines = docstring.expandtabs().splitlines()
+
+ if len(lines) == 0:
+ return ''
+
indent = sys.maxsize
- for line in lines[1:]:
- stripped = line.lstrip()
+ if len(lines) > 1:
+ for line in lines[1:]:
+ stripped = line.lstrip()
- if stripped:
- indent = min(indent, len(line) - len(stripped))
+ if stripped:
+ indent = min(indent, len(line) - len(stripped))
trimmed = [lines[0].strip()]
- if indent < sys.maxsize:
+ if indent < sys.maxsize and len(lines) > 1:
for line in lines[1:]:
trimmed.append(line[indent:].rstrip())
self.assertEqual(MySink.description, 'The description.')
- def test_empty_description(self):
+ def test_empty_description_no_lines(self):
class MySink(bt2._UserSinkComponent):
+ # fmt: off
+ """"""
+ # fmt: on
+
+ def _user_consume(self):
+ pass
+
+ self.assertIsNone(MySink.description)
+
+ def test_empty_description_no_contents(self):
+ class MySink(bt2._UserSinkComponent):
+ # fmt: off
"""
"""
+ # fmt: on
def _user_consume(self):
pass
self.assertIsNone(MySink.description)
+ def test_empty_description_single_line(self):
+ class MySink(bt2._UserSinkComponent):
+ """my description"""
+
+ def _user_consume(self):
+ pass
+
+ self.assertEqual(MySink.description, "my description")
+
def test_help(self):
class MySink(bt2._UserSinkComponent):
"""