0

我有一个 pyclips / clips 程序,我使用 pytest 为其编写了一些单元测试。每个测试用例都包含一个初始clips.Clear()值,然后是通过clips.Load(rule_file.clp). 单独运行每个测试都可以正常工作。

然而,当告诉 pytest 运行所有测试时,有些失败并显示ClipsError: S03: environment could not be cleared. 实际上,这取决于 .py 文件中测试的顺序。似乎有测试用例导致后续测试用例抛出异常。

也许某些剪辑代码仍在“使用中”,因此清除失败?我在这里读到(clear)

清除 CLIPS。从 CLIPS 环境中删除所有构造和所有关联的数据结构(例如事实和实例)。可以随时安全地执行清除,但是,某些构造在使用时不允许自己被删除。

这里可能是这种情况吗?是什么导致(clear)命令失败?

编辑:

我能够缩小问题的范围。在以下情况下会发生:

test_case_A 在 test_case_B 之前。在 test_case_A 中有一个test例如

(test (eq (type ?f_bio_puts) clips_FUNCTION))

f_bio_puts已设置为

(slot f_bio_puts (default [nil]))

所以测试一个槽变量的类型,它已经设置为[nil]最初,似乎会导致(clear)命令失败。有任何想法吗?

编辑 2

我想我知道是什么导致了这个问题。这是test线。我调整了我的代码以使其在剪辑对话框窗口中运行。我在加载时遇到了这个错误(batch ...)

[INSFUN2] No such instance nil in function type.
[DRIVE1] This error occurred in the join network
   Problem resided in associated join
       Of pattern #1 in rule part_1

我想这是被掩盖的 pyclips 的错误。

4

1 回答 1

1

更改 CLIPS 源代码construct.c 文件中的EnvClear 函数,添加以下代码行以重置错误标志:

globle void EnvClear(
  void *theEnv)
  {
   struct callFunctionItem *theFunction;

   /*==============================*/
   /* Clear error flags if issued  */
   /* from an embedded controller. */
   /*==============================*/

   if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && 
       (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
       (EvaluationData(theEnv)->CurrentExpression == NULL))
     {
      SetEvaluationError(theEnv,FALSE);
      SetHaltExecution(theEnv,FALSE);
     }
于 2017-03-24T21:37:51.953 回答