File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ import argparse
2+ import importlib
3+ import ast
4+
5+ from .docscrape_sphinx import get_doc_object
6+
7+
8+ def main (argv = None ):
9+ """Test numpydoc docstring generation for a given object"""
10+
11+ ap = argparse .ArgumentParser (description = __doc__ )
12+ ap .add_argument ('import_path' , help = 'e.g. numpy.ndarray' )
13+
14+ def _parse_config (s ):
15+ key , _ , value = s .partition ('=' )
16+ value = ast .literal_eval (value )
17+ return key , value
18+
19+ ap .add_argument ('-c' , '--config' , type = _parse_config ,
20+ action = 'append' ,
21+ help = 'key=val where val will be parsed by literal_eval, '
22+ 'e.g. -c use_plots=True. Multiple -c can be used.' )
23+ args = ap .parse_args (argv )
24+
25+ parts = args .import_path .split ('.' )
26+
27+ for split_point in range (len (parts ), 0 , - 1 )[::- 1 ]:
28+ try :
29+ path = '.' .join (parts [:split_point ])
30+ obj = importlib .import_module (path )
31+ except ImportError :
32+ continue
33+ break
34+ else :
35+ raise ImportError ('Could not resolve {!r} to an importable object'
36+ '' .format (args .import_path ))
37+
38+ for part in parts [split_point :]:
39+ obj = getattr (obj , part )
40+
41+ print (get_doc_object (obj , config = dict (args .config or [])))
42+
43+ if __name__ == '__main__' :
44+ main ()
Original file line number Diff line number Diff line change 1+ from numpydoc .__main__ import main
2+
3+ import sys
4+ import io
5+
6+
7+ def test_main ():
8+ f = io .StringIO ()
9+ sys .stdout , old_stdout = f , sys .stdout
10+ main (['numpydoc.__main__.main' ])
11+ assert f .getvalue ().strip () == main .__doc__
12+ sys .stdout = old_stdout
You can’t perform that action at this time.
0 commit comments