在plone 5中,我创建一个名为IFindMathModeTexInText
的接口,并使用five.grok
注册一个全局实用程序,如下所示:
class FindMathModeTexInText (grok.GlobalUtility):
implements (IFindMathModeTexInText)
def process(self, text):
equation_indices, all_indices = find_equation(text)
return create_list_of_text_nodes(text, equation_indices, all_indices)
我在不同的模块中使用
IFindMathModeTexInText
调用了zope.component.getUtility
,如下所示:result = getUtility(IFindMathModeTexInText).process(new_el_text)
运行
bin/instance fg
时我没有问题但是,当我运行
bin/test
时,出现以下错误:in getUtility
raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass nti.content.util.common_interfaces.IFindMathModeTexInText>, '')
我了解,如果找不到实用程序,将引发ComponentLookupError。为什么在运行
bin.test
时会出现此错误,而在运行bin/instance fg
时会找到实用程序。ps:完整的回溯如下:
Error in test test_html_header (nti.content.tools.tests.test_html_to_latex.TestHTMLToLatex)
Traceback (most recent call last):
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/buildout-cache/eggs/unittest2-0.5.1-py2.7.egg/unittest2/case.py", line 340, in run
testMethod()
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/tests/test_html_to_latex.py", line 31, in test_html_header
node = RichText.process(script, reading_type = True)
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/rich_text_adapter.py", line 21, in process
me.add_child(Run.process(element,[],reading_type))
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 25, in process
me = check_child(me, element, reading_type)
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 322, in check_child
me.add_child(_process_h1_elements(child,reading_type))
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 393, in _process_h1_elements
return Paragraph.process(element, ['Heading1'], reading_type)
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 39, in process
me = check_element_text(me, element)
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/sources/nti.content/nti/content/tools/html_adapter/run_html_adapter.py", line 287, in check_element_text
list_of_child_nodes = getUtility(IFindMathModeTexInText).process(new_el_text)
File "/Users/ega/CCMF/PloneCourseContentCMF/PloneCourseContentCMF-Buildout/buildout-cache/eggs/zope.component-3.9.5-py2.7.egg/zope/component/_api.py", line 169, in getUtility
raise ComponentLookupError(interface, name)
ComponentLookupError: (<InterfaceClass nti.content.util.common_interfaces.IFindMathModeTexInText>, '')
谢谢
最佳答案
我通过定义plone.app.testing documentation中记录的单元测试层解决了这个问题。