Skip to content

Commit fcbee24

Browse files
execution utils tests
1 parent 545b936 commit fcbee24

File tree

2 files changed

+183
-4
lines changed

2 files changed

+183
-4
lines changed

src/utils/execution.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function defineNotepadExecutionType(
359359
}
360360
}
361361

362+
/* c8 ignore next */
362363
export function convertDSDataResponse(dataQueryCall: any) {
363364
if (dataQueryCall?.error) {
364365
return parseError(dataQueryCall.error);
@@ -370,6 +371,7 @@ export function convertDSDataResponse(dataQueryCall: any) {
370371
}
371372
}
372373

374+
/* c8 ignore next */
373375
export function parseError(error: GetDataError) {
374376
if (error instanceof Object && error.buffer) {
375377
return handleWSError(error.buffer);

test/suite/utils/execution.test.ts

Lines changed: 181 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ import * as assert from "assert";
1515
import * as vscode from "vscode";
1616

1717
import { ext } from "../../../src/extensionVariables";
18-
import { ExecutionTypes } from "../../../src/models/execution";
19-
import { QueryResultType } from "../../../src/models/queryResult";
20-
import * as executionUtils from "../../../src/utils/execution";
21-
import { getPartialDatasourceFile } from "../../../src/utils/dataSource";
2218
import {
2319
createDefaultDataSourceFile,
2420
DataSourceTypes,
2521
} from "../../../src/models/dataSource";
22+
import { ExecutionTypes } from "../../../src/models/execution";
2623
import { CellKind } from "../../../src/models/notebook";
24+
import { QueryResultType } from "../../../src/models/queryResult";
25+
import * as executionUtils from "../../../src/utils/execution";
2726

2827
describe("execution", () => {
2928
it("runQFileTerminal", () => {
@@ -1063,4 +1062,182 @@ describe("execution", () => {
10631062
assert.strictEqual(result, ".");
10641063
});
10651064
});
1065+
1066+
describe("getEditorExecutionType", () => {
1067+
it("should return PythonQueryFile for Python with no target", () => {
1068+
const result = executionUtils.getEditorExecutionType(true);
1069+
assert.strictEqual(result, ExecutionTypes.PythonQueryFile);
1070+
});
1071+
1072+
it("should return PythonQueryFile for Python with scratchpad target", () => {
1073+
const result = executionUtils.getEditorExecutionType(true, "scratchpad");
1074+
assert.strictEqual(result, ExecutionTypes.PythonQueryFile);
1075+
});
1076+
1077+
it("should return PythonDataQueryFile for Python with custom target", () => {
1078+
const result = executionUtils.getEditorExecutionType(true, "database");
1079+
assert.strictEqual(result, ExecutionTypes.PythonDataQueryFile);
1080+
});
1081+
1082+
it("should return QueryFile for non-Python with no target", () => {
1083+
const result = executionUtils.getEditorExecutionType(false);
1084+
assert.strictEqual(result, ExecutionTypes.QueryFile);
1085+
});
1086+
1087+
it("should return QueryFile for non-Python with scratchpad target", () => {
1088+
const result = executionUtils.getEditorExecutionType(false, "scratchpad");
1089+
assert.strictEqual(result, ExecutionTypes.QueryFile);
1090+
});
1091+
1092+
it("should return DataQueryFile for non-Python with custom target", () => {
1093+
const result = executionUtils.getEditorExecutionType(false, "database");
1094+
assert.strictEqual(result, ExecutionTypes.DataQueryFile);
1095+
});
1096+
1097+
it("should return PythonDataQueryFile for Python with empty string target", () => {
1098+
const result = executionUtils.getEditorExecutionType(true, "");
1099+
assert.strictEqual(result, ExecutionTypes.PythonQueryFile);
1100+
});
1101+
1102+
it("should return DataQueryFile for non-Python with empty string target", () => {
1103+
const result = executionUtils.getEditorExecutionType(false, "");
1104+
assert.strictEqual(result, ExecutionTypes.QueryFile);
1105+
});
1106+
});
1107+
1108+
describe("getDataTypeForEditor", () => {
1109+
it("should return QSQL for .q files", () => {
1110+
const result = executionUtils.getDataTypeForEditor("script.q");
1111+
assert.strictEqual(result, DataSourceTypes.QSQL);
1112+
});
1113+
1114+
it("should return QSQL for .py files", () => {
1115+
const result = executionUtils.getDataTypeForEditor("script.py");
1116+
assert.strictEqual(result, DataSourceTypes.QSQL);
1117+
});
1118+
1119+
it("should return SQL for .sql files", () => {
1120+
const result = executionUtils.getDataTypeForEditor("query.sql");
1121+
assert.strictEqual(result, DataSourceTypes.SQL);
1122+
});
1123+
1124+
it("should return SQL for .txt files", () => {
1125+
const result = executionUtils.getDataTypeForEditor("document.txt");
1126+
assert.strictEqual(result, DataSourceTypes.SQL);
1127+
});
1128+
1129+
it("should return SQL for files without extension", () => {
1130+
const result = executionUtils.getDataTypeForEditor("filename");
1131+
assert.strictEqual(result, DataSourceTypes.SQL);
1132+
});
1133+
1134+
it("should return SQL for empty string", () => {
1135+
const result = executionUtils.getDataTypeForEditor("");
1136+
assert.strictEqual(result, DataSourceTypes.SQL);
1137+
});
1138+
1139+
it("should return QSQL for file paths ending with .q", () => {
1140+
const result = executionUtils.getDataTypeForEditor("/path/to/file.q");
1141+
assert.strictEqual(result, DataSourceTypes.QSQL);
1142+
});
1143+
1144+
it("should return QSQL for file paths ending with .py", () => {
1145+
const result = executionUtils.getDataTypeForEditor("/path/to/script.py");
1146+
assert.strictEqual(result, DataSourceTypes.QSQL);
1147+
});
1148+
1149+
it("should handle case sensitivity for extensions", () => {
1150+
const resultQ = executionUtils.getDataTypeForEditor("script.Q");
1151+
assert.strictEqual(resultQ, DataSourceTypes.SQL);
1152+
1153+
const resultPy = executionUtils.getDataTypeForEditor("script.PY");
1154+
assert.strictEqual(resultPy, DataSourceTypes.SQL);
1155+
});
1156+
});
1157+
1158+
describe("retrieveEditorFileType", () => {
1159+
it("should return NOTEBOOK for .kxnb files", () => {
1160+
const result = executionUtils.retrieveEditorFileType("notebook.kxnb");
1161+
assert.strictEqual(result, "NOTEBOOK");
1162+
});
1163+
1164+
it("should return DATASOURCE for .kdb.json files", () => {
1165+
const result = executionUtils.retrieveEditorFileType(
1166+
"datasource.kdb.json",
1167+
);
1168+
assert.strictEqual(result, "DATASOURCE");
1169+
});
1170+
1171+
it("should return GGPLOT for .plot files", () => {
1172+
const result = executionUtils.retrieveEditorFileType("chart.plot");
1173+
assert.strictEqual(result, "GGPLOT");
1174+
});
1175+
1176+
it("should return WORKBOOK for .kdb.q files", () => {
1177+
const result = executionUtils.retrieveEditorFileType("workbook.kdb.q");
1178+
assert.strictEqual(result, "WORKBOOK");
1179+
});
1180+
1181+
it("should return WORKBOOK for .kdb.py files", () => {
1182+
const result = executionUtils.retrieveEditorFileType("workbook.kdb.py");
1183+
assert.strictEqual(result, "WORKBOOK");
1184+
});
1185+
1186+
it("should return SCRATCHPAD for .q files", () => {
1187+
const result = executionUtils.retrieveEditorFileType("script.q");
1188+
assert.strictEqual(result, "SCRATCHPAD");
1189+
});
1190+
1191+
it("should return SCRATCHPAD for .py files", () => {
1192+
const result = executionUtils.retrieveEditorFileType("script.py");
1193+
assert.strictEqual(result, "SCRATCHPAD");
1194+
});
1195+
1196+
it("should return SCRATCHPAD for .sql files", () => {
1197+
const result = executionUtils.retrieveEditorFileType("query.sql");
1198+
assert.strictEqual(result, "SCRATCHPAD");
1199+
});
1200+
1201+
it("should return SCRATCHPAD for files without extension", () => {
1202+
const result = executionUtils.retrieveEditorFileType("filename");
1203+
assert.strictEqual(result, "SCRATCHPAD");
1204+
});
1205+
1206+
it("should return SCRATCHPAD for empty string", () => {
1207+
const result = executionUtils.retrieveEditorFileType("");
1208+
assert.strictEqual(result, "SCRATCHPAD");
1209+
});
1210+
1211+
it("should handle file paths correctly", () => {
1212+
const result = executionUtils.retrieveEditorFileType(
1213+
"/path/to/notebook.kxnb",
1214+
);
1215+
assert.strictEqual(result, "NOTEBOOK");
1216+
});
1217+
1218+
it("should handle multiple dots in filename", () => {
1219+
const result = executionUtils.retrieveEditorFileType(
1220+
"file.with.dots.kdb.json",
1221+
);
1222+
assert.strictEqual(result, "DATASOURCE");
1223+
});
1224+
1225+
it("should handle case sensitivity for extensions", () => {
1226+
const resultKxnb = executionUtils.retrieveEditorFileType("notebook.KXNB");
1227+
assert.strictEqual(resultKxnb, "SCRATCHPAD");
1228+
1229+
const resultJson = executionUtils.retrieveEditorFileType(
1230+
"datasource.KDB.JSON",
1231+
);
1232+
assert.strictEqual(resultJson, "SCRATCHPAD");
1233+
1234+
const resultPlot = executionUtils.retrieveEditorFileType("chart.PLOT");
1235+
assert.strictEqual(resultPlot, "SCRATCHPAD");
1236+
});
1237+
1238+
it("should prioritize more specific extensions", () => {
1239+
const result = executionUtils.retrieveEditorFileType("test.kdb.q.kxnb");
1240+
assert.strictEqual(result, "NOTEBOOK");
1241+
});
1242+
});
10661243
});

0 commit comments

Comments
 (0)