(self, trial)
| 397 | return self.idxs_vals[1] |
| 398 | |
| 399 | def assert_valid_trial(self, trial): |
| 400 | if not (hasattr(trial, "keys") and hasattr(trial, "values")): |
| 401 | raise InvalidTrial("trial should be dict-like", trial) |
| 402 | for key in TRIAL_KEYS: |
| 403 | if key not in trial: |
| 404 | raise InvalidTrial("trial missing key %s", key) |
| 405 | for key in TRIAL_MISC_KEYS: |
| 406 | if key not in trial["misc"]: |
| 407 | raise InvalidTrial('trial["misc"] missing key', key) |
| 408 | if trial["tid"] != trial["misc"]["tid"]: |
| 409 | raise InvalidTrial("tid mismatch between root and misc", trial) |
| 410 | # -- check for SON-encodable |
| 411 | if have_bson: |
| 412 | try: |
| 413 | bson.BSON.encode(trial) |
| 414 | except: |
| 415 | # TODO: save the trial object somewhere to inspect, fix, re-insert |
| 416 | # so that precious data is not simply deallocated and lost. |
| 417 | print("-" * 80) |
| 418 | print("CAN'T ENCODE") |
| 419 | print("-" * 80) |
| 420 | raise |
| 421 | if trial["exp_key"] != self._exp_key: |
| 422 | raise InvalidTrial("wrong exp_key", (trial["exp_key"], self._exp_key)) |
| 423 | # XXX how to assert that tids are unique? |
| 424 | return trial |
| 425 | |
| 426 | def _insert_trial_docs(self, docs): |
| 427 | """insert with no error checking""" |
no test coverage detected