You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
760 B

3 years ago
  1. from typing import Dict, Any
  2. from gooey.python_bindings.types import PublicGooeyState
  3. from gooey.python_bindings import types as t
  4. def validate_public_state(state: Dict[str, Any]) -> PublicGooeyState:
  5. """
  6. Very, very minimal validation the shape of the incoming state
  7. is inline with the PublicGooeyState type.
  8. TODO: turn this into something useful.
  9. """
  10. top_level_keys = PublicGooeyState.__annotations__.keys()
  11. assert set(top_level_keys) == set(state.keys())
  12. for item in state['active_form']:
  13. assert 'type' in item
  14. expected_keys = getattr(t, item['type']).__annotations__.keys()
  15. a = set(expected_keys)
  16. b = set(item.keys())
  17. assert set(expected_keys) == set(item.keys())
  18. return state