Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to test rules e.g. with pytest #465

Open
1 of 6 tasks
spacemanspiff2007 opened this issue Dec 9, 2024 · 1 comment
Open
1 of 6 tasks

Add ability to test rules e.g. with pytest #465

spacemanspiff2007 opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels
feature request New feature

Comments

@spacemanspiff2007
Copy link
Owner

spacemanspiff2007 commented Dec 9, 2024

It would be nice if the rules could be easily tested e.g. with pytest.

Identified things to do:

  • Create a way to import rule classes in other files without executing them
  • Mock items
  • Time Travel
  • Bind global states (event bus, item registry) to runtime object
  • Mock runtime object
  • Time travel for item constant watcher

Existing testing implementations
DerFetzner
nobbi1991


@DerFetzer
I've opened this issue so we can track progress here instead of your PR.
The rework of the scheduler was lots of work, way more than I anticipated but I have not forgotten about the issue.
I'm gradually working on it, but unfortunately time is limited at the moment (as always).

The most difficult thing is that a new rule runner will have to be run asynchronously and that makes things much more difficult ...

Creating rules in an importable way already works:

from HABApp.rule import create_rule,

create_rule(MyRuleClass, arg1)
@spacemanspiff2007 spacemanspiff2007 added the feature request New feature label Dec 9, 2024
@spacemanspiff2007 spacemanspiff2007 self-assigned this Dec 9, 2024
@spacemanspiff2007
Copy link
Owner Author

@DerFetzer
Since you offered to help: I am currently struggling with the RuleRunner.
Since callbacks can be both synchronous and asynchronous I'm thinking about making the rulerunner fully async.
However that would require reworking of all tests and all docs examples and the script that runs the examples so I'm currently hesitant to go that way.
However I can't get the tests to pass - maybe you have an idea?
The Dev branch is up to date ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature
Projects
None yet
Development

No branches or pull requests

1 participant