Consider to implement a more declarative approach for validate_settings. You wrote
Still, I can't think of a better way other than checking each individual key in each individual dictionay/subdictionary, since each key has a different name, each subdict has a different structure and many different data types are used for values.
Of course, butI can think of one. I guess a generic description for thisthe settings cannot be much more complex than your actual JSON file? Why not have a complementary description file in JSON for those values, for example, like this:
{
"global_settings": {
"param1": "integer",
"param2": "bool",
"param3": "double|optional"
},
"simulation_settings": {
"param4": "bool",
"param5": "bool",
"param6": "bool|optional"
},
"output_settings": {
"file_settings": {
"param7": "string"
"param8": "bool"
"param9": "bool|optional"
},
"param10": "bool"
}
}
Now, validate_settings can use this description and do the validation for data types and non-optional values in a generic fashion. And that makes the actual testing of validate_settings a whole lot simpler, since for getting full test coverage, you can now use a few simple tests which cover each data type once and the optional/non-optional feature.
Of course, you will also have to proofread the description file to make sure it contains no errors, but that is way less effort than writing a test for each original attribute (and proofread also there is no error in those tests).
As an alternative, you could also have a look at JSON schema, which seems to be way more powerful, but I am not an expert on this.