Skip to content

Commit

Permalink
IO tests are only run for latest Julia version
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmandlik committed Oct 14, 2024
1 parent 89a231f commit 7e551de
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 53 deletions.
96 changes: 50 additions & 46 deletions test/hierarchical_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,54 @@ end
@test NodeIterator(n2, n2m) |> collect == collect(zip(NodeIterator(n2) |> collect, NodeIterator(n2m) |> collect))
end

@testset "printtree" begin
@test buf_printtree(n2, trav=true) ==
"""
ProductNode [""] 2 obs, 0 bytes
├── ProductNode ["E"] 2 obs, 0 bytes
│ ├─── b: BagNode ["I"] 2 obs, 176 bytes
│ │ ╰── ArrayNode(3×4 Array with Float32 elements) ["K"] 4 obs, 104 bytes
│ ╰── wb: WeightedBagNode ["M"] 2 obs, 240 bytes
│ ╰── ArrayNode(17×4 NGramMatrix with Int64 elements) ["O"] 4 obs, 154 bytes
╰── ArrayNode(10×2 SparseMatrixCSC with Float32 elements) ["U"] 2 obs, 424 bytes
"""

@test buf_printtree(n2m, trav=true) ==
"""
ProductModel ↦ Dense(20 => 10) [""] 2 arrays, 210 params, 928 bytes
├── ProductModel ↦ Dense(20 => 10) ["E"] 2 arrays, 210 params, 928 bytes
│ ├─── b: BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["I"] 4 arrays, 240 params, 1.102 KiB
│ │ ╰── ArrayModel(Dense(3 => 10)) ["K"] 2 arrays, 40 params, 248 bytes
│ ╰── wb: BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["M"] 4 arrays, 240 params, 1.102 KiB
│ ╰── ArrayModel(Dense(17 => 10)) ["O"] 2 arrays, 180 params, 808 bytes
╰── ArrayModel(Dense(10 => 10)) ["U"] 2 arrays, 110 params, 528 bytes
"""
end

@testset "LazyNode" begin
ds = LazyNode{:Codons}(ss)
m = Mill.reflectinmodel(ds)
@test nchildren(ds) == 4
@test nleafs(ds) == 4
@test nnodes(ds) == 5

@test buf_printtree(ds, trav=true) ==
"""
LazyNode{Codons}(String) [""] 4 obs, 8 bytes
├── "GGGCGGCGA" ["6"]
├── "CCTCGCGGG" ["E"]
├── "TTTTCGCTATTTATGAAAATT" ["M"]
╰── "TTCCGGTTTAAGGCGTTTCCG" ["U"]
"""

@test buf_printtree(m, trav=true) ==
"""
LazyModel{Codons} [""]
╰── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["U"] 4 arrays, 240 params, 1.102 KiB
╰── ArrayModel(Dense(64 => 10)) ["k"] 2 arrays, 650 params, 2.625 KiB
"""
@static if VERSION v"1.11.0"
@testset "printtree" begin
@test buf_printtree(n2, trav=true) ==
"""
ProductNode [""] 2 obs, 0 bytes
├── ProductNode ["E"] 2 obs, 0 bytes
│ ├─── b: BagNode ["I"] 2 obs, 176 bytes
│ │ ╰── ArrayNode(3×4 Array with Float32 elements) ["K"] 4 obs, 104 bytes
│ ╰── wb: WeightedBagNode ["M"] 2 obs, 240 bytes
│ ╰── ArrayNode(17×4 NGramMatrix with Int64 elements) ["O"] 4 obs, 154 bytes
╰── ArrayNode(10×2 SparseMatrixCSC with Float32 elements) ["U"] 2 obs, 424 bytes
"""

@test buf_printtree(n2m, trav=true) ==
"""
ProductModel ↦ Dense(20 => 10) [""] 2 arrays, 210 params, 928 bytes
├── ProductModel ↦ Dense(20 => 10) ["E"] 2 arrays, 210 params, 928 bytes
│ ├─── b: BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["I"] 4 arrays, 240 params, 1.102 KiB
│ │ ╰── ArrayModel(Dense(3 => 10)) ["K"] 2 arrays, 40 params, 248 bytes
│ ╰── wb: BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["M"] 4 arrays, 240 params, 1.102 KiB
│ ╰── ArrayModel(Dense(17 => 10)) ["O"] 2 arrays, 180 params, 808 bytes
╰── ArrayModel(Dense(10 => 10)) ["U"] 2 arrays, 110 params, 528 bytes
"""
end
end

@static if VERSION v"1.11.0"
@testset "LazyNode" begin
ds = LazyNode{:Codons}(ss)
m = Mill.reflectinmodel(ds)
@test nchildren(ds) == 4
@test nleafs(ds) == 4
@test nnodes(ds) == 5

@test buf_printtree(ds, trav=true) ==
"""
LazyNode{Codons}(String) [""] 4 obs, 8 bytes
├── "GGGCGGCGA" ["6"]
├── "CCTCGCGGG" ["E"]
├── "TTTTCGCTATTTATGAAAATT" ["M"]
╰── "TTCCGGTTTAAGGCGTTTCCG" ["U"]
"""

@test buf_printtree(m, trav=true) ==
"""
LazyModel{Codons} [""]
╰── BagModel ↦ BagCount([SegmentedMean(10); SegmentedMax(10)]) ↦ Dense(21 => 10) ["U"] 4 arrays, 240 params, 1.102 KiB
╰── ArrayModel(Dense(64 => 10)) ["k"] 2 arrays, 650 params, 2.625 KiB
"""
end
end
19 changes: 12 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,22 @@ function Mill.unpack2mill(ds::LazyNode{:Sentence})
BagNode(x, Mill.length2bags(length.(s)))
end

@testset "Doctests" begin
DocMeta.setdocmeta!(Mill, :DocTestSetup, quote
using Mill, Flux, Random, SparseArrays, Accessors, HierarchicalUtils
# do not shorten prints in doctests
ENV["LINES"] = ENV["COLUMNS"] = typemax(Int)
end; recursive=true)
doctest(Mill)
@static if VERSION v"1.11.0"
@testset "Doctests" begin
DocMeta.setdocmeta!(Mill, :DocTestSetup, quote
using Mill, Flux, Random, SparseArrays, Accessors, HierarchicalUtils
# do not shorten prints in doctests
ENV["LINES"] = ENV["COLUMNS"] = typemax(Int)
end; recursive=true)
doctest(Mill)
end
end

for test_f in readdir(".")
(endswith(test_f, ".jl") && test_f "runtests.jl") || continue
@static if VERSION < v"1.11.0"
test_f == "io.jl" && continue
end
@testset verbose = true "$test_f" begin
include(test_f)
end
Expand Down

0 comments on commit 7e551de

Please sign in to comment.