FaradayInstitution / BPX

BPX schema in pydantic and JSON schema format, and parsers
MIT License
25 stars 12 forks source link

BPX parser raises irrelevant validation errors #52

Open ejfdickinson opened 4 months ago

ejfdickinson commented 4 months ago

In the presence of an invalid BPX object, the BPX parser reports non-existent errors in addition to real errors.

Repeat

  1. import bpx
    bpx.parse_bpx_file("examples/nmc_pouch_cell_BPX.json", v_tol=1)

Here, the file is parsed with no errors (valid BPX).

  1. Delete line 10 from nmc_pouch_cell_BPX.json:

    "Ambient temperature [K]": 298.15,
  2. import bpx
    bpx.parse_bpx_file("examples/nmc_pouch_cell_BPX.json", v_tol=1)

The parser raises 40 errors, most of which are not correctly identified (missing or extra fields). The only real error (missing required field ["Parameterisation"]["Cell"]["Ambient temperature [K]"]) is raised twice, as the first and last reported error.

ejfdickinson commented 4 months ago

@rtimms @martinjrobins

rtimms commented 2 months ago

Maybe related, it seems like some optional fields are not validated correctly. E.g. the below test fails (no ValidationError is raised even though title should be a string!)

    def test_bad_title(self):
        test = copy.copy(self.base)
        test["Header"]["Title"] = 1
        with self.assertRaises(ValidationError):
            parse_obj_as(BPX, test)

@Ubham16 can you take a look?