Skip to content

Commit

Permalink
Add simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Dec 4, 2024
1 parent 5ebcc64 commit c9aeb28
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 23 deletions.
39 changes: 39 additions & 0 deletions test/test_dataprod_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,44 @@
using LegendDataManagement
using Test

using TypedTables
using Unitful

@testset "dataprod_config" begin
l200 = LegendData(:l200)

@testset "runinfo" begin
rinfo = runinfo(l200, (DataPeriod(2), DataRun(6), :cal))
@test rinfo isa TypedTables.Table
@test length(rinfo) == 1
@test only(rinfo).startkey.period == DataPeriod(2)
@test only(rinfo).startkey.run == DataRun(6)
@test only(rinfo).startkey.category == DataCategory(:cal)
@test_nowarn empty!(LegendDataManagement._cached_runinfo)
end

@testset "analysis_runs" begin
analysisruns = analysis_runs(l200)
@test analysisruns isa TypedTables.Table
@test hasproperty(analysisruns, :period)
@test hasproperty(analysisruns, :run)
@test_nowarn empty!(LegendDataManagement._cached_analysis_runs)
end

@testset "partitioninfo" begin
partinfo = partitioninfo(l200, :V99000A)
@test partinfo isa IdDict
@test_nowarn empty!(LegendDataManagement._cached_partitioninfo)
end

@testset "utils" begin
sel = (DataPeriod(2), DataRun(6), :phy)
@test start_filekey(l200, sel) isa FileKey
@test livetime(l200, sel) isa Unitful.Time

rsel = (DataPeriod(2), DataRun(6))
@test LegendDataManagement.is_analysis_cal_run(l200, rsel)
@test LegendDataManagement.is_analysis_phy_run(l200, rsel)
@test LegendDataManagement.is_analysis_run(l200, sel)
end
end
6 changes: 6 additions & 0 deletions test/test_filekey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using LegendDataManagement
using Test

using Dates
using Unitful

@testset "filekey" begin
setup = ExpSetup(:l200)
Expand All @@ -29,6 +30,11 @@ using Dates
timestamp = @inferred(Timestamp("20221226T200846Z"))
@test timestamp.unixtime == 1672085326
@test @inferred(string(timestamp)) == "20221226T200846Z"

unix_timestamp = 1672085326u"s"
timestamp2 = @inferred(Timestamp(unix_timestamp))
@test timestamp2.unixtime == 1672085326
@test @inferred(string(timestamp2)) == "20221226T200846Z"

key = @inferred FileKey("l200-p02-r006-cal-20221226T200846Z")
@test string(key) == "l200-p02-r006-cal-20221226T200846Z"
Expand Down
54 changes: 31 additions & 23 deletions test/test_legend_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,35 @@ include("testing_utils.jl")
props_base_path = data_path(LegendDataConfig().setups.l200, "metadata")
@test l200.metadata isa LegendDataManagement.PropsDB

# ToDo: Make type-stable:
@test channelinfo(l200, filekey) isa TypedTables.Table
chinfo = channelinfo(l200, filekey)
@test all(filterby(@pf $processable && $usability == :on)(chinfo).processable)
@test all(filterby(@pf $processable && $usability == :on)(chinfo).usability .== :on)

# Delete the channelinfo cache
empty!(LegendDataManagement._cached_channelinfo)

# Test the extended channel info with active volume calculation
extended = channelinfo(l200, filekey, extended = true)
@test extended isa TypedTables.Table

# Check that some keywords only appear in the extended channelinfo
extended_keywords = (:cc4, :cc4ch, :daqcrate, :daqcard, :hvcard, :hvch, :enrichment, :mass, :total_volume, :active_volume)
@test !any(in(columnnames(chinfo)), extended_keywords)
@test all(in(columnnames(extended)), extended_keywords)

# ToDo: Make type-stable:
# @test #=@inferred=#(channel_info(l200, filekey)) isa StructArray
# chinfo = channel_info(l200, filekey)
# @test all(filterby(@pf $processable && $usability == :on)(chinfo).processable)
# @test all(filterby(@pf $processable && $usability == :on)(chinfo).usability .== :on)
@testset "channelinfo" begin
# ToDo: Make type-stable:
@test channelinfo(l200, filekey) isa TypedTables.Table
chinfo = channelinfo(l200, filekey)
@test all(filterby(@pf $processable && $usability == :on)(chinfo).processable)
@test all(filterby(@pf $processable && $usability == :on)(chinfo).usability .== :on)

# Delete the channelinfo cache
empty!(LegendDataManagement._cached_channelinfo)

# Test the extended channel info with active volume calculation
extended = channelinfo(l200, filekey, only_usability = :on, extended = true)
@test extended isa TypedTables.Table

# Check that some keywords only appear in the extended channelinfo
extended_keywords = (:cc4, :cc4ch, :daqcrate, :daqcard, :hvcard, :hvch, :enrichment, :mass, :total_volume, :active_volume)
@test !any(in(columnnames(chinfo)), extended_keywords)
@test all(in(columnnames(extended)), extended_keywords)

# ToDo: Make type-stable:
# @test #=@inferred=#(channel_info(l200, filekey)) isa StructArray
# chinfo = channel_info(l200, filekey)
# @test all(filterby(@pf $processable && $usability == :on)(chinfo).processable)
# @test all(filterby(@pf $processable && $usability == :on)(chinfo).usability .== :on)
end

@testset "search_disk" begin
datasets = search_disk(DataSet, l200)
# LegendTestData is probably not in the correct formats
@test_broken !(isempty(datasets))
end
end

0 comments on commit c9aeb28

Please sign in to comment.