在plone 5中运行bin / test时找不到实用程序

时间:2015-04-17 19:39:02

标签: unit-testing plone zope utility grok

在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>, '')

由于

1 个答案:

答案 0 :(得分:2)

我通过定义plone.app.testing documentation中记录的单元测试层来解决问题。