Skip to content
Open
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
291 changes: 273 additions & 18 deletions src/ASDF.jl

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions test/data/asdf-1.6.0/anchor.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.6.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 4.1.0}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/core/extensions/core-1.6.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.1.1}
software: !core/software-1.0.0 {name: asdf, version: 4.1.0}
a: &id001 {abc: 123}
b: *id001
...
37 changes: 37 additions & 0 deletions test/data/asdf-1.6.0/anchor_roundtrip.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.2.0
# This is an ASDF file <https://asdf-standard.readthedocs.io/>
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
---
!core/asdf-1.1.0
asdf_library:
author: "The ASDF Developers"
homepage: "http://github.com/asdf-format/asdf"
name: "asdf"
version: "4.1.0"
history:
extensions:
- extension_class: "asdf.extension._manifest.ManifestExtension"
extension_uri: "asdf://asdf-format.org/core/extensions/core-1.6.0"
manifest_software:
name: "asdf_standard"
version: "1.1.1"
software:
name: "asdf"
version: "4.1.0"
a:
abc: 123
b:
abc: 123
asdf/library: !core/software-1.0.0
name: "ASDF.jl"
author: "Erik Schnetter <schnetter@gmail.com>"
homepage: "https://github.com/JuliaAstro/ASDF.jl"
version: "2.0.0"
...
#ASDF BLOCK INDEX
%YAML 1.1
---
[]
...
Binary file added test/data/asdf-1.6.0/ascii.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/ascii_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/basic.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/basic_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/complex.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/complex_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/compressed.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/compressed_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/endian.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/endian_roundtrip.asdf
Binary file not shown.
20 changes: 20 additions & 0 deletions test/data/asdf-1.6.0/exploded.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.6.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 4.1.0}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/core/extensions/core-1.6.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.1.1}
software: !core/software-1.0.0 {name: asdf, version: 4.1.0}
data: !core/ndarray-1.1.0
source: exploded0000.asdf
datatype: int64
byteorder: little
shape: [8]
...
Binary file added test/data/asdf-1.6.0/exploded0000.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/float.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/float_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/int.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/int_roundtrip.asdf
Binary file not shown.
18 changes: 18 additions & 0 deletions test/data/asdf-1.6.0/scalars.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.6.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 4.1.0}
history:
extensions:
- !core/extension_metadata-1.0.0
extension_class: asdf.extension._manifest.ManifestExtension
extension_uri: asdf://asdf-format.org/core/extensions/core-1.6.0
manifest_software: !core/software-1.0.0 {name: asdf_standard, version: 1.1.1}
software: !core/software-1.0.0 {name: asdf, version: 4.1.0}
float: 3.14
int: 42
string: foo
...
36 changes: 36 additions & 0 deletions test/data/asdf-1.6.0/scalars_roundtrip.asdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ASDF 1.0.0
#ASDF_STANDARD 1.2.0
# This is an ASDF file <https://asdf-standard.readthedocs.io/>
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
---
!core/asdf-1.1.0
asdf_library:
author: "The ASDF Developers"
homepage: "http://github.com/asdf-format/asdf"
name: "asdf"
version: "4.1.0"
history:
extensions:
- extension_class: "asdf.extension._manifest.ManifestExtension"
extension_uri: "asdf://asdf-format.org/core/extensions/core-1.6.0"
manifest_software:
name: "asdf_standard"
version: "1.1.1"
software:
name: "asdf"
version: "4.1.0"
float: 3.14
int: 42
string: "foo"
asdf/library: !core/software-1.0.0
name: "ASDF.jl"
author: "Erik Schnetter <schnetter@gmail.com>"
homepage: "https://github.com/JuliaAstro/ASDF.jl"
version: "2.0.0"
...
#ASDF BLOCK INDEX
%YAML 1.1
---
[]
...
Binary file added test/data/asdf-1.6.0/shared.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/shared_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/stream.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/structured.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/structured_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/unicode_bmp.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/unicode_bmp_roundtrip.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/unicode_spp.asdf
Binary file not shown.
Binary file added test/data/asdf-1.6.0/unicode_spp_roundtrip.asdf
Binary file not shown.
File renamed without changes.
9 changes: 9 additions & 0 deletions test/test-ndarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ end
"`strides` must have only positive elements.";
strides = Int64[0],
)
test_ndarray(
ArgumentError,
"Unknown string datatype kind: utf16";
datatype = ["utf16", 8],
)
end

@testset "getindex" begin
Expand All @@ -93,8 +98,12 @@ end
disk_bytes = collect(reinterpret(UInt8, bswap.(expected)))
lbh = ASDF.LazyBlockHeaders()
push!(lbh.block_headers, make_block_header(disk_bytes))

nd = make_ndarray(; lazy_block_headers = lbh, source = Int64(0), data = nothing, byteorder = opposite)
@test nd[] == expected

nd = make_ndarray(; lazy_block_headers = lbh, source = Int64(0), data = nothing, byteorder = opposite, datatype = ASDF.Ucs4Datatype(2), shape = [Int64(1)], strides = [Int64(8)])
@test nd[] == [(UInt32(0x00000001), UInt32(0x00000002))]
end

nd = make_ndarray(; strides = Int64[5])
Expand Down
2 changes: 1 addition & 1 deletion test/test-read.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "Read ASDF file" begin
asdf = load("blue_upchan_gain.00000000.asdf")
asdf = load(joinpath("data", "blue_upchan_gain.00000000.asdf"))
println(YAML.write(asdf.metadata))

map_tree(output, asdf.metadata)
Expand Down
2 changes: 1 addition & 1 deletion test/test-read_chunked.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "Read ASDF file with chunked arrays" begin
asdf = load("chunking.asdf")
asdf = load(joinpath("data", "chunking.asdf"))
println(YAML.write(asdf.metadata))

map_tree(output, asdf.metadata)
Expand Down
53 changes: 53 additions & 0 deletions test/test-reference.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
compare(field1::ASDF.NDArray, field2::ASDF.NDArray) = isequal(field1[], field2[])
compare(field1, field2) = isequal(field1, field2)

function test_fields(af1, af2)
for ((k1, v1), (k2, v2)) in zip(af1.metadata, af2.metadata)
if occursin("asdf", k1)
# Skip non-data entries
else
@test compare(v1, v2)
end
end
end

function roundtrip(fpath; extensions = false, validate_checksum = true)
af = ASDF.load_file(fpath; extensions, validate_checksum)
fpath_roundtrip = replace(fpath, ".asdf" => "_roundtrip.asdf")
ASDF.write_file(fpath_roundtrip, af.metadata)
af_roundtrip = ASDF.load_file(fpath_roundtrip; extensions, validate_checksum)
return af_roundtrip, af
end

function test_references(references)
for reference in references
@testset "$(reference)" begin
af_roundtrip, af = if reference == "compressed"
# Bug on Python side, see 03 Apr ASDF office hour discussion
roundtrip(joinpath("data", "asdf-1.6.0", reference * ".asdf"); validate_checksum = false)
else
roundtrip(joinpath("data", "asdf-1.6.0", reference * ".asdf"))
end
test_fields(af_roundtrip, af)
end
end
end

references = [
"anchor",
"ascii",
"basic",
"complex",
"compressed",
"endian",
#"exploded", See https://github.com/JuliaAstro/ASDF.jl/issues/31
"float",
"int",
"scalars",
"shared",
#"stream", See https://github.com/JuliaAstro/ASDF.jl/issues/31
"structured",
"unicode_bmp",
"unicode_spp",
]
test_references(references)
2 changes: 1 addition & 1 deletion test/test-show.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "Show method for `ASDF.ASDFFile`" begin
af = load("blue_upchan_gain.00000000.asdf")
af = load(joinpath("data", "blue_upchan_gain.00000000.asdf"))

@test occursin("blue_upchan_gain.00000000.asdf\n├─", sprint(show, MIME"text/plain"(), af))

Expand Down
Loading