Skip to content

Commit

Permalink
test-pipeline.jl: tests for set_tbl_col
Browse files Browse the repository at this point in the history
suvayu committed Apr 18, 2024
1 parent 41eb16a commit 7b66be4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/test-pipeline.jl
Original file line number Diff line number Diff line change
@@ -186,17 +186,17 @@ end

con = DBInterface.connect(DB)

opts = Dict(:on => :name, :col => :investable, :show => true)
opts = Dict(:on => :name, :show => true)
@testset "w/ vector" begin
df_exp = DF.DataFrame(CSV.File(csv_copy; header = 2))
df_res = TIO.set_tbl_col(con, csv_path, df_exp.investable; opts...)
df_res = TIO.set_tbl_col(con, csv_path, Dict(:investable => df_exp.investable); opts...)
# NOTE: row order is different, join to determine equality
cmp = join_cmp(df_exp, df_res, ["name", "investable"]; on = :name)
investable = cmp[!, [c for c in propertynames(cmp) if occursin("investable", String(c))]]
@test isequal.(investable[!, 1], investable[!, 2]) |> all

# stupid Julia! grow up!
args = [con, csv_path, df_exp.investable[2:end]]
args = [con, csv_path, Dict(:investable => df_exp.investable[2:end])]
@test_throws DimensionMismatch TIO.set_tbl_col(args...; opts...)
if (VERSION.major >= 1) && (VERSION.minor >= 8)
@test_throws r"Length.+different" TIO.set_tbl_col(args...; opts...)
@@ -205,7 +205,15 @@ end
end

@testset "w/ constant" begin
df_res = TIO.set_tbl_col(con, csv_path, true; opts...)
df_res = TIO.set_tbl_col(con, csv_path, Dict(:investable => true); opts...)
@test df_res.investable |> all
end

@testset "w/ constant after filtering" begin
where_clause = TIO.FmtSQL.@where_(lifetime in 25:50, name % "Valhalla_%")
df_res = TIO.set_tbl_col(con, csv_path, Dict(:investable => true); opts..., where_ = where_clause)
@test shape(df_res) == shape(df_org)
df_res = filter(row -> 25 <= row.lifetime <= 50 && startswith(row.name, "Valhalla_"), df_res)
@test df_res.investable |> all
end
end

0 comments on commit 7b66be4

Please sign in to comment.