Skip to content

Commit 8941cac

Browse files
committed
test: support reset instructions when mode=fast
1 parent cefdb57 commit 8941cac

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

examples.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ def examples_data(input_dir, output_fn):
191191
'julia': shutil.which('julia'),
192192
}
193193

194+
def reset_code(lang):
195+
'''
196+
some code to reset local identifyers, in order to speed up execution (to avoid restarts)
197+
while avoid side effects of previous examples (mostly, I guess)
198+
'''
199+
reset = {
200+
'sage': 'reset()',
201+
'python': '%reset -f'
202+
}
203+
return reset.get(lang.lower(), '')
204+
194205
def language_to_kernel(lang):
195206
data = {
196207
"sage": "sagemath",
@@ -223,6 +234,9 @@ def get_jupyter(language, restart=True):
223234

224235
def exec_jupyter(language, code, restart=False):
225236
client = get_jupyter(language, restart=restart)
237+
if not restart:
238+
# if we don't restart, prepend a reset instruction
239+
code = '\n'.join([reset_code(language), code])
226240
msg_id = client.execute(code)
227241
outputs = []
228242
errors = []

src/sage/interact.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ code: |
2424
print("k: %s" % k)
2525
s = (1 - sqrt(k))^2
2626
print("s: %s" % s)
27+
test: false
2728
---
2829
title: Symbolic Function
2930
descr: |
@@ -38,6 +39,7 @@ code: |
3839
@interact
3940
def f_interact(x=(0, 100)):
4041
print 'f({}) = {}'.format(x, f(x))
42+
test: false
4143
---
4244
title: Multiple Sliders
4345
descr: |
@@ -50,3 +52,4 @@ code: |
5052
print("k: %s" % k)
5153
print("j: %s" % j)
5254
print("l: [%s, %s]" % l)
55+
test: false

src/sage/tutorial.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@ descr: |
107107
108108
*Warning*: when defining a symbolic function like `f(x) = x^2`, the variable `x`
109109
will not be a symbolic variable. So the code
110+
110111
```
111112
x = 7
112113
print x
113114
f(x) = x^2
114115
print x
115116
```
116-
will print `7` and then `x`.
117+
118+
will print `7` and then `x`.
117119
code: |
118120
def f(x):
119121
return 2*x

0 commit comments

Comments
 (0)