CLIPS(清除)命令失败/在pyclips中抛出异常

时间:2017-03-23 19:55:26

标签: pytest clips pyclips

我有一个pyclips / clips程序,我用pytest编写了一些单元测试。 每个测试用例都会初始化clips.Clear(),然后通过clips.Load(rule_file.clp)执行实际剪辑COOL代码。单独运行每个测试都可以正常工作。

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

也许某些剪辑代码仍然“正在使用”,以便清除失败? 我看了(clear)

here
  

清除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]的slot变量的类型似乎会导致(clear)命令失败。有什么想法吗?

编辑2

我想我知道造成这个问题的原因。它是test行。我调整了我的代码,使其在剪辑对话框Windows中运行。通过(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的错误,这被掩盖了。

1 个答案:

答案 0 :(得分: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);
     }
相关问题