Skip to content

Commit

Permalink
refactor: Remove testing.loadMem (#4857)
Browse files Browse the repository at this point in the history
* refactor: Remove testing.loadMem

I have not found anyone overriding this and I am not sure what such an override would do as `csv.from`
already loads from memory. So I think we can just remove this entirely

* chore: Don't use testing.loadMem in doc tests
  • Loading branch information
Markus Westerlind authored Jun 9, 2022
1 parent 9501c99 commit 1785418
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 86 deletions.
34 changes: 17 additions & 17 deletions libflux/go/libflux/buildinfo.gen.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion semantic/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ my_value
name: "option statement for subpackage",
s: `import c "csv"
import "testing"
option testing.loadMem = (csv) => c.from(csv: csv)
option testing.load = (tables) => tables
`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion stdlib/contrib/bonitoo-io/tickscript/alert_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tickscript_alert = (table=<-) =>
|> drop(columns: ["_time"])

testcase tickscript_alert {
want = testing.loadMem(csv: outData)
want = csv.from(csv: outData)
got = csv.from(csv: inData) |> testing.load() |> tickscript_alert()

testing.diff(want: want, got: got) |> yield()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tickscript_alert = (table=<-) =>
|> drop(columns: ["_time"])

testcase tickscript_alert_with_topic {
want = testing.loadMem(csv: outData)
want = csv.from(csv: outData)
got = csv.from(csv: inData) |> testing.load() |> tickscript_alert()

testing.diff(want: want, got: got) |> yield()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tickscript_deadman = (table=<-) =>
|> drop(columns: ["_time"])

testcase tickscript_deadman_threshold {
want = testing.loadMem(csv: outData)
want = csv.from(csv: outData)
got = csv.from(csv: inData) |> testing.load() |> tickscript_deadman()

testing.diff(want: want, got: got) |> yield()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/experimental/oee/apq_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ outData =

testcase APQ {
got =
testing.loadMem(csv: inData)
csv.from(csv: inData)
|> range(start: 2021-03-22T00:00:00Z, stop: 2021-03-22T04:00:00Z)
|> oee.APQ(runningState: "running", plannedTime: 8h, idealCycleTime: 30s)
|> drop(columns: ["_start", "_stop"])
Expand Down
6 changes: 3 additions & 3 deletions stdlib/experimental/oee/computeapq_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ outData =
,,0,2021-03-22T04:00:00Z,0.375,0.24583333333333332,0.6666666666666666,0.9833333333333333,10800000000000
"
productionEvents =
testing.loadMem(csv: productionData)
csv.from(csv: productionData)
|> range(start: 2021-03-22T00:00:00Z, stop: 2021-03-22T04:00:00Z)
partEvents =
testing.loadMem(csv: partData)
csv.from(csv: partData)
|> range(start: 2021-03-22T00:00:00Z, stop: 2021-03-22T04:00:00Z)

testcase computeAPQ {
table = testing.loadMem(csv: inData)
table = csv.from(csv: inData)
got =
oee.computeAPQ(
productionEvents: productionEvents,
Expand Down
7 changes: 4 additions & 3 deletions stdlib/experimental/table/fill_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package table_test


import "array"
import "csv"
import "planner"
import "testing"
import "testing/expect"
Expand Down Expand Up @@ -104,7 +105,7 @@ loadData = () =>

testcase window {
want =
testing.loadMem(
csv.from(
csv:
"
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double,string
Expand Down Expand Up @@ -237,7 +238,7 @@ test_idempotent =
() =>
{
want =
testing.loadMem(
csv.from(
csv:
"
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double,string
Expand Down Expand Up @@ -282,7 +283,7 @@ testcase idempotent_planner_rule {

testcase fill_unknown_column {
want =
testing.loadMem(
csv.from(
csv:
"
#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double,string
Expand Down
4 changes: 2 additions & 2 deletions stdlib/internal/debug/debug_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ input = () =>

testcase slurp {
got = input() |> debug.slurp()
want = testing.loadMem(csv: inData)
want = csv.from(csv: inData)

testing.diff(got, want) |> yield()
}
testcase sink {
got = input() |> debug.sink()
want = testing.loadMem(csv: inData) |> filter(fn: (r) => false)
want = csv.from(csv: inData) |> filter(fn: (r) => false)

testing.diff(got, want) |> yield()
}
Expand Down
12 changes: 6 additions & 6 deletions stdlib/planner/group_max_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ testcase group_max_bare {
,,0,2018-05-22T19:53:26Z,system,host.local,load4,1.77
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_bare)) |> yield()
}

input_host =
Expand Down Expand Up @@ -79,7 +79,7 @@ testcase group_max_bare_host {
,,2,2018-05-22T19:53:36Z,system,host.local,load4,1.78
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_bare)) |> yield()
}

input_field =
Expand Down Expand Up @@ -131,7 +131,7 @@ testcase group_max_bare_field {
,,2,2018-05-22T19:00:00Z,2018-05-24T00:00:00Z,hostC,load5,1.95
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_bare)) |> yield()
}
testcase group_max_window {
result =
Expand All @@ -151,7 +151,7 @@ testcase group_max_window {
,,0,2018-05-22T19:53:26Z,2018-05-23T00:00:00Z,2018-05-22T19:53:26Z,system,host.local,load4,1.77
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_window)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_window)) |> yield()
}
testcase group_max_agg_window {
result =
Expand All @@ -169,7 +169,7 @@ testcase group_max_agg_window {
,,0,2018-05-22T19:53:26Z,2018-05-24T00:00:00Z,2018-05-23T00:00:00Z,system,host.local,load1,1.83
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_agg_window)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_agg_window)) |> yield()
}
testcase group_max_agg_window_empty {
result =
Expand All @@ -193,5 +193,5 @@ testcase group_max_agg_window_empty {
,,2,2018-05-22T19:53:26Z,2018-05-24T00:00:00Z,2018-05-24T00:00:00Z,load4,
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_agg_window_empty)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_agg_window_empty)) |> yield()
}
6 changes: 3 additions & 3 deletions stdlib/planner/group_min_max_table_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ testcase group_min_table {
,,2,2019-11-25T00:00:00Z,m0,f0,a-2,b-0,1.0
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_table)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_table)) |> yield()
}
testcase group_max_table {
result =
Expand All @@ -130,7 +130,7 @@ testcase group_max_table {
,,2,2019-11-25T00:00:30Z,m0,f0,a-2,b-1,8.0
"

testing.diff(got: result, want: testing.loadMem(csv: out_max_table)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_max_table)) |> yield()
}
testcase group_no_agg_table {
result =
Expand Down Expand Up @@ -220,5 +220,5 @@ testcase group_no_agg_table {
,,2,2019-11-25T00:01:50Z,m0,f0,a-2,b-1,8.0
"

testing.diff(got: result, want: testing.loadMem(csv: out_no_agg_table)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_no_agg_table)) |> yield()
}
12 changes: 6 additions & 6 deletions stdlib/planner/group_min_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ testcase group_min_bare {
,,0,2018-05-22T19:53:26Z,system,host.local,load4,1.77
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_bare)) |> yield()
}

input_host =
Expand Down Expand Up @@ -78,7 +78,7 @@ testcase group_min_bare_host {
,,2,2018-05-22T19:53:26Z,system,host.local,load4,1.77
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_bare)) |> yield()
}

input_field =
Expand Down Expand Up @@ -130,7 +130,7 @@ testcase group_min_bare_field {
,,2,2018-05-22T19:00:00Z,2018-05-24T00:00:00Z,hostC,load1,1.89
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_bare)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_bare)) |> yield()
}
testcase group_min_window {
result =
Expand All @@ -150,7 +150,7 @@ testcase group_min_window {
,,0,2018-05-22T19:53:26Z,2018-05-23T00:00:00Z,2018-05-22T19:53:26Z,system,host.local,load4,1.77
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_window)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_window)) |> yield()
}
testcase group_min_agg_window {
result =
Expand All @@ -168,7 +168,7 @@ testcase group_min_agg_window {
,,0,2018-05-22T19:53:26Z,2018-05-24T00:00:00Z,2018-05-23T00:00:00Z,system,host.local,load1,1.63
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_agg_window)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_agg_window)) |> yield()
}
testcase group_min_agg_window_empty {
result =
Expand All @@ -192,5 +192,5 @@ testcase group_min_agg_window_empty {
,,2,2018-05-22T19:53:26Z,2018-05-24T00:00:00Z,2018-05-24T00:00:00Z,load4,
"

testing.diff(got: result, want: testing.loadMem(csv: out_min_agg_window_empty)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_min_agg_window_empty)) |> yield()
}
39 changes: 5 additions & 34 deletions stdlib/testing/testing.flux
Original file line number Diff line number Diff line change
Expand Up @@ -230,37 +230,6 @@ option loadStorage = (csv) =>
//
option load = (tables=<-) => tables

// loadMem loads annotated CSV test data from memory to emulate query results
// returned by Flux.
//
// ## Parameters
// - csv: Annotated CSV data to load.
//
// ## Examples
//
// ### Load annotated CSV as if returned by Flux
// ```
// import "testing"
//
// csvData =
// "
// #datatype,string,long,string,dateTime:RFC3339,string,double
// #group,false,false,true,false,true,false
// #default,_result,,,,,
// ,result,table,_measurement,_time,_field,_value
// ,,0,m,2021-01-01T00:00:00Z,t,1.2
// ,,0,m,2021-01-02T00:00:00Z,t,1.4
// ,,0,m,2021-01-03T00:00:00Z,t,2.2
// "
//
// testing.loadMem(csv: csvData)
// ```
//
// ## Metadata
// introduced: 0.20.0
//
option loadMem = (csv) => c.from(csv: csv)

// inspect returns information about a test case.
//
// ## Parameters
Expand Down Expand Up @@ -297,7 +266,7 @@ option loadMem = (csv) => c.from(csv: csv)
// |> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-03T01:00:00Z)
// |> sum()
//
// test _sum = () => ({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_sum})
// test _sum = () => ({input: csv.from(csv: inData), want: csv.from(csv: outData), fn: t_sum})
//
// testing.inpsect(case: _sum)
//
Expand Down Expand Up @@ -336,6 +305,7 @@ inspect = (case) => {
//
// ### Define and execute a test case
// ```
// import "csv"
// import "testing"
//
// inData =
Expand Down Expand Up @@ -363,7 +333,7 @@ inspect = (case) => {
// |> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-03T01:00:00Z)
// |> sum()
//
// test _sum = () => ({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_sum})
// test _sum = () => ({input: csv.from(csv: inData), want: csv.from(csv: outData), fn: t_sum})
//
// testing.run(case: _sum)
// ```
Expand All @@ -389,6 +359,7 @@ run = (case) => {
// profilers to measure query performance.
//
// ```
// import "csv"
// import "testing"
// import "profiler"
//
Expand Down Expand Up @@ -419,7 +390,7 @@ run = (case) => {
// |> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-03T01:00:00Z)
// |> sum()
//
// test _sum = () => ({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_sum})
// test _sum = () => ({input: csv.from(csv: inData), want: csv.from(csv: outData), fn: t_sum})
//
// testing.benchmark(case: _sum)
// ```
Expand Down
2 changes: 1 addition & 1 deletion stdlib/universe/join_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ testcase join_base {
|> testing.load()
|> range(start: 2018-05-22T19:53:00Z, stop: 2018-05-22T19:55:00Z)
|> drop(columns: ["_start", "_stop"])
want = testing.loadMem(csv: outData)
want = csv.from(csv: outData)
left =
input
|> filter(fn: (r) => r.user == "user1")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/universe/limit_offset_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ input = () =>

testcase limit_offset {
want = input()
got = testing.loadMem(csv: outData)
got = csv.from(csv: outData)

testing.diff(want: want, got: got) |> yield()
}
2 changes: 1 addition & 1 deletion stdlib/universe/limit_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ input = () =>

testcase limit_1 {
want = input()
got = testing.loadMem(csv: outData)
got = csv.from(csv: outData)

testing.diff(want: want, got: got) |> yield()
}
4 changes: 2 additions & 2 deletions stdlib/universe/merge_filter_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ merge_filter_fn = () =>
//testcase merge_filter {
// expect.planner(rules: ["MergeFiltersRule": 1])
// result = merge_filter_fn()
// testing.diff(got: result, want: testing.loadMem(csv: output))
// testing.diff(got: result, want: csv.from(csv: output))
//}
testcase merge_filter_flag_off {
option planner.disableLogicalRules = ["MergeFiltersRule"]
Expand All @@ -50,5 +50,5 @@ testcase merge_filter_flag_off {

result = merge_filter_fn()

testing.diff(got: result, want: testing.loadMem(csv: output))
testing.diff(got: result, want: csv.from(csv: output))
}
2 changes: 1 addition & 1 deletion stdlib/universe/pivot_table_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ testcase pivot_table {
,,1,2018-05-22T19:53:26Z,2030-01-01T00:00:00Z,2018-05-22T19:54:16Z,system,host.local,1.84,1.97,93
"

testing.diff(got: result, want: testing.loadMem(csv: out_fields)) |> yield()
testing.diff(got: result, want: csv.from(csv: out_fields)) |> yield()
}
2 changes: 1 addition & 1 deletion stdlib/universe/yield_test.flux
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ testcase yield {
|> sample(n: 2, pos: 1)
|> yield(name: "2: 2nd row")
|> yield(name: "5")
want = testing.loadMem(csv: outData) |> yield(name: "6")
want = csv.from(csv: outData) |> yield(name: "6")

testing.diff(got, want)
}

0 comments on commit 1785418

Please sign in to comment.