COVESA / vss-tools

Software for working with VSS (https://github.com/COVESA/vehicle_signal_specification)
Mozilla Public License 2.0
55 stars 55 forks source link

Improve quantity check #318

Closed erikbosch closed 10 months ago

erikbosch commented 10 months ago

Give proper error if "definition" is not given and not any other attributes either. (In that case v is NoneType som you cannot check for "definition")

Detected by https://github.com/COVESA/vehicle_signal_specification/pull/526

Currently you get the output below if you have not added definition and no other attributes as well

erik@debian4:~/vss-tools/tests/vspec/test_units$ ../../../vspec2json.py --json-pretty  -u units_all.yaml -q quantities_no_def.yaml signals_with_special_units.vspec out.json
INFO     Output to json format
INFO     Known extended attributes: 
Traceback (most recent call last):
  File "/home/erik/vss-tools/tests/vspec/test_units/../../../vspec2json.py", line 19, in <module>
    vspec2x.main(["--format", "json"]+sys.argv[1:])
  File "/home/erik/vss-tools/vspec2x.py", line 158, in main
    vspec.load_quantities(args.vspec_file, args.quantity_file)
  File "/home/erik/vss-tools/vspec/__init__.py", line 883, in load_quantities
    nbr_quantities = VSSQuantityCollection.load_config_file(quantity_file)
  File "/home/erik/vss-tools/vspec/model/constants.py", line 232, in load_config_file
    if "definition" in v:
TypeError: argument of type 'NoneType' is not iterable

With this change you instead get:

erik@debian4:~/vss-tools/tests/vspec/test_units$ ../../../vspec2json.py --json-pretty  -u units_all.yaml -q quantities_no_def.yaml signals_with_special_units.vspec out.json
INFO     Output to json format
INFO     Known extended attributes: 
ERROR    No definition found for quantity volume