在 plone 5 中 运行 bin/test 时找不到实用程序
Utility not found when run bin/test in plone 5
在 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)
我在不同的模块中使用 zope.component.getUtility
调用了 IFindMathModeTexInText
,如下所示:
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 中记录的单元测试层解决了这个问题。
在 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)
我在不同的模块中使用 zope.component.getUtility
调用了 IFindMathModeTexInText
,如下所示:
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 中记录的单元测试层解决了这个问题。