test_input_schema.py 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import inspect
  2. from flexmeasures import Sensor
  3. from flexmeasures.data.schemas.io import Input
  4. def test_input_schema():
  5. """Input schema must describe all keyword arguments of the Sensor.search_beliefs method."""
  6. arg_names = inspect.getfullargspec(Sensor.search_beliefs).args
  7. field_names = Input._declared_fields.keys()
  8. # These arguments may have been mapped to a different field name (state a reason)
  9. mapped_arg_names = {
  10. "self": "sensor", # mapped in Sensor.search_beliefs but not in TimedBelief.search
  11. "beliefs_before": "belief_time", # todo: actually named 'prior' in the API, so this needs consolidating, preferably in the schema
  12. }
  13. # These arguments are not mapped to a field at all (state a reason)
  14. excluded_arg_names = [
  15. "as_json", # used in Sensor.search_beliefs but not in TimedBelief.search
  16. ]
  17. arg_names_without_associated_fields = [
  18. arg_name
  19. for arg_name in arg_names
  20. if mapped_arg_names.get(arg_name, arg_name) not in field_names
  21. and arg_name not in excluded_arg_names
  22. ]
  23. if arg_names_without_associated_fields:
  24. raise NotImplementedError(
  25. f"Some search arguments have no associated field defined. Define a field for, or exclude from this test, the following arguments: {arg_names_without_associated_fields}",
  26. )