openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 70 forks source link

[testing] Error executing `/Script Examples/Python/testing_example.py` #177

Closed fivesails closed 5 years ago

fivesails commented 5 years ago

When executed, a
ValueError: when: "Item TestNumber1 received update" could not be parsed because Item "TestNumber1" is not in the ItemRegistry occurs. To Reproduce Steps to reproduce the behavior:

  1. copy /Script Examples/Python/testing_example.py to the appropriate folder

Environment (please complete the following information):

Additional context

  1. I think,this error occurs because the @when decorator is expanded before the unit test creates the items. If the creation of the Trigger is delayed, the unit test runs fine on my system. I attach that version: testing_2_example.py.txt
  2. In the current version of the library, the methods in core.items are add_item() iso add() and remove_item() iso remove().
  3. The items are not required therefore removed from the files' first comment
5iver commented 5 years ago

Thank you for pointing this out, @fivesails. There are many layers of issues with this example. I've never gotten around to really going through this module, but I'd like to start using it to build out tests that use each of the modules. There have been several bugs introduced in the script as the core modules evolved. Definitely, the functions in core.items are add_item and remove_item. The when decorator does validation of the Items, but I'm not sure yet how the script worked before with the old decorator.

Please submit a PR with your fixes so that others don't bump into this. At some point in the future, I'll dig into this module and example.

fivesails commented 5 years ago

Thank you for your reply, I submitted a PR