-
Notifications
You must be signed in to change notification settings - Fork 55
Simplify setting of attributes #49
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
Conversation
f2e7472
to
eff1c21
Compare
* Support omitting the value for `state.set('domain.value', some_attr='abc')` * Support setting attributes like `domain.value.some_attr = 'abc'` * Support setting attributes like `state.set_attr('domain.value.attr', 'abc')`
This looks good - thanks for submitting. Could you also include updates to tests for the new features, and docs to reflect these changes? |
I've updated the docs. I assume I should be looking at I was thinking about using the following pyscript to test: pyscript.test_attr.a = False
pyscript.test_attr.b = False
@service
def test_set_attr(key, value):
state.set_attr(f"pyscript.test_attr.{key}", value)
@service
def test_attr_a(value):
pyscript.test_attr.a = value
@service
def test_attr_b(value):
pyscript.test_attr.a = value
@state_trigger("True or pyscript.test_attr")
def test_attr():
pyscript.test_attr = "on" if any([pyscript.test1.a, pyscript.test1.b]) else "off" |
It's probably sufficient to add expressions and results to The first test function in that file executes all the tests in the long list. The list has pairs of [source_code, expected_result]. So you could do things like:
You should test both directions (ie, setting the variable directly and checking the value with The second function checks for exceptions. So you could add tests that raise specific exceptions, and confirm you get the correct error. Generally when I write those, I first put in an empty error message so the test fails, and I can see what error is generated. So long as that looks correct, I then paste that in as the expected error message. |
You'll need to rebase given the changes to master. Also, are you planning to add some tests per the discussion above? |
@swazrgb - do you plan to update this PR? Or do you want me to manually merge the changes? |
Manually added these changes, with a few tweaks, and added tests. |
Support omitting the value for
state.set('domain.value', some_attr='abc')
Support setting attributes like
domain.value.some_attr = 'abc'
Support setting attributes like
state.set_attr('domain.value.attr', 'abc')