def process_file(f, processor):
try:
dirpath, filename = os.path.split(f)
modulename = filename[:-3]
if dirpath in sys.path:
sys.path.remove(dirpath)
sys.path.insert(0, dirpath)
module = __import__(modulename)
member_names = dir(module)
print('Testing file %s' % f)
for name in member_names:
try:
attr = getattr(module, name)
if isinstance(attr, Template):
description = '(member name %s)' % name
test_if_template(attr, description, processor)
elif isinstance(attr, types.ListType):
for mem in attr:
description = '(element in list %s)' % name
test_if_template(mem, description, processor)
elif isinstance(attr, types.DictionaryType):
for k in attr:
description = '(%s[%s])' % (name, k)
test_if_template(attr[k], description, processor)
else:
attr = None
except Exception as e:
print('Exception when testing member %s' % name)
if processor.verbose:
print(traceback.format_exc())
except Exception as e:
print('Exception when processing file %s: %s' % (f, e))
if processor.verbose:
print(traceback.format_exc())
评论列表
文章目录