Skip to content

Commit a304555

Browse files
committed
bam
1 parent 5d95d6b commit a304555

4 files changed

Lines changed: 143 additions & 115 deletions

File tree

‎v3/tests/backend-tests/cs61a-multi-lambdas.golden_py3‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@
12161216
"func_name": "<lambda> <line 3>",
12171217
"is_zombie": true,
12181218
"parent_frame_id_list": [
1219-
4
1219+
1
12201220
],
12211221
"unique_hash": "<lambda> <line 3>_f2_p_z",
12221222
"ordered_varnames": [
@@ -1332,7 +1332,7 @@
13321332
"func_name": "<lambda> <line 3>",
13331333
"is_zombie": true,
13341334
"parent_frame_id_list": [
1335-
4
1335+
1
13361336
],
13371337
"unique_hash": "<lambda> <line 3>_f2_p_z",
13381338
"ordered_varnames": [
@@ -1370,7 +1370,7 @@
13701370
"func_name": "<lambda> <line 3>",
13711371
"is_zombie": false,
13721372
"parent_frame_id_list": [
1373-
4
1373+
1
13741374
],
13751375
"unique_hash": "<lambda> <line 3>_f5_p",
13761376
"ordered_varnames": [
@@ -1465,7 +1465,7 @@
14651465
"func_name": "<lambda> <line 3>",
14661466
"is_zombie": true,
14671467
"parent_frame_id_list": [
1468-
4
1468+
1
14691469
],
14701470
"unique_hash": "<lambda> <line 3>_f2_p_z",
14711471
"ordered_varnames": [
@@ -1503,7 +1503,7 @@
15031503
"func_name": "<lambda> <line 3>",
15041504
"is_zombie": false,
15051505
"parent_frame_id_list": [
1506-
4
1506+
1
15071507
],
15081508
"unique_hash": "<lambda> <line 3>_f5_p",
15091509
"ordered_varnames": [
@@ -1598,7 +1598,7 @@
15981598
"func_name": "<lambda> <line 3>",
15991599
"is_zombie": true,
16001600
"parent_frame_id_list": [
1601-
4
1601+
1
16021602
],
16031603
"unique_hash": "<lambda> <line 3>_f2_p_z",
16041604
"ordered_varnames": [
@@ -1640,7 +1640,7 @@
16401640
"func_name": "<lambda> <line 3>",
16411641
"is_zombie": false,
16421642
"parent_frame_id_list": [
1643-
4
1643+
1
16441644
],
16451645
"unique_hash": "<lambda> <line 3>_f5_p",
16461646
"ordered_varnames": [
@@ -1741,7 +1741,7 @@
17411741
"func_name": "<lambda> <line 3>",
17421742
"is_zombie": true,
17431743
"parent_frame_id_list": [
1744-
4
1744+
1
17451745
],
17461746
"unique_hash": "<lambda> <line 3>_f2_p_z",
17471747
"ordered_varnames": [
@@ -1783,7 +1783,7 @@
17831783
"func_name": "<lambda> <line 3>",
17841784
"is_zombie": true,
17851785
"parent_frame_id_list": [
1786-
4
1786+
1
17871787
],
17881788
"unique_hash": "<lambda> <line 3>_f5_p_z",
17891789
"ordered_varnames": [
@@ -1801,8 +1801,8 @@
18011801
"func_name": "<lambda> <line 3>",
18021802
"is_zombie": false,
18031803
"parent_frame_id_list": [
1804-
2,
1805-
4
1804+
5,
1805+
1
18061806
],
18071807
"unique_hash": "<lambda> <line 3>_f6",
18081808
"ordered_varnames": [
@@ -1902,7 +1902,7 @@
19021902
"func_name": "<lambda> <line 3>",
19031903
"is_zombie": true,
19041904
"parent_frame_id_list": [
1905-
4
1905+
1
19061906
],
19071907
"unique_hash": "<lambda> <line 3>_f2_p_z",
19081908
"ordered_varnames": [
@@ -1944,7 +1944,7 @@
19441944
"func_name": "<lambda> <line 3>",
19451945
"is_zombie": true,
19461946
"parent_frame_id_list": [
1947-
4
1947+
1
19481948
],
19491949
"unique_hash": "<lambda> <line 3>_f5_p_z",
19501950
"ordered_varnames": [
@@ -1962,8 +1962,8 @@
19621962
"func_name": "<lambda> <line 3>",
19631963
"is_zombie": false,
19641964
"parent_frame_id_list": [
1965-
2,
1966-
4
1965+
5,
1966+
1
19671967
],
19681968
"unique_hash": "<lambda> <line 3>_f6",
19691969
"ordered_varnames": [
@@ -2063,7 +2063,7 @@
20632063
"func_name": "<lambda> <line 3>",
20642064
"is_zombie": true,
20652065
"parent_frame_id_list": [
2066-
4
2066+
1
20672067
],
20682068
"unique_hash": "<lambda> <line 3>_f2_p_z",
20692069
"ordered_varnames": [
@@ -2105,7 +2105,7 @@
21052105
"func_name": "<lambda> <line 3>",
21062106
"is_zombie": true,
21072107
"parent_frame_id_list": [
2108-
4
2108+
1
21092109
],
21102110
"unique_hash": "<lambda> <line 3>_f5_p_z",
21112111
"ordered_varnames": [
@@ -2124,8 +2124,8 @@
21242124
"func_name": "<lambda> <line 3>",
21252125
"is_zombie": false,
21262126
"parent_frame_id_list": [
2127-
2,
2128-
4
2127+
5,
2128+
1
21292129
],
21302130
"unique_hash": "<lambda> <line 3>_f6",
21312131
"ordered_varnames": [
@@ -2226,7 +2226,7 @@
22262226
"func_name": "<lambda> <line 3>",
22272227
"is_zombie": true,
22282228
"parent_frame_id_list": [
2229-
4
2229+
1
22302230
],
22312231
"unique_hash": "<lambda> <line 3>_f2_p_z",
22322232
"ordered_varnames": [
@@ -2268,7 +2268,7 @@
22682268
"func_name": "<lambda> <line 3>",
22692269
"is_zombie": true,
22702270
"parent_frame_id_list": [
2271-
4
2271+
1
22722272
],
22732273
"unique_hash": "<lambda> <line 3>_f5_p_z",
22742274
"ordered_varnames": [

‎v5-unity/doctest_exec.py‎

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,61 @@
99
1010
Output:
1111
12-
- a JSON representation of the result of running those tests
12+
- a JSON representation of the result of running the given example
1313
1414
'''
1515

1616
'''
1717
TODOs
18-
- return success/failure/errors/etc.
19-
20-
- because doctests are based on stdout and not semantic value checking ...
21-
- there is an ambiguity between 'return-ing' stuff and printing stuff to
22-
the terminal. right now if students try to print, it will return None
23-
and print an extra None, which could be confusing
24-
- when students are trying to do printf-debugging inside of their
25-
functions, they will *always* get test failures since doctests are based
26-
on prints, not actual return values. hmmm, how do we fix this?!?
18+
19+
- are people going to brush up against the 1000-instruction execution
20+
limit? maybe raise that limit more?
21+
2722
'''
2823

2924
import cPickle
3025
import imp
3126
import json
3227
import sys
3328
import pg_logger
29+
from doctest_reader import encode_doctest
30+
3431
import pprint
32+
pp = pprint.PrettyPrinter()
3533

36-
def opt_run_doctest(doctest, example_number, student_code):
37-
module_name = doctest.name.split('.')[0] # grab the module part out of the test's name
3834

39-
# import student_code as a module
40-
# http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/
41-
#student_module = imp.new_module(module_name)
42-
#exec student_code in student_module.__dict__
43-
#student_globals = student_module.__dict__
35+
def opt_run_doctest(doctest, example_number, student_code):
36+
def my_finalizer(input_code, output_trace):
37+
ret = dict(doctest=encode_doctest(doctest),
38+
example_number=example_number,
39+
student_code=student_code,
40+
opt_trace=output_trace)
41+
json_output = json.dumps(ret, indent=None) # use indent=None, indent=2 for debugging
42+
#print(json_output)
43+
pp.pprint(output_trace)
44+
45+
46+
def opt_doctest_exec_script_str(script_str, custom_modules):
47+
logger = pg_logger.PGLogger(False, False, False, my_finalizer,
48+
disable_security_checks=False,
49+
custom_modules=custom_modules,
50+
separate_stdout_by_module=True)
51+
try:
52+
logger._runscript(script_str)
53+
except bdb.BdbQuit:
54+
pass
55+
finally:
56+
return logger.finalize()
4457

58+
module_name = doctest.name.split('.')[0] # grab the module part out of the test's name
4559
if example_number != 'all':
46-
assert 0 <= example_number < len(t.examples)
60+
assert 0 <= example_number < len(doctest.examples)
4761
# run a single example
48-
example_to_run = t.examples[example_number]
49-
#print example_to_run.source
50-
51-
#exec compile(example_to_run.source, module_name, "single") in student_globals
62+
example_to_run = doctest.examples[example_number]
5263
opt_doctest_exec_script_str(example_to_run.source,
53-
my_finalizer,
5464
custom_modules={module_name: student_code})
5565
else:
5666
raise NotImplementedError # not implemented yet!
57-
#for e in t.examples:
58-
# opt_run_doctest_example(t, e, student_code)
59-
pass
60-
61-
62-
def my_finalizer(input_code, output_trace):
63-
#ret = dict(code=input_code, trace=output_trace)
64-
#json_output = json.dumps(output_trace, indent=2) # use indent=None for most compact repr
65-
#print(json_output)
66-
pp = pprint.PrettyPrinter()
67-
pp.pprint(output_trace)
68-
69-
def opt_doctest_exec_script_str(script_str, finalizer_func, custom_modules):
70-
logger = pg_logger.PGLogger(False, False, False, finalizer_func,
71-
disable_security_checks=False,
72-
custom_modules=custom_modules)
73-
try:
74-
logger._runscript(script_str)
75-
except bdb.BdbQuit:
76-
pass
77-
finally:
78-
return logger.finalize()
7967

8068

8169
if __name__ == "__main__":
@@ -94,4 +82,3 @@ def opt_doctest_exec_script_str(script_str, finalizer_func, custom_modules):
9482
if t.name == test_name:
9583
opt_run_doctest(t, example_number, student_code)
9684
break
97-

‎v5-unity/doctest_reader.py‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
import sys
1313
import json
1414

15+
def encode_doctest(t):
16+
encoded_test = {}
17+
encoded_test['docstring'] = t.docstring
18+
encoded_test['name'] = t.name
19+
encoded_test['filename'] = t.filename
20+
encoded_examples = []
21+
encoded_test['examples'] = encoded_examples
22+
for e in t.examples:
23+
encoded_examples.append(
24+
dict(source=e.source,
25+
want=e.want,
26+
options=e.options,
27+
exc_msg=e.exc_msg))
28+
return encoded_test
29+
30+
1531
if __name__ == "__main__":
1632
fullpath = sys.argv[1]
1733
assert fullpath.endswith(".pickle")
1834
with open(fullpath) as f:
1935
tests = cPickle.load(f)
20-
21-
all_encoded_tests = []
22-
for t in tests:
23-
encoded_test = {}
24-
encoded_test['docstring'] = t.docstring
25-
encoded_test['name'] = t.name
26-
encoded_test['filename'] = t.filename
27-
encoded_examples = []
28-
encoded_test['examples'] = encoded_examples
29-
for e in t.examples:
30-
encoded_examples.append(
31-
dict(source=e.source,
32-
want=e.want,
33-
options=e.options,
34-
exc_msg=e.exc_msg))
35-
all_encoded_tests.append(encoded_test)
36-
36+
all_encoded_tests = [encode_doctest(t) for t in tests]
3737
print(json.dumps(all_encoded_tests, indent=2))

0 commit comments

Comments
 (0)