gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:23:41 24 4
gpt4 key购买 nike

在 plone 5 中,我创建了一个名为 IFindMathModeTexInText 的接口(interface),并使用 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 中所述.

关于unit-testing - 在 plone 5 中运行 bin/test 时找不到实用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29708026/

24 4 0
文章推荐: d3.js - 在 D3 中设置