Skip to content

Commit e7308cb

Browse files
committed
fixed tests to accommodate new api
1 parent d96bd84 commit e7308cb

File tree

3 files changed

+72
-67
lines changed

3 files changed

+72
-67
lines changed

resources/evaluatePy.q

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fn: {[returnFormat;code;sample_fn;sample_size]
1+
{[returnFormat;code;sample_fn;sample_size]
22
if [`histogram in key `.qp;
33
if [not `display2 in key `.qp;
44
.qp.display2: (')[{x[`output][`bytes]}; .qp.display]

test/q/tests/evaluate.quke

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,5 @@ feature EDI
165165
`s ~ .test.evaluate["."; "\n\n" sv .test.attrLines; ::; "serialized"]`data
166166
expect an attribute with semi colons with two newlines
167167
`s ~ .test.evaluate["."; "\n\n" sv .test.attrLines ,\: ";"; ::; "serialized"]`data
168+
169+
// TODO: ADD STRUCTUREDTEXT TESTS

test/q/tests/evaluatePy.quke

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ feature removeExtraIndents
44
.test.evaluatePy: {[isString; code]
55
0i (.test.src; isString; code; "first"; 10000)
66
};
7-
7+
.qu.compare: (~)
88
should handle unmatched dedents
99
expect both expressions to be moved to column 0
1010
x: " a = 1 + 2\n",
1111
"a + 3";
12-
.qu.compare[.test.evaluatePy["serialized"; x]`result; 6]
12+
.qu.compare[.test.evaluatePy["serialized"; x]`data; 6]
1313

1414
should handle blank lines
1515
expect the expression to be moved to column 0
1616
x: "\n",
1717
" 1 + 2";
18-
.qu.compare[.test.evaluatePy["serialized"; x]`result; 3]
18+
.qu.compare[.test.evaluatePy["serialized"; x]`data; 3]
1919

2020
should handle tabs
2121
expect the expression and statement to be moved to column 0
2222
x: "\t\ta = 1\n",
2323
"\t\tdef foo(x):\n",
2424
"\t\t\treturn x + 1\n",
2525
"\tfoo(a)\n";
26-
.qu.compare[.test.evaluatePy["serialized"; x]`result; 2]
26+
.qu.compare[.test.evaluatePy["serialized"; x]`data; 2]
2727

2828
xshould handle multiline strings
2929
expect all statements to be moved to column 0
@@ -33,7 +33,7 @@ feature removeExtraIndents
3333
" b = \"one\"\n",
3434
" c = \"two\"\n",
3535
" (a,b,c)";
36-
.qu.compare[.test.evaluatePy["serialized"; x]`result; (21; `one; `two)];
36+
.qu.compare[.test.evaluatePy["serialized"; x]`data; (21; `one; `two)];
3737

3838
should handle functions at decreasing indents
3939
expect all statements to start in col 0
@@ -48,7 +48,7 @@ feature removeExtraIndents
4848
"\n",
4949
"foo(bar(quux(2)))";
5050

51-
.qu.compare[.test.evaluatePy["serialized"; x]`result; 256];
51+
.qu.compare[.test.evaluatePy["serialized"; x]`data; 256];
5252

5353
should handle functions at decreasing indents
5454
expect relative indenting within the function to be preserved
@@ -58,12 +58,12 @@ feature removeExtraIndents
5858
" \n",
5959
" def indented3 (x):\n",
6060
" return x * x";
61-
.test.evaluatePy["serialized"; x]`result;
61+
.test.evaluatePy["serialized"; x]`data;
6262

6363
all (
64-
.test.evaluatePy["serialized"; "indented1(1)"][`errored] ~ 0b;
65-
.test.evaluatePy["serialized"; "indented2(1)"][`errored] ~ 1b;
66-
.test.evaluatePy["serialized"; "indented3(1)"][`errored] ~ 1b
64+
.test.evaluatePy["serialized"; "indented1(1)"][`error] ~ 0b;
65+
.test.evaluatePy["serialized"; "indented2(1)"][`error] ~ 1b;
66+
.test.evaluatePy["serialized"; "indented3(1)"][`error] ~ 1b
6767
)
6868

6969
should leave legitimately incorrect indentation
@@ -73,8 +73,8 @@ feature removeExtraIndents
7373
" else:\n",
7474
" print(2)\n";
7575

76-
.qu.compare[.test.evaluatePy["serialized"; x]`error;
77-
"unindent does not match any outer indentation level (<unknown>, line 3)"]
76+
.qu.compare[.test.evaluatePy["serialized"; x]`errorMsg;
77+
`$"('unindent does not match any outer indentation level', ('<unknown>', 3, 7, ' else:\\n', 3, -1))"]
7878

7979

8080
feature evaluatePy 1
@@ -84,13 +84,13 @@ feature evaluatePy 1
8484
.test.evaluatePy: {[isString; code]
8585
0i (.test.src; isString; code; "first"; 10000)
8686
};
87-
.test.wrap: {`result`errored`error!(x; 0b; "")}
87+
.test.wrap: {`error`errorMsg`data!(0b; `; x)}
8888

8989
should run python code
9090
expect an empty input to return "None"
9191
.qu.compare[
9292
.test.evaluatePy["text"; ""];
93-
.test.wrap "None"]
93+
.test.wrap "None\n"]
9494
expect an empty input to return ::
9595
.qu.compare[
9696
.test.evaluatePy["serialized"; " \n \n "];
@@ -103,19 +103,19 @@ feature evaluatePy 1
103103
expect expressions to return a value
104104
.qu.compare[
105105
.test.evaluatePy["text"; "1+2"];
106-
.test.wrap "3"]
106+
.test.wrap "3\n"]
107107
expect statements to return an empty string
108108
.qu.compare[
109109
.test.evaluatePy["text"; "def axedi_test_fn(x):\n return 1 + x"];
110-
.test.wrap "None"]
110+
.test.wrap "None\n"]
111111
expect statements to have been executed
112112
.qu.compare[
113113
.test.evaluatePy["text"; "axedi_test_fn(10)"];
114-
.test.wrap "11"]
114+
.test.wrap "11\n"]
115115
expect utf-8 to be handled
116116
.qu.compare[
117117
.test.evaluatePy["text"; "'你好'"];
118-
.test.wrap "你好"]
118+
.test.wrap "'你好'\n"]
119119
xexpect return values to be limited to 250,000 characters
120120
.qu.compare[
121121
.test.evaluatePy["text"; "'", (251000#.Q.a) , "'"];
@@ -130,19 +130,22 @@ feature evaluatePy 1
130130
.test.evaluatePy["text"; "Long_Text()"];
131131
.test.wrap (raze 25000#enlist "\n123456789") , "\n.."]
132132
expect invalid statements to error
133+
result: .test.evaluatePy["text"; "1+++"];
134+
stacktrace: string result[`stacktrace];
135+
result[`stacktrace]: stacktrace;
133136
.qu.compare[
134-
.test.evaluatePy["text"; "1+++"];
137+
result;
135138
(!) . flip (
136-
(`result; ::);
137-
(`errored; 1b);
138-
(`error; "invalid syntax (<unknown>, line 1)");
139-
(`backtrace; " File \"<unknown>\", line 1\n 1+++\n ^\nSyntaxError: invalid syntax"))]
139+
(`error; 1b);
140+
(`errorMsg; `$"('invalid syntax', ('<unknown>', 1, 5, '1+++\\n', 1, 5))");
141+
(`data; ::);
142+
(`stacktrace; " File \"<unknown>\", line 1\n 1+++\n ^\nSyntaxError: invalid syntax"))]
140143

141144
should run multiline python code
142145
expect code ending in comments to evaluate correctly
143146
.qu.compare[
144147
.test.evaluatePy["text";"a=(1+ # An inline comment\n 2 + 3)\na\n# This is a comment"];
145-
.test.wrap "6"]
148+
.test.wrap "6\n"]
146149
xexpect code multiline strings to return the value of the last expression
147150
.qu.compare[
148151
.test.evaluatePy["text";"'''This is\na multiline\nstring'''"];
@@ -162,7 +165,7 @@ feature evaluatePy 1
162165
expect an assignment to return None
163166
.qu.compare[
164167
.test.evaluatePy["text";"a=1"];
165-
.test.wrap "None"]
168+
.test.wrap "None\n"]
166169
expect a backslash to work for writing multiline expressions
167170
.qu.compare[.test.evaluatePy["text";"\n" sv (
168171
"a = 1 \\";
@@ -171,7 +174,7 @@ feature evaluatePy 1
171174
" - 0";
172175
"a * \\";
173176
" 3")];
174-
.test.wrap "18"]
177+
.test.wrap "18\n"]
175178

176179
should display the stack trace for Python errors
177180
expect the stack trace to not show the functions before usercode
@@ -182,52 +185,52 @@ feature evaluatePy 1
182185
"def bar(x):";
183186
" return x + 'hello'");
184187

185-
.qu.compare[.test.evaluatePy["text"; "size = len(foo(5))"];
188+
result: .test.evaluatePy["text"; "size = len(foo(5))"];
189+
stacktrace: string result[`stacktrace];
190+
result[`stacktrace]: stacktrace;
191+
.qu.compare[
192+
result;
186193
(!) . flip (
187-
(`result; ::);
188-
(`errored; 1b);
189-
(`error; "unsupported operand type(s) for +: 'int' and 'str'");
190-
(`backtrace; "\n" sv (
191-
"Traceback (most recent call last):";
192-
" File \"<string>\", line 1, in <module>";
193-
" File \"<string>\", line 2, in foo";
194-
" File \"<string>\", line 5, in bar";
195-
"TypeError: unsupported operand type(s) for +: 'int' and 'str'")))]
194+
(`error; 1b);
195+
(`errorMsg; `$"(\"unsupported operand type(s) for +: 'int' and 'str'\",)");
196+
(`data; ::);
197+
(`stacktrace; "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n File \"<string>\", line 2, in foo\n File \"<string>\", line 5, in bar\nTypeError: unsupported operand type(s) for +: 'int' and 'str'"))]
196198

197199
expect the stack trace to not show the functions before user code
198-
.qu.compare[.test.evaluatePy["serialized"; "1 2 + 3 4"];
200+
result: .test.evaluatePy["serialized"; "1 2 + 3 4"];
201+
stacktrace: string result[`stacktrace];
202+
result[`stacktrace]: stacktrace;
203+
.qu.compare[
204+
result;
199205
(!) . flip (
200-
(`result; ::);
201-
(`errored; 1b);
202-
(`error; "invalid syntax (<unknown>, line 1)");
203-
(`backtrace; "\n" sv (
204-
" File \"<unknown>\", line 1";
205-
" 1 2 + 3 4";
206-
" ^";
207-
"SyntaxError: invalid syntax")))]
206+
(`error; 1b);
207+
(`errorMsg; `$"('invalid syntax', ('<unknown>', 1, 3, '1 2 + 3 4\\n', 1, 4))");
208+
(`data; ::);
209+
(`stacktrace; " File \"<unknown>\", line 1\n 1 2 + 3 4\n ^\nSyntaxError: invalid syntax"))]
208210

209211
expect no stack trace for errors outside a function
210-
.qu.compare[.test.evaluatePy["text"; "1 + 'a'"];
212+
result: .test.evaluatePy["text"; "1 + 'a'"];
213+
stacktrace: string result[`stacktrace];
214+
result[`stacktrace]: stacktrace;
215+
.qu.compare[
216+
result;
211217
(!) . flip (
212-
(`result; ::);
213-
(`errored; 1b);
214-
(`error; "unsupported operand type(s) for +: 'int' and 'str'");
215-
(`backtrace; "\n" sv (
216-
"Traceback (most recent call last):";
217-
" File \"<string>\", line 1, in <module>";
218-
"TypeError: unsupported operand type(s) for +: 'int' and 'str'")))]
218+
(`error; 1b);
219+
(`errorMsg; `$"(\"unsupported operand type(s) for +: 'int' and 'str'\",)");
220+
(`data; ::);
221+
(`stacktrace; "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\nTypeError: unsupported operand type(s) for +: 'int' and 'str'"))]
219222

220223
expect a stack trace for syntax errors
221-
.qu.compare[.test.evaluatePy["serialized"; "2)"];
224+
result: .test.evaluatePy["serialized"; "2)"];
225+
stacktrace: string result[`stacktrace];
226+
result[`stacktrace]: stacktrace;
227+
.qu.compare[
228+
result;
222229
(!) . flip (
223-
(`result; ::);
224-
(`errored; 1b);
225-
(`error; "unmatched ')' (<unknown>, line 1)");
226-
(`backtrace; "\n" sv (
227-
" File \"<unknown>\", line 1";
228-
" 2)";
229-
" ^";
230-
"SyntaxError: unmatched ')'")))]
230+
(`error; 1b);
231+
(`errorMsg; `$"(\"unmatched ')'\", ('<unknown>', 1, 2, '2)', 1, 2))");
232+
(`data; ::);
233+
(`stacktrace; " File \"<unknown>\", line 1\n 2)\n ^\nSyntaxError: unmatched ')'"))]
231234

232235
feature evaluatePy 2
233236
// These are the tests specific to the VS Code extension
@@ -239,9 +242,9 @@ feature evaluatePy 2
239242

240243
should define nothing in the global namespace except when explicitly the result of user code
241244
expect sendMe to not define anything in the remote process
242-
.test.evaluatePy["text"; "1+2"];
245+
; .test.evaluatePy["text"; "1+2"];
243246
.test.evaluatePy["serialized"; "1+2"];
244-
.pykx.qeval "all(map(lambda x: not(x in globals()), ['_kx_ast', 'BytesIO', 'tokenize', 'is_expr', 'run_line', 'range_to_text', 'run', 'find_strings']))";
247+
.pykx.qeval "all(map(lambda x: not(x in globals()), ['_kx_ast', 'BytesIO', 'tokenize', 'is_expr', 'run_line', 'range_to_text', 'run', 'find_strings']))"
245248

246249
expect the nested functions to be undefined
247250
@[{.pykx.eval x; 0b};
@@ -261,7 +264,7 @@ feature evaluatePy 2
261264
.pykx.i.defaultConv: original;
262265
all (
263266
defaultConvAfter ~ "py";
264-
result[`result] ~ 3
267+
result[`data] ~ 3
265268
)
266269

267270
should raise an error when .pykx is not installed
@@ -276,6 +279,6 @@ feature evaluatePy 2
276279

277280
.qu.compare[result;
278281
(!) . flip (
279-
(`result; ::);
282+
(`data; ::);
280283
(`errored; 1b);
281284
(`error; ".pykx is not defined: please load pykx"))]

0 commit comments

Comments
 (0)