using Test using PSBoardDataBase using CSV, DataFrames using SQLite, DBInterface using Dates true || include("../src/PSBoardDataBase.jl") @testset "PSBoardDataBase" begin @testset "parse master log" begin masterlog_metadata::PSBoardDataBase.QaqcMasterLog.QaqcMasterLogMetadata = PSBoardDataBase.QaqcMasterLog.parse_master_log("input/log/57_long.log") @test masterlog_metadata.shifters == "Otsubo" @test masterlog_metadata.timestamp == DateTime(2024, 07, 26, 10, 33, 05) @test masterlog_metadata.runid == 57 @test masterlog_metadata.shiftscript_version == v"1.0.2" end @testset "Download data csv" begin out = tempname() @test CSV.read( PSBoardDataBase.DownloadCSVs.download_single_run_csv(out), DataFrame, ) isa DataFrame @test CSV.read( PSBoardDataBase.DownloadCSVs.download_runlist_csv(out), DataFrame, ) isa DataFrame @test CSV.read( PSBoardDataBase.DownloadCSVs.download_dispatch_csv(out), DataFrame, ) isa DataFrame @test CSV.read( PSBoardDataBase.DownloadCSVs.download_hundred_run_csv(out), DataFrame, ) isa DataFrame @test CSV.read(PSBoardDataBase.DownloadCSVs.download_jathub_csv(out), DataFrame) isa DataFrame end @testset "prepare dataframe" begin single_result_df = CSV.read(PSBoardDataBase.DownloadCSVs.download_single_run_csv(), DataFrame) @test PSBoardDataBase.prepare_single_result_df(single_result_df) isa DataFrame @test PSBoardDataBase.prepare_dispatch_table( CSV.read(PSBoardDataBase.DownloadCSVs.download_dispatch_csv(), DataFrame), ) isa DataFrame @test PSBoardDataBase.prepare_100test_table( CSV.read(PSBoardDataBase.DownloadCSVs.download_hundred_run_csv(), DataFrame), ) isa DataFrame end @testset "full integrated test" begin dbpath = tempname() db = PSBoardDataBase.create_database(dbpath) @info "" db @test PSBoardDataBase.insert_version_info(db) |> isnothing let stmt stmt = DBInterface.prepare( db, sql""" SELECT * FROM versions """, ) result = DBInterface.execute(stmt) |> DataFrame @test nrow(result) |> ==(1) end @test PSBoardDataBase.insert_qaqc_campaign_id(db) |> isnothing jathub_list_df = CSV.read(PSBoardDataBase.DownloadCSVs.download_jathub_csv(), DataFrame) @test PSBoardDataBase.insert_qaqc_positions(db, jathub_list_df) |> isnothing single_result_df = CSV.read(PSBoardDataBase.DownloadCSVs.download_single_run_csv(), DataFrame) runlist_table = CSV.read(PSBoardDataBase.DownloadCSVs.download_runlist_csv(), DataFrame) @test PSBoardDataBase.add_psboard_ids(db, single_result_df) |> isnothing @test PSBoardDataBase.add_qaqc_runlist_from_runlist(db, runlist_table) |> isnothing @test PSBoardDataBase.add_qaqc_single_result(db, single_result_df, runlist_table) |> isnothing dispatch_table = CSV.read(PSBoardDataBase.DownloadCSVs.download_dispatch_csv(), DataFrame) @test PSBoardDataBase.add_qaqc_dispatch(db, dispatch_table) |> isnothing if haskey(ENV, "LOCAL_TEST") @test PSBoardDataBase.add_qaqc_runlist_from_masterlogs(db, "input/log/") |> isnothing extra_100test_result_df = CSV.read(PSBoardDataBase.DownloadCSVs.download_hundred_run_csv(), DataFrame) @test PSBoardDataBase.add_qaqc_100test_result(db, extra_100test_result_df) |> isnothing run(`sqlitebrowser $dbpath`) end end end