HelloThisIsFlo / Appdaemon-Test-Framework

Clean, human-readable tests for Appdaemon
https://hellothisisflo.github.io/Appdaemon-Test-Framework/
MIT License
45 stars 19 forks source link

Test run_at_sunrise and run_at_sunset #1

Closed SvenHoloch closed 5 years ago

SvenHoloch commented 6 years ago

First, great work! Thank you very much!

If I am not wrong, currently it is not possible to write tests for an app that uses the AppDaemon run_at_sunrise() and run_at_sunset() calls.

May it possible to add this feature?

HelloThisIsFlo commented 6 years ago

Hey,

This is correct, these 2 functions are not supported natively by the framework. But definitely, you can add support for it with a Pull Request. That's what Github is all about in the end :)

In terms of how you'd actually do that, I'm not totally sure. First you'd have to add it to the list of patched functions in init_framework.py. But then where would be the best place to perform the assertion. . . that's the part I'm not sure about. It feels related to time, so I'd be tempted to say time_travel.py, but then the sunset/sunrise functions represent a different way of perceiving time than actual minutes passing by and I'm not sure what would be the cleanest way to seamlesly integrate both in this time_travel.py module.

Do you have any suggestions? What interface would you have wished for when you intended to test your functions using run_at_sun[set/rise]()?

For a quick implementation you could also only do the first step, add it to the list of patched functions in init_framework.py, and then use it as a MagicMock from there. I'd totally merge that as it has no impact on the rest. But I'm definitely interested on your though on what an actual integration would look like 🙂

HelloThisIsFlo commented 5 years ago

I'm closing this issue for now.

Feel free to re-open if you wish to share more details on the use-case to possibly draft an implementation.