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

Should a setup state also pass an assertion? #12

Open
paulwarwicker opened this issue Jan 2, 2024 · 0 comments
Open

Should a setup state also pass an assertion? #12

paulwarwicker opened this issue Jan 2, 2024 · 0 comments

Comments

@paulwarwicker
Copy link

Thanks for making this code available. Very useful indeed.

I am new to python/appdaemon testing and was debugging a test case, but should the commented out assertions below not return true? If I comment the line out it passes okay.

test code

from appdaemon_testing.pytest import automation_fixture
from appdaemon_testing.pytest import mock
from apps.automation import Automation

@automation_fixture(
    Automation,
    args={
    },
)

def automation() -> Automation:
    pass

...
def test_not_is_dusk(hass_driver, automation: Automation):
    with hass_driver.setup():
        hass_driver.set_state('sun.sun', 0, attribute_name='elevation')
    # assert automation.get_state('sun.sun', attribute_name='elevation') == 0 # <<<<<<<<<<<<<<<<<<<<<<
    assert not automation.is_dusk()

def test_is_dusk(hass_driver, automation: Automation):
    with hass_driver.setup():
        hass_driver.set_state('sun.sun', -4, attribute_name='elevation')
    # assert automation.get_state('sun.sun', attribute_name='elevation') == -4 # <<<<<<<<<<<<<<<<<<<<<<
    assert automation.is_dusk()

code under test

class Automation(hass.Hass):
...
    def get_sun_elevation(self):
        elev = self.get_state('sun.sun', attribute='elevation')
        self.log(f'   elev ({elev:2.2f})', level='DEBUG')
        return elev

    def is_dusk(self):
        elev = self.get_sun_elevation()
        dusk = elev < -3
        t = 'is' if dusk else 'is not'
        self.log(f'   {t} dusk', level='DEBUG')
        return dusk
...
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

No branches or pull requests

1 participant