예제 #1
0
 def _test_find_args(self, docstring, expected_args, is_keyword = False):
     parser = DocstringParser(docstring)
     expected = {}
     for arg in expected_args:
         expected[arg.argname] = arg
     for arg in parser.find_args('keyword' if is_keyword else 'param'):
         assert arg.argname in expected and arg.argtype == expected[arg.argname].argtype
 def test_defaults(self):
     parser = DocstringParser(docstring_multi_complex_type)
     # the docstring parser adds "..." for keyword-arguments
     # to signify they are optional
     assert parser.default_for("country_hint") == "..."
     # for "everything else" we don't set a default from the docstring
     # instead we will seek the default from the signature inspection
     assert parser.default_for("documents") is None
예제 #3
0
 def _test_variable_type(self, docstring, varname, expected):
     docstring_parser = DocstringParser(docstring)
     assert expected == docstring_parser.find_type("(type|keywordtype|paramtype|vartype)", varname)
예제 #4
0
 def _test_return_type(self, docstring, expected):
     docstring_parser = DocstringParser(docstring)
     assert expected == docstring_parser.find_return_type()
 def test_docstring_defaults_legacy(self):
     parser = DocstringParser(docstring_default_legacy)
     assert parser.default_for("value") == "cat"
     assert parser.default_for("another") == "dog"
     assert parser.default_for(
         "some_class") == ":py:class:`apistubgen.test.models.FakeObject`"
 def test_defaults(self):
     parser = DocstringParser(docstring_multi_complex_type)
     # optional keyword-arguments are documented with "..."
     assert parser.default_for("country_hint") == "..."
     assert parser.default_for("documents") == None
 def _test_return_type(self, docstring, expected):
     parser = DocstringParser(docstring)
     assert expected == parser.ret_type
 def _test_variable_type(self, docstring, expected):
     parser = DocstringParser(docstring)
     for varname, expect_val in expected.items():
         actual = parser.type_for(varname)
         assert expect_val == actual