MCPcopy
hub / github.com/pydata/xarray / test_load_async

Method test_load_async

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

Source from the content-addressed store, hash-verified

575
576 @pytest.mark.asyncio
577 async def test_load_async(self) -> None:
578 # Note: please keep this in sync with test_load above as much as possible!
579
580 # Copied from `test_load` on the base test class, but won't work for netcdf
581 expected = create_test_data()
582
583 @contextlib.contextmanager
584 def assert_loads(vars=None):
585 if vars is None:
586 vars = expected
587 with self.roundtrip(expected) as actual:
588 for k, v in actual.variables.items():
589 # IndexVariables are eagerly loaded into memory
590 assert v._in_memory == (k in actual.dims)
591 yield actual
592 for k, v in actual.variables.items():
593 if k in vars:
594 assert v._in_memory
595 assert_identical(expected, actual)
596
597 with pytest.raises(AssertionError):
598 # make sure the contextmanager works!
599 with assert_loads() as ds:
600 pass
601
602 with assert_loads() as ds:
603 await ds.load_async()
604
605 with assert_loads(["var1", "dim1", "dim2"]) as ds:
606 await ds["var1"].load_async()
607
608 # verify we can read data even after closing the file
609 with self.roundtrip(expected) as ds:
610 actual = await ds.load_async()
611 assert_identical(expected, actual)
612
613 def test_dataset_compute(self) -> None:
614 expected = create_test_data()

Callers

nothing calls this directly

Calls 4

roundtripMethod · 0.95
assert_identicalFunction · 0.90
create_test_dataFunction · 0.85
load_asyncMethod · 0.45

Tested by

no test coverage detected