Skip to content

Commit

Permalink
don't assume standard version matches file format
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jan 31, 2024
1 parent 61d6727 commit 16c821e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ def _parse_header_line(cls, line):
msg = f"Unparsable version in ASDF file: {parts[1]}"
raise ValueError(msg) from err

if version != versioning._FILE_FORMAT_VERSION:
msg = f"Unsupported ASDF file format version {version}"
raise ValueError(msg)

return version

@classmethod
Expand Down Expand Up @@ -809,13 +813,15 @@ def _open_asdf(
msg = "Does not appear to be a ASDF file."
raise ValueError(msg) from e
self._file_format_version = cls._parse_header_line(header_line)
self.version = self.file_format_version

self._comments = cls._read_comment_section(fd)

version = cls._find_asdf_version_in_comments(self._comments)
if version is not None:
self.version = version
else:
# If no ASDF_STANDARD comment is found...
self.version = versioning.AsdfVersion("1.0.0")

# Now that version is set for good, we can add any additional
# extensions, which may have narrow ASDF Standard version
Expand Down
2 changes: 1 addition & 1 deletion asdf/_tests/test_file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_invalid_version(tmp_path):
foo : bar
..."""
buff = io.BytesIO(content)
with pytest.raises(ValueError, match=r"ASDF Standard version .* is not supported by asdf==.*"), asdf.open(buff):
with pytest.raises(ValueError, match=r"Unsupported ASDF file format version*"), asdf.open(buff):
pass


Expand Down
3 changes: 2 additions & 1 deletion asdf/_tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def check_asdf(asdf):


def test_explicit_tags():
yaml = f"""#ASDF {asdf.versioning.default_version}
yaml = """#ASDF 1.0.0
#ASDF_STANDARD 1.5.0
%YAML 1.1
--- !<tag:stsci.edu:asdf/core/asdf-1.1.0>
foo: !<tag:stsci.edu:asdf/core/ndarray-1.0.0> [1, 2, 3]
Expand Down

0 comments on commit 16c821e

Please sign in to comment.