Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the use of tmpdir and related #1759

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ The ASDF Standard is at v1.6.0
- Require pytest 7+ and update asdf pytest plugin to be compatible
with the current development version of pytest (8.1) [#1731]

- Eliminate the use of the legacy ``tmpdir`` fixture in favor of
the new ``tmp_path`` fixture for temporary directory creation. [#1759]

3.0.1 (2023-10-30)
------------------

Expand Down
22 changes: 11 additions & 11 deletions asdf/_tests/commands/tests/test_defragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from asdf.commands import main


def _test_defragment(tmpdir, codec):
def _test_defragment(tmp_path, codec):
x = np.arange(0, 1000, dtype=float)

tree = {
Expand All @@ -19,8 +19,8 @@ def _test_defragment(tmpdir, codec):
"not_shared": np.arange(100, 0, -1, dtype=np.uint8),
}

path = os.path.join(str(tmpdir), "original.asdf")
out_path = os.path.join(str(tmpdir), "original.defragment.asdf")
path = os.path.join(str(tmp_path), "original.asdf")
out_path = os.path.join(str(tmp_path), "original.defragment.asdf")
ff = AsdfFile(tree)
ff.write_to(path)
with asdf.open(path) as af:
Expand All @@ -30,26 +30,26 @@ def _test_defragment(tmpdir, codec):

assert result == 0

files = get_file_sizes(str(tmpdir))
files = get_file_sizes(str(tmp_path))

assert "original.asdf" in files
assert "original.defragment.asdf" in files

assert files["original.defragment.asdf"] < files["original.asdf"]

with asdf.open(os.path.join(str(tmpdir), "original.defragment.asdf")) as ff:
with asdf.open(os.path.join(str(tmp_path), "original.defragment.asdf")) as ff:
assert_tree_match(ff.tree, tree)
assert len(ff._blocks.blocks) == 2


def test_defragment_zlib(tmpdir):
_test_defragment(tmpdir, "zlib")
def test_defragment_zlib(tmp_path):
_test_defragment(tmp_path, "zlib")


def test_defragment_bzp2(tmpdir):
_test_defragment(tmpdir, "bzp2")
def test_defragment_bzp2(tmp_path):
_test_defragment(tmp_path, "bzp2")


def test_defragment_lz4(tmpdir):
def test_defragment_lz4(tmp_path):
pytest.importorskip("lz4")
_test_defragment(tmpdir, "lz4")
_test_defragment(tmp_path, "lz4")
14 changes: 7 additions & 7 deletions asdf/_tests/commands/tests/test_exploded.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from asdf.commands import main


def test_explode_then_implode(tmpdir):
def test_explode_then_implode(tmp_path):
x = np.arange(0, 10, dtype=float)

tree = {
Expand All @@ -18,7 +18,7 @@ def test_explode_then_implode(tmpdir):
"not_shared": np.arange(10, 0, -1, dtype=np.uint8),
}

path = os.path.join(str(tmpdir), "original.asdf")
path = os.path.join(str(tmp_path), "original.asdf")
ff = AsdfFile(tree)
# Since we're testing with small arrays, force all arrays to be stored
# in internal blocks rather than letting some of them be automatically put
Expand All @@ -31,7 +31,7 @@ def test_explode_then_implode(tmpdir):

assert result == 0

files = get_file_sizes(str(tmpdir))
files = get_file_sizes(str(tmp_path))

assert "original.asdf" in files
assert "original_exploded.asdf" in files
Expand All @@ -41,16 +41,16 @@ def test_explode_then_implode(tmpdir):

assert files["original.asdf"] > files["original_exploded.asdf"]

path = os.path.join(str(tmpdir), "original_exploded.asdf")
path = os.path.join(str(tmp_path), "original_exploded.asdf")
result = main.main_from_args(["implode", path])

assert result == 0

with asdf.open(str(tmpdir.join("original_exploded_all.asdf"))) as af:
with asdf.open(str(tmp_path / "original_exploded_all.asdf")) as af:
assert_tree_match(af.tree, tree)
assert len(af._blocks.blocks) == 2


def test_file_not_found(tmpdir):
path = os.path.join(str(tmpdir), "original.asdf")
def test_file_not_found(tmp_path):
path = os.path.join(str(tmp_path), "original.asdf")
assert main.main_from_args(["explode", path]) == 2
8 changes: 4 additions & 4 deletions asdf/_tests/commands/tests/test_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from asdf.commands import main


def test_to_yaml(tmpdir):
def test_to_yaml(tmp_path):
x = np.arange(0, 10, dtype=float)

tree = {
Expand All @@ -18,7 +18,7 @@ def test_to_yaml(tmpdir):
"not_shared": np.arange(10, 0, -1, dtype=np.uint8),
}

path = os.path.join(str(tmpdir), "original.asdf")
path = os.path.join(str(tmp_path), "original.asdf")
ff = AsdfFile(tree)
ff.write_to(path)
with asdf.open(path) as ff2:
Expand All @@ -28,11 +28,11 @@ def test_to_yaml(tmpdir):

assert result == 0

files = get_file_sizes(str(tmpdir))
files = get_file_sizes(str(tmp_path))

assert "original.asdf" in files
assert "original.yaml" in files

with asdf.open(os.path.join(str(tmpdir), "original.yaml")) as ff:
with asdf.open(os.path.join(str(tmp_path), "original.yaml")) as ff:
assert_tree_match(ff.tree, tree)
assert len(list(ff._blocks.blocks)) == 0
2 changes: 1 addition & 1 deletion asdf/_tests/core/_converters/test_external_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from asdf.testing.helpers import roundtrip_object


def test_roundtrip_external_array(tmpdir):
def test_roundtrip_external_array(tmp_path):
ref = ExternalArrayReference("./nonexistent.fits", 1, "np.float64", (100, 100))

result = roundtrip_object(ref)
Expand Down
8 changes: 4 additions & 4 deletions asdf/_tests/tags/core/tests/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
random.getrandbits(200),
],
)
def test_integer_value(tmpdir, value, sign):
def test_integer_value(tmp_path, value, sign):
if sign == "-":
value = -value

integer = IntegerType(value)
tree = {"integer": integer}
helpers.assert_roundtrip_tree(tree, tmpdir)
helpers.assert_roundtrip_tree(tree, tmp_path)


@pytest.mark.parametrize("inline", [False, True])
def test_integer_storage(tmpdir, inline):
tmpfile = str(tmpdir.join("integer.asdf"))
def test_integer_storage(tmp_path, inline):
tmpfile = str(tmp_path / "integer.asdf")

kwargs = {}
if inline:
Expand Down
Loading
Loading