Skip to content

Commit aa99294

Browse files
committed
test cleanup
1 parent 3808301 commit aa99294

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

packages/perspective/test/js/computed/functionality.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,38 @@ module.exports = perspective => {
228228
table.delete();
229229
});
230230

231-
it("Should be able to create multiple computed columns in multiple `view()`s", async function() {
231+
it("Should be able to create multiple computed columns with unique names in multiple `view()`s", async function() {
232232
const table = perspective.table(common.int_float_data);
233233
const view = table.view({
234234
computed_columns: [
235235
{
236236
column: "float + int",
237237
computed_function_name: "+",
238238
inputs: ["w", "x"]
239+
},
240+
{
241+
column: "float - int",
242+
computed_function_name: "-",
243+
inputs: ["w", "x"]
244+
},
245+
{
246+
column: "float * int",
247+
computed_function_name: "*",
248+
inputs: ["w", "x"]
239249
}
240250
]
241251
});
242252
const view2 = table.view({
243253
computed_columns: [
244254
{
245-
column: "float - int",
246-
computed_function_name: "-",
255+
column: "float / int",
256+
computed_function_name: "/",
247257
inputs: ["w", "x"]
258+
},
259+
{
260+
column: "int * float",
261+
computed_function_name: "*",
262+
inputs: ["x", "w"]
248263
}
249264
]
250265
});
@@ -257,15 +272,18 @@ module.exports = perspective => {
257272
x: "integer",
258273
y: "string",
259274
z: "boolean",
260-
"float + int": "float"
275+
"float + int": "float",
276+
"float - int": "float",
277+
"float * int": "float"
261278
});
262279

263280
expect(schema2).toEqual({
264281
w: "float",
265282
x: "integer",
266283
y: "string",
267284
z: "boolean",
268-
"float - int": "float"
285+
"float / int": "float",
286+
"int * float": "float"
269287
});
270288

271289
const result = await view.to_columns();
@@ -276,15 +294,18 @@ module.exports = perspective => {
276294
x: [1, 2, 3, 4],
277295
y: ["a", "b", "c", "d"],
278296
z: [true, false, true, false],
279-
"float + int": [2.5, 4.5, 6.5, 8.5]
297+
"float + int": [2.5, 4.5, 6.5, 8.5],
298+
"float - int": [0.5, 0.5, 0.5, 0.5],
299+
"float * int": [1.5, 5, 10.5, 18]
280300
});
281301

282302
expect(result2).toEqual({
283303
w: [1.5, 2.5, 3.5, 4.5],
284304
x: [1, 2, 3, 4],
285305
y: ["a", "b", "c", "d"],
286306
z: [true, false, true, false],
287-
"float - int": [0.5, 0.5, 0.5, 0.5]
307+
"float / int": [1.5, 1.25, 1.1666666666666667, 1.125],
308+
"int * float": [1.5, 5, 10.5, 18]
288309
});
289310

290311
view2.delete();
@@ -334,6 +355,9 @@ module.exports = perspective => {
334355

335356
view.delete();
336357

358+
// force a process()
359+
expect(await table.size()).toEqual(4);
360+
337361
const schema2 = await view2.schema();
338362

339363
expect(schema2).toEqual({
@@ -408,6 +432,9 @@ module.exports = perspective => {
408432

409433
const schema2 = await view2.schema();
410434

435+
// force a process()
436+
expect(await table.size()).toEqual(4);
437+
411438
expect(schema2).toEqual({
412439
w: "float",
413440
x: "integer",
@@ -549,7 +576,7 @@ module.exports = perspective => {
549576
table.delete();
550577
});
551578

552-
it("A view without computed columns should break when serializing after another view with a computed column is deleted.", async function() {
579+
it("A view without computed columns should not serialize computed columns from other views.", async function() {
553580
const table = perspective.table(common.int_float_data);
554581
const view = table.view({
555582
computed_columns: [
@@ -802,7 +829,7 @@ module.exports = perspective => {
802829
table.delete();
803830
});
804831

805-
it("Should be able to row pivot on a non-computed column and get correct results.", async function() {
832+
it("Should be able to row pivot on a non-computed column and get correct results for the computed column.", async function() {
806833
const table = perspective.table(common.int_float_data);
807834
const view = table.view({
808835
row_pivots: ["w"],

python/perspective/perspective/tests/table/test_view.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,13 @@ def test_invalid_sorts_should_throw(self):
14791479
tbl.view(sort=[["x", "desc"]])
14801480
assert str(ex.value) == "Invalid column 'x' found in View sorts.\n"
14811481

1482+
def test_should_throw_on_first_invalid(self):
1483+
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
1484+
tbl = Table(data)
1485+
with raises(PerspectiveCppError) as ex:
1486+
tbl.view(row_pivots=["a"], column_pivots=["c"], filter=[["a", ">", 1]], aggregates={"a": "avg"}, sort=[["x", "desc"]])
1487+
assert str(ex.value) == "Invalid column 'x' found in View sorts.\n"
1488+
14821489
def test_invalid_columns_not_in_computed_should_throw(self):
14831490
data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
14841491
tbl = Table(data)

0 commit comments

Comments
 (0)