1- /*
1+ // Python Tutor: https://github.com/pgbovine/OnlinePythonTutor/
2+ // Copyright (C) Philip Guo (philip@pgbovine.net)
3+ // LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
24
3- Online Python Tutor
4- https://github.com/pgbovine/OnlinePythonTutor/
5+ // use Webpack to automatically package up these dependencies
6+ require ( '../css/opt-testcases.css' ) ;
57
6- Copyright (C) Philip J. Guo (philip@pgbovine.net)
8+ var optCommon = require ( './opt-frontend-common.js' ) ;
9+ var pytutor = require ( './pytutor.js' ) ;
710
8- Permission is hereby granted, free of charge, to any person obtaining a
9- copy of this software and associated documentation files (the
10- "Software"), to deal in the Software without restriction, including
11- without limitation the rights to use, copy, modify, merge, publish,
12- distribute, sublicense, and/or sell copies of the Software, and to
13- permit persons to whom the Software is furnished to do so, subject to
14- the following conditions:
11+ var redSadFace = require ( './images/red-sad-face.jpg' ) ;
12+ var yellowHappyFace = require ( './images/yellow-happy-face.jpg' ) ;
1513
16- The above copyright notice and this permission notice shall be included
17- in all copies or substantial portions of the Software.
18-
19- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26-
27- */
28-
29- // Pre-reqs:
30- // - jquery-1.8.2.min.js
31- // - pytutor.js
32- // - opt-frontend-common.js
33- // - ace/src-min-noconflict/ace.js
34- // should all be imported BEFORE this file
14+ // TODO: abstract this better
15+ module . exports = {
16+ initTestcasesPane : initTestcasesPane ,
17+ }
3518
3619
3720var testcasesPaneHtml = '\
@@ -68,7 +51,7 @@ function initTestcasesPane(parentDivId, onChangeCallback /* optional */) {
6851}
6952
7053function getCombinedCode ( id ) {
71- var userCod = pyInputGetValue ( ) ;
54+ var userCod = optCommon . pyInputGetValue ( ) ;
7255 var testCod = ace . edit ( 'testCaseEditor_' + id ) . getValue ( ) ;
7356 // for reporting syntax errors separately for user and test code
7457 var userCodNumLines = userCod . split ( '\n' ) . length ;
@@ -105,7 +88,7 @@ function runTestFinishSuccessfulExecution() {
10588}
10689
10790function vizTestFinishSuccessfulExecution ( ) {
108- optFinishSuccessfulExecution ( ) ;
91+ optCommon . optFinishSuccessfulExecution ( ) ;
10992 doneRunningTest ( ) ;
11093}
11194
@@ -146,6 +129,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
146129 te . setShowPrintMargin ( false ) ;
147130 te . setBehavioursEnabled ( false ) ;
148131 te . setFontSize ( 11 ) ;
132+ te . $blockScrolling = Infinity ; // kludgy to shut up weird warnings
149133 //te.setReadOnly(true);
150134
151135 var s = te . getSession ( ) ;
@@ -185,6 +169,7 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
185169
186170 te . setValue ( initialCod ? initialCod . rtrim ( ) : defaultVal ,
187171 - 1 /* do NOT select after setting text */ ) ;
172+ te . focus ( ) ;
188173
189174 function runOrVizTestCase ( isViz /* true for visualize, false for run */ ) {
190175 if ( isViz ) {
@@ -197,9 +182,9 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
197182 var dat = getCombinedCode ( id ) ;
198183
199184 // adapted from executeCode in opt-frontend.js
200- var backend_script = langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
201- var backendOptionsObj = getBaseBackendOptionsObj ( ) ;
202- var frontendOptionsObj = getBaseFrontendOptionsObj ( ) ;
185+ var backend_script = optCommon . langToBackendScript ( $ ( '#pythonVersionSelector' ) . val ( ) ) ;
186+ var backendOptionsObj = optCommon . getBaseBackendOptionsObj ( ) ;
187+ var frontendOptionsObj = optCommon . getBaseFrontendOptionsObj ( ) ;
203188 frontendOptionsObj . jumpToEnd = true ;
204189
205190 if ( isViz ) {
@@ -221,9 +206,9 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
221206 } ) ;
222207
223208 if ( exceptionMsg ) {
224- $ ( '#outputTd_' + id ) . html ( '<img src="red-sad-face.jpg "></img>' ) ;
209+ $ ( '#outputTd_' + id ) . html ( '<img src="' + redSadFace + ' "></img>') ;
225210 } else {
226- $ ( '#outputTd_' + id ) . html ( '<img src="yellow-happy-face.jpg "></img>' ) ;
211+ $ ( '#outputTd_' + id ) . html ( '<img src="' + yellowHappyFace + ' "></img>') ;
227212 }
228213 } ;
229214 }
@@ -245,13 +230,13 @@ function addTestcase(initialCod /* optional code to pre-seed this test */,
245230
246231 var msg = trace [ 0 ] . exception_msg ;
247232 var trimmedMsg = msg . split ( ':' ) [ 0 ] ;
248- $ ( '#outputTd_' + id ) . html ( htmlspecialchars ( trimmedMsg ) ) ;
233+ $ ( '#outputTd_' + id ) . html ( pytutor . htmlspecialchars ( trimmedMsg ) ) ;
249234
250- handleUncaughtExceptionFunc ( trace ) ;
235+ optCommon . handleUncaughtExceptionFunc ( trace ) ;
251236 doneRunningTest ( ) ;
252237 }
253238
254- executeCodeAndCreateViz ( dat . cod ,
239+ optCommon . executeCodeAndCreateViz ( dat . cod ,
255240 backend_script , backendOptionsObj ,
256241 frontendOptionsObj ,
257242 'pyOutputPane' ,
0 commit comments