-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest-convenience.jl
41 lines (37 loc) · 1.57 KB
/
test-convenience.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using CSV: CSV
using DataFrames: DataFrames, DataFrame
using DuckDB: DuckDB, DBInterface
using TulipaIO: TulipaIO
@testset "Test convenience functions" begin
@testset "Read CSV folder" begin
tmpdir = mktempdir()
CSV.write(
joinpath(tmpdir, "some-file.csv"),
DataFrame(:a => ["A", "B", "C"], :x => rand(3)),
)
open(joinpath(tmpdir, "ignore-this-file.txt"), "w") do io
println(io, "Nothing")
end
connection = DBInterface.connect(DuckDB.DB)
TulipaIO.read_csv_folder(connection, tmpdir)
@test (DBInterface.execute(connection, "SHOW TABLES") |> DataFrame |> df -> df.name) ==
["some_file"]
end
@testset "Test reading w/ schema" begin
con = DBInterface.connect(DuckDB.DB)
schemas = Dict(
"rep_periods_mapping" =>
Dict(:period => "INT", :rep_period => "VARCHAR", :weight => "DOUBLE"),
)
TulipaIO.read_csv_folder(con, "data/Norse"; schemas)
df_types = DuckDB.query(con, "DESCRIBE rep_periods_mapping") |> DataFrame
@test df_types.column_name == ["period", "rep_period", "weight"]
@test df_types.column_type == ["INTEGER", "VARCHAR", "DOUBLE"]
end
@testset "Test show_tables and get_table" begin
connection = DBInterface.connect(DuckDB.DB)
TulipaIO.create_tbl(connection, "data/Norse/assets-data.csv"; name = "my_table")
@test TulipaIO.show_tables(connection).name == ["my_table"]
@test "Asgard_Battery" in TulipaIO.get_table(connection, "my_table").name
end
end