def test_init_with_sentinel_kwargs(self): a = iter([1, 2, 3, 4]) sentinel = 4 def get_next(): return next(a) it = modify_iter(get_next, sentinel, modifier=str) expected = ['1', '2', '3'] self.assertEqual(expected, [i for i in it])
def __init__(self, docstring, config=None, app=None, what='', name='', obj=None, options=None): self._config = config self._app = app if not self._config: from sphinxcontrib.napoleon import Config self._config = self._app and self._app.config or Config() if not what: if inspect.isclass(obj): what = 'class' elif inspect.ismodule(obj): what = 'module' elif isinstance(obj, collections.Callable): what = 'function' else: what = 'object' self._what = what self._name = name self._obj = obj self._opt = options if isinstance(docstring, basestring): docstring = docstring.splitlines() self._lines = docstring self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip()) self._parsed_lines = [] self._is_in_section = False self._section_indent = 0 if not hasattr(self, '_directive_sections'): self._directive_sections = [] if not hasattr(self, '_sections'): self._sections = { 'args': self._parse_parameters_section, 'arguments': self._parse_parameters_section, 'attributes': self._parse_attributes_section, 'example': self._parse_examples_section, 'examples': self._parse_examples_section, 'keyword args': self._parse_keyword_arguments_section, 'keyword arguments': self._parse_keyword_arguments_section, 'methods': self._parse_methods_section, 'note': self._parse_note_section, 'notes': self._parse_notes_section, 'other parameters': self._parse_other_parameters_section, 'parameters': self._parse_parameters_section, 'return': self._parse_returns_section, 'returns': self._parse_returns_section, 'raises': self._parse_raises_section, 'references': self._parse_references_section, 'see also': self._parse_see_also_section, 'warning': self._parse_warning_section, 'warnings': self._parse_warning_section, 'warns': self._parse_warns_section, 'yields': self._parse_yields_section, } self._parse()
def test_init_with_sentinel_args(self): a = iter(['1', '2', '3', 'DONE']) sentinel = 'DONE' def get_next(): return next(a) it = modify_iter(get_next, sentinel, int) expected = [1, 2, 3] self.assertEqual(expected, [i for i in it])
def test_init_with_sentinel_kwargs(self): a = iter([1, 2, 3, 4]) sentinel = 4 def get_next(): return a.next() it = modify_iter(get_next, sentinel, modifier=str) expected = ['1', '2', '3'] self.assertEqual(expected, [i for i in it])
def test_init_with_sentinel_args(self): a = iter(['1', '2', '3', 'DONE']) sentinel = 'DONE' def get_next(): return a.next() it = modify_iter(get_next, sentinel, int) expected = [1, 2, 3] self.assertEqual(expected, [i for i in it])
def __init__(self, docstring, config=None, app=None, what='', name='', obj=None, options=None): self._config = config self._app = app if not self._config: from sphinxcontrib.napoleon import Config self._config = self._app and self._app.config or Config() self._what = what self._name = name self._obj = obj self._opt = options if isinstance(docstring, str): docstring = docstring.splitlines() self._lines = docstring self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip()) self._parsed_lines = [] self._is_in_section = False self._section_indent = 0 if not hasattr(self, '_directive_sections'): self._directive_sections = [] if not hasattr(self, '_sections'): self._sections = { 'args': self._parse_parameters_section, 'arguments': self._parse_parameters_section, 'attributes': self._parse_attributes_section, 'example': self._parse_examples_section, 'examples': self._parse_examples_section, 'keyword args': self._parse_keyword_arguments_section, 'keyword arguments': self._parse_keyword_arguments_section, 'methods': self._parse_methods_section, 'note': self._parse_note_section, 'notes': self._parse_notes_section, 'other parameters': self._parse_other_parameters_section, 'parameters': self._parse_parameters_section, 'return': self._parse_returns_section, 'returns': self._parse_returns_section, 'raises': self._parse_raises_section, 'references': self._parse_references_section, 'see also': self._parse_see_also_section, 'warning': self._parse_warning_section, 'warnings': self._parse_warning_section, 'warns': self._parse_warns_section, 'yields': self._parse_yields_section, } self._parse()
def test_modifier_rstrip_unicode(self): a = [u(''), u(' '), u(' a '), u('b '), u(' c'), u(' '), u('')] it = modify_iter(a, modifier=lambda s: s.rstrip()) expected = [u(''), u(''), u(' a'), u('b'), u(' c'), u(''), u('')] self.assertEqual(expected, [i for i in it])
def test_modifier_rstrip(self): a = ['', ' ', ' a ', 'b ', ' c', ' ', ''] it = modify_iter(a, modifier=lambda s: s.rstrip()) expected = ['', '', ' a', 'b', ' c', '', ''] self.assertEqual(expected, [i for i in it])
def test_modifier_default(self): a = ['', ' ', ' a ', 'b ', ' c', ' ', ''] it = modify_iter(a) expected = ['', ' ', ' a ', 'b ', ' c', ' ', ''] self.assertEqual(expected, [i for i in it])
def test_modifier_rstrip_unicode(self): a = [u'', u' ', u' a ', u'b ', u' c', u' ', u''] it = modify_iter(a, modifier=lambda s: s.rstrip()) expected = [u'', u'', u' a', u'b', u' c', u'', u''] self.assertEqual(expected, [i for i in it])