Update of /cvsroot/happydoc/HappyDoc3/happydoclib/parseinfo
In directory sc8-pr-cvs1:/tmp/cvs-serv28607/happydoclib/parseinfo
Modified Files:
__init__.py
Log Message:
Use module-level options controlled by the application instead of
passing lots of arguments around to different objects.
Index: __init__.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/parseinfo/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** __init__.py 17 Nov 2002 15:05:43 -0000 1.1
--- __init__.py 1 Dec 2002 22:38:38 -0000 1.2
***************
*** 125,129 ****
#
! def getDocs(parent, fileName, includeComments=1, defaultConfigValues={}):
"""Retrieve information from the parse tree of a source file.
--- 125,162 ----
#
! _parser_options = {
! 'include_comments':1,
! }
!
! def setOption(**kwargs):
! """Set options to control the parser behavior.
!
! Options
!
! include_comments -- Boolean (default true) controlling whether
! text should be taken from comments in
! addition to docstrings.
!
! """
! global _parser_options
! #print 'Before %s' % str(_parser_options)
! #print 'Updating with %s' % str(kwargs)
! _parser_options.update(kwargs)
! #print 'After %s' % str(_parser_options)
! return
!
! def getOption(name):
! """Get options which control the parser behavior.
!
! Options
!
! name -- The name of the option whose value should be retrieved.
!
! """
! global _parser_options
! return _parser_options[name]
!
!
! def getDocs(parent, fileName):
"""Retrieve information from the parse tree of a source file.
***************
*** 133,146 ****
Name of the file to read Python source code from.
- includeComments=1 --
- Flag to indicate whether comments should be parsed for
- cases where __doc__ strings are not available.
-
"""
happydoclib.TRACE.into('parseinfo', 'getDocs',
parent=parent,
fileName=fileName,
- includeComments=includeComments,
- defaultConfigValues=defaultConfigValues,
)
f = open(fileName)
--- 166,173 ----
***************
*** 173,181 ****
tup = parser.ast2tuple(ast)
! if includeComments:
comment_info = parsecomments.extractComments(source)
else:
comment_info = {}
happydoclib.TRACE.write('Creating ModuleInfo')
mod_info = ModuleInfo(parent=parent,
tree=tup,
--- 200,216 ----
tup = parser.ast2tuple(ast)
!
! include_comments = getOption('include_comments')
!
! if include_comments:
comment_info = parsecomments.extractComments(source)
else:
comment_info = {}
happydoclib.TRACE.write('Creating ModuleInfo')
+
+ config_values = {}
+ global _parser_options
+ config_values.update(_parser_options)
+
mod_info = ModuleInfo(parent=parent,
tree=tup,
***************
*** 183,187 ****
fileName=fileName,
commentInfo=comment_info,
! defaultConfigValues=defaultConfigValues)
happydoclib.TRACE.outof(mod_info)
return mod_info
--- 218,222 ----
fileName=fileName,
commentInfo=comment_info,
! defaultConfigValues=config_values)
happydoclib.TRACE.outof(mod_info)
return mod_info
***************
*** 208,221 ****
'testNestedFunctions':'TestCases/parseinfo/test_nested_structures.py',
}
- include_comments = {
- 'testIgnoreComments':0,
- }
def setUp(self):
name = self._TestCase__testMethodName
filename = self.filename_map.get(name, self.default_filename)
- comments_flag = self.include_comments.get(name, 1)
self.filename = filename
! self.parsed_module = getDocs(None, filename, includeComments=comments_flag)
return
--- 243,253 ----
'testNestedFunctions':'TestCases/parseinfo/test_nested_structures.py',
}
def setUp(self):
name = self._TestCase__testMethodName
filename = self.filename_map.get(name, self.default_filename)
self.filename = filename
! setOption(include_comments=1)
! self.parsed_module = getDocs(None, filename)
return
***************
*** 317,328 ****
return
! # def testExtractVariablesFromModule(self):
! # expected_values = {
! # 'TestInt':1,
! # 'TestString':"String",
! # 'TestStringModule':"this has spaces in front and back",
! # 'url': 'b=B&a=A',
! # }
! # module_values = self.parsed_module.getConfigurationValues()
# if self.verboseLevel.get() > 1:
--- 349,367 ----
return
! def testExtractVariablesFromModule(self):
! expected_values = {
! 'include_comments':1,
! 'TestInt':1,
! 'TestString':"String",
! 'TestStringModule':"this has spaces in front and back",
! 'url': 'a=A&b=B',
! }
! module_values = self.parsed_module.getConfigurationValues()
!
! #for name, value in module_values.items():
! # self.failUnlessEqual(
! # value, expected_values[name],
! # 'Got %s for %s instead of %s' % (value, name, expected_values[name])
! # )
# if self.verboseLevel.get() > 1:
***************
*** 331,340 ****
# pprint.pprint(module_values)
! # assert (module_values == expected_values), 'Did not find expected variables'
! # return
def testExtractVariablesFromModuleWithException(self):
module_values = self.parsed_module.getConfigurationValues()
! assert not module_values, 'Did not find expected exception'
return
--- 370,383 ----
# pprint.pprint(module_values)
! self.failUnlessEqual(module_values, expected_values)
! return
def testExtractVariablesFromModuleWithException(self):
+ expected_values = {
+ 'include_comments':1,
+ }
module_values = self.parsed_module.getConfigurationValues()
! self.failUnlessEqual(module_values, expected_values)
! #assert not module_values, 'Did not find expected exception'
return
***************
*** 371,394 ****
return
def testIgnoreComments(self):
! assert not self.parsed_module._comments, \
'Did not ignore module comments %s' % self.filename
! assert self.parsed_module._docstring, \
'Did not find docstring for module %s' % self.filename
! c = self.parsed_module['WithComments']
! assert not c._comments, \
! 'Did not ignore comments in class WithComments'
assert not c._docstring, \
'Found unexepcted docstring for class WithComments'
method = c['__init__']
! assert not method._comments, \
'Did not ignore comments in method WithComments.__init__'
assert not method._docstring, \
'Found unexpected docstring for method WithComments.__init__'
! c = self.parsed_module['WithoutComments']
! assert not c._comments, \
'Found unexepected comments for class WithoutComments'
assert c._docstring, \
--- 414,453 ----
return
+ def testIgnoreCommentsSetting(self):
+ setOption(include_comments=0)
+ include_comments = getOption('include_comments')
+ if include_comments:
+ self.fail('include_comments option not turned off (%s)' % include_comments)
+ return
+
+ def testIncludeCommentsSetting(self):
+ setOption(include_comments=1)
+ include_comments = getOption('include_comments')
+ if not include_comments:
+ self.fail('include_comments option not turned off')
+ return
+
def testIgnoreComments(self):
! setOption(include_comments=0)
! parsed_module = getDocs(None, self.filename)
! assert not parsed_module._comments, \
'Did not ignore module comments %s' % self.filename
! assert parsed_module._docstring, \
'Did not find docstring for module %s' % self.filename
! c = parsed_module['WithComments']
! assert not c.getComment(), \
! 'Did not ignore comments in class WithComments (%s)' % c.getComment()
assert not c._docstring, \
'Found unexepcted docstring for class WithComments'
method = c['__init__']
! assert not method.getComment(), \
'Did not ignore comments in method WithComments.__init__'
assert not method._docstring, \
'Found unexpected docstring for method WithComments.__init__'
! c = parsed_module['WithoutComments']
! assert not c.getComment(), \
'Found unexepected comments for class WithoutComments'
assert c._docstring, \
***************
*** 396,400 ****
method = c['__init__']
! assert not method._comments, \
'Found unexpected comments for method WithoutComments.__init__'
assert method._docstring, \
--- 455,459 ----
method = c['__init__']
! assert not method.getComment(), \
'Found unexpected comments for method WithoutComments.__init__'
assert method._docstring, \
***************
*** 580,583 ****
--- 639,675 ----
'Docstring for InnerFunction2 does not match.'
+ return
+
+ def testIncludeCommentsOptionTrue(self):
+ happydoclib.parseinfo.setOption(include_comments=1)
+
+ input_filename = os.path.join( 'TestCases',
+ 'parseinfo',
+ 'test_decorated_comments.py'
+ )
+ module_info = happydoclib.parseinfo.getDocs(None, input_filename)
+
+ func_names = module_info.getFunctionNames()
+ for func_name in func_names:
+ func_info = module_info.getFunctionInfo(func_name)
+ comments = func_info.getComment()
+ self.failUnless(comments, 'Did not get any comments for %s.' % func_name)
+ return
+
+ def testIncludeCommentsOptionFalse(self):
+ happydoclib.parseinfo.setOption(include_comments=0)
+
+ input_filename = os.path.join( 'TestCases',
+ 'parseinfo',
+ 'test_decorated_comments.py'
+ )
+ module_info = happydoclib.parseinfo.getDocs(None, input_filename)
+
+ func_names = module_info.getFunctionNames()
+ for func_name in func_names:
+ func_info = module_info.getFunctionInfo(func_name)
+ comments = func_info.getComment()
+ if comments:
+ self.fail('Got comments for %s.' % func_name)
return
|