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

Improve testability #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DerFetzer
Copy link

This takes ideas from nobbi1991 and extends them with a time-aware scheduler.

Goal is to simplify testing of user rules. I implemented an example in habapp-rule-test-demo.
watch_change is not working at the moment since it seems to use a different mechanism.

* Make SimpleRuleRunner publicly available
* Add TimeAwareRuleRunner to allow testing of scheduled tasks
* Add base test class and helper methods
@spacemanspiff2007
Copy link
Owner

spacemanspiff2007 commented Apr 4, 2023

I think the rule factory is a nice idea.
We could have something like create_rule(SimpleRule, 'p1', 2) which will do SimpleRule('p1', 2) in normal cases and during testing it won't create anything. What do you think about something like that?
Obviously I'd implement it using pytest since this is what HABApp uses so the fixtures can be shared

@DerFetzer
Copy link
Author

I think the rule factory is a nice idea. We could have something like create_rule(SimpleRule, 'p1', 2) which will do SimpleRule('p1', 2) in normal cases and during testing it won't create anything. What do you think about something like that?

Sure, we could do that. What do you think would be the best way to figure out if we are running tests or not? In the demo repo I am using an environment variable. Maybe we could do something similar.

Obviously I'd implement it using pytest since this is what HABApp uses so the fixtures can be shared

I am not familiar with pytest but I'll figure it out.

@spacemanspiff2007
Copy link
Owner

I am not familiar with pytest but I'll figure it out.

No worries - this issue is more like a brainstorming issue to create a good concept and evaluate some ideas.
I by no means expect you to implement this and modify all existing test cases yourself.
I'll do the heavy lifting myself but I'd rather have a good concept first instead of quickly implementing something that is not properly thought through. And for that I'll appreciate any input.

Have you found the ability to progress in time useful? I'd have expected these tests are more like an input -> expected output black box.

@DerFetzer
Copy link
Author

No worries - this issue is more like a brainstorming issue to create a good concept and evaluate some ideas.

👍

Have you found the ability to progress in time useful? I'd have expected these tests are more like an input -> expected output black box.

I see this as a very important aspect because I do want to test as much of my rules as possible. And most of them need some kind of temporal behavior.

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

Successfully merging this pull request may close these issues.

2 participants