MCPcopy Create free account
hub / github.com/pydata/xarray / test_robust_getitem

Method test_robust_getitem

xarray/tests/test_backends.py:400–421  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

398
399class TestCommon:
400 def test_robust_getitem(self) -> None:
401 class UnreliableArrayFailure(Exception):
402 pass
403
404 class UnreliableArray:
405 def __init__(self, array, failures=1):
406 self.array = array
407 self.failures = failures
408
409 def __getitem__(self, key):
410 if self.failures > 0:
411 self.failures -= 1
412 raise UnreliableArrayFailure
413 return self.array[key]
414
415 array = UnreliableArray([0])
416 with pytest.raises(UnreliableArrayFailure):
417 array[0]
418 assert array[0] == 0
419
420 actual = robust_getitem(array, 0, catch=UnreliableArrayFailure, initial_delay=0)
421 assert actual == 0
422
423
424class NetCDF3Only:

Callers

nothing calls this directly

Calls 2

robust_getitemFunction · 0.90
UnreliableArrayClass · 0.85

Tested by

no test coverage detected