Skip to content

Commit

Permalink
Merge pull request #1750 from braingram/update_precommit
Browse files Browse the repository at this point in the history
update pre-commit hooks
  • Loading branch information
braingram authored Feb 12, 2024
2 parents 7caee6e + 4c409f6 commit 80e4dbe
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ repos:
exclude: "asdf/(extern||_jsonschema)/.*"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.4'
rev: 'v0.2.1'
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/psf/black
rev: 23.10.1
rev: 24.1.1
hooks:
- id: black

Expand All @@ -59,6 +59,6 @@ repos:
- id: blacken-docs

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.15"
rev: "v0.16"
hooks:
- id: validate-pyproject
1 change: 1 addition & 0 deletions asdf/_block/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
operations that we generally do not want to expose to
extension code.
"""

import weakref


Expand Down
1 change: 1 addition & 0 deletions asdf/_block/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
the block manager to have a reference to the `AsdfFile`
(that references the block manager).
"""

import os
import urllib

Expand Down
1 change: 1 addition & 0 deletions asdf/_block/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Low-level functions for reading and writing ASDF blocks
and other block related file contents (like the block index).
"""

import hashlib
import io
import os
Expand Down
1 change: 1 addition & 0 deletions asdf/_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Implementation of the asdf.info(...) function. This is just a thin wrapper
around _display module code.
"""

import pathlib
from contextlib import contextmanager

Expand Down
1 change: 1 addition & 0 deletions asdf/_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
call that method expecting a dict or list to be returned. The method can
return what it thinks is suitable for display.
"""

import numpy as np

from ._node_info import create_tree
Expand Down
70 changes: 50 additions & 20 deletions asdf/_tests/tags/core/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,11 @@ def test_invalid_mask_datatype(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r".* is not valid under any of the given schemas"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r".* is not valid under any of the given schemas"),
asdf.open(
buff,
),
):
pass

Expand All @@ -655,8 +658,11 @@ def test_ndim_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Wrong number of dimensions:.*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Wrong number of dimensions:.*"),
asdf.open(
buff,
),
):
pass

Expand Down Expand Up @@ -708,8 +714,11 @@ def test_ndim_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Wrong number of dimensions:.*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Wrong number of dimensions:.*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -735,8 +744,11 @@ def test_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Can not safely cast from .* to .*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Can not safely cast from .* to .*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -759,8 +771,11 @@ def test_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Expected datatype .*, got .*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Expected datatype .*, got .*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -776,8 +791,11 @@ def test_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Expected scalar datatype .*, got .*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Expected scalar datatype .*, got .*"),
asdf.open(
buff,
),
):
pass

Expand Down Expand Up @@ -811,8 +829,11 @@ def test_structured_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Can not safely cast to expected datatype.*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Can not safely cast to expected datatype.*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -830,8 +851,11 @@ def test_structured_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Mismatch in number of columns:.*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Mismatch in number of columns:.*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -842,8 +866,11 @@ def test_structured_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Expected structured datatype.*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Expected structured datatype.*"),
asdf.open(
buff,
),
):
pass

Expand All @@ -859,8 +886,11 @@ def test_structured_datatype_validation(tmpdir):
"""
buff = helpers.yaml_to_asdf(content)

with pytest.raises(ValidationError, match=r"Expected datatype .*, got .*"), asdf.open(
buff,
with (
pytest.raises(ValidationError, match=r"Expected datatype .*, got .*"),
asdf.open(
buff,
),
):
pass

Expand Down
9 changes: 6 additions & 3 deletions asdf/_tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ def test_update_exceptions(tmp_path):
ff = asdf.AsdfFile(tree)
ff.write_to(path)

with asdf.open(path, mode="r", copy_arrays=True) as ff, pytest.raises(
IOError,
match=r"Can not update, since associated file is read-only.*",
with (
asdf.open(path, mode="r", copy_arrays=True) as ff,
pytest.raises(
IOError,
match=r"Can not update, since associated file is read-only.*",
),
):
ff.update()

Expand Down
11 changes: 7 additions & 4 deletions asdf/_tests/test_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,13 @@ def test_unclosed_file(tmp_path):
path = tmp_path / "empty.asdf"
path.touch()

with pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
), open_asdf(path):
with (
pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
),
open_asdf(path),
):
pass


Expand Down
17 changes: 10 additions & 7 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ def test_asdf_util_is_primitive_deprecation():

def test_AsdfFile_tree_assignment_validation_deprecation():
af = asdf.AsdfFile()
with pytest.warns(AsdfDeprecationWarning, match="Validation on tree assignment is deprecated"), pytest.raises(
ValidationError
with (
pytest.warns(AsdfDeprecationWarning, match="Validation on tree assignment is deprecated"),
pytest.raises(ValidationError),
):
af.tree = {"history": 42}


def test_AsdfFile_resolve_references_validation_deprecation():
af = asdf.AsdfFile()
af._tree["history"] = 42
with pytest.warns(
AsdfDeprecationWarning, match="Validation during resolve_references is deprecated"
), pytest.raises(ValidationError):
with (
pytest.warns(AsdfDeprecationWarning, match="Validation during resolve_references is deprecated"),
pytest.raises(ValidationError),
):
af.resolve_references()


Expand All @@ -110,7 +112,8 @@ def test_AsdfFile_resolve_references_kwargs_deprecation():


def test_AsdfFile_init_validation_deprecation():
with pytest.warns(AsdfDeprecationWarning, match="Validation during AsdfFile.__init__ is deprecated"), pytest.raises(
ValidationError
with (
pytest.warns(AsdfDeprecationWarning, match="Validation during AsdfFile.__init__ is deprecated"),
pytest.raises(ValidationError),
):
asdf.AsdfFile({"history": 42})
31 changes: 20 additions & 11 deletions asdf/_tests/test_file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ def test_no_asdf_header(tmp_path):
with open(path, "wb") as fd:
fd.write(content)

with open(path, "rb") as fd, pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
with (
open(path, "rb") as fd,
pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
),
):
asdf.open(fd)

Expand All @@ -102,19 +105,25 @@ def test_not_asdf_file():
buff = io.BytesIO(b"SIMPLE")
buff.seek(0)

with pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
), asdf.open(buff):
with (
pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
),
asdf.open(buff),
):
pass

buff = io.BytesIO(b"SIMPLE\n")
buff.seek(0)

with pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
), asdf.open(buff):
with (
pytest.raises(
ValueError,
match=r"Does not appear to be a ASDF file.",
),
asdf.open(buff),
):
pass


Expand Down
30 changes: 20 additions & 10 deletions asdf/_tests/test_generic_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ def test_open_not_binary_fail(tmp_path, mode):
fd.write("\n\n\n")

file_mode = mode if mode != "rw" else "r+"
with open(path, file_mode) as fd, pytest.raises(
ValueError,
match=r"File-like object must be opened in binary mode.",
with (
open(path, file_mode) as fd,
pytest.raises(
ValueError,
match=r"File-like object must be opened in binary mode.",
),
):
generic_io.get_file(fd, mode=mode)

Expand Down Expand Up @@ -358,10 +361,14 @@ def test_unicode_open(tmp_path, small_tree):

ff.write_to(path)

with open(path, encoding="utf-8") as fd, pytest.raises(
ValueError,
match=r"File-like object must be opened in binary mode.",
), asdf.open(fd):
with (
open(path, encoding="utf-8") as fd,
pytest.raises(
ValueError,
match=r"File-like object must be opened in binary mode.",
),
asdf.open(fd),
):
pass


Expand All @@ -376,9 +383,12 @@ def test_invalid_obj(tmp_path):
generic_io.get_file(42)

path = os.path.join(str(tmp_path), "test.asdf")
with generic_io.get_file(path, "w") as fd, pytest.raises(
ValueError,
match=r"File is opened as 'w', but 'r' was requested",
with (
generic_io.get_file(path, "w") as fd,
pytest.raises(
ValueError,
match=r"File is opened as 'w', but 'r' was requested",
),
):
generic_io.get_file(fd, "r")

Expand Down
Loading

0 comments on commit 80e4dbe

Please sign in to comment.