Skip to content

Commit

Permalink
fix tests to use new default
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Oct 31, 2024
1 parent 9bb044f commit 1fe2d64
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ def test_memmap_write(tmp_path):
tmpfile = str(tmp_path / "data.asdf")
tree = {"data": np.zeros(100)}

with asdf.AsdfFile(tree) as af:
with asdf.AsdfFile(tree, memmap=False) as af:
# Make sure we're actually writing to an internal array for this test
af.write_to(tmpfile, all_array_storage="internal")

Expand All @@ -1002,7 +1002,7 @@ def test_readonly(tmp_path):
af.write_to(tmpfile, all_array_storage="internal")

# Opening in read mode (the default) should mean array is readonly
with asdf.open(tmpfile) as af:
with asdf.open(tmpfile, memmap=True) as af:
assert af["data"].flags.writeable is False
with pytest.raises(ValueError, match=r"assignment destination is read-only"):
af["data"][0] = 41
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def test_block_data_change(pad_blocks, tmp_path):
with asdf.AsdfFile(tree) as af:
af.write_to(tmpfile, pad_blocks=pad_blocks)

with asdf.open(tmpfile, mode="rw") as af:
with asdf.open(tmpfile, mode="rw", memmap=True) as af:
assert np.all(af.tree["data"] == 0)
array_before = af.tree["data"].__array__()
af.tree["data"][:5] = 1
Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_open_readonly(tmp_path):
os.chmod(tmpfile, 0o440)
assert os.access(tmpfile, os.W_OK) is False

with asdf.open(tmpfile) as af:
with asdf.open(tmpfile, memmap=True) as af:
assert af["baz"].flags.writeable is False

with pytest.raises(PermissionError, match=r".* Permission denied: .*"), asdf.open(tmpfile, mode="rw"):
Expand Down
10 changes: 6 additions & 4 deletions asdf/_tests/test_array_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,11 @@ def filename_with_array(tmp_path_factory):
@pytest.mark.parametrize(
"open_kwargs,should_memmap",
[
({}, True),
({"memmap": True}, True),
({"memmap": False}, False),
({}, False),
({"lazy_load": True, "memmap": True}, True),
({"lazy_load": False, "memmap": True}, True),
({"lazy_load": True, "memmap": False}, False),
({"lazy_load": False, "memmap": False}, False),
],
)
def test_open_no_memmap(filename_with_array, open_kwargs, should_memmap):
Expand All @@ -823,7 +825,7 @@ def test_open_no_memmap(filename_with_array, open_kwargs, should_memmap):
default (no kwargs)
memmap
"""
with asdf.open(filename_with_array, lazy_load=False, **open_kwargs) as af:
with asdf.open(filename_with_array, **open_kwargs) as af:
array = af.tree["array"]
if should_memmap:
assert isinstance(array.base, np.memmap)
Expand Down
6 changes: 3 additions & 3 deletions asdf/_tests/test_generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_read_fd():
f.read(0)
return f

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2
assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)

Expand All @@ -133,7 +133,7 @@ def get_read_fd():
assert f._uri == path.as_uri()
return f

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2
assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)

Expand Down Expand Up @@ -173,7 +173,7 @@ def get_read_fd():
assert f._uri == path.as_uri()
return f

with _roundtrip(tree, get_write_fd, get_read_fd) as ff:
with _roundtrip(tree, get_write_fd, get_read_fd, read_options={"memmap": True}) as ff:
assert len(ff._blocks.blocks) == 2
assert isinstance(ff._blocks.blocks[0].cached_data, np.memmap)
ff.tree["science_data"][0] = 42
Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def do_asserts(ff):

assert_array_equal(ff.tree["internal"], exttree["cool_stuff"]["a"])

with asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri()) as ff:
with asdf.AsdfFile({}, uri=(tmp_path / "main.asdf").as_uri(), memmap=True) as ff:
# avoid passing tree to AsdfFile to avoid the deprecation warning, this can be updated
# when automatic find_references on AsdfFile.__init__ is removed
ff.tree = tree
Expand Down

0 comments on commit 1fe2d64

Please sign in to comment.