Example #1
0
def verify_case(cname):
    # read .in and .out files from cases
    indata = read_input_file(cname)
    outdata = read_output_file(cname)

    # first run the test
    result = wrapper.run_test(deepcopy(indata))

    # then run the verifier
    vresult, vmsg = verify(result, deepcopy(indata), deepcopy(outdata))

    # if failure, alert the test system
    if not vresult:
        raise AssertionError(vmsg)
def verify_case(cname):
    # read .in and .out files from cases
    with open(os.path.join('cases',cname+'.in'),'r') as f:
        indata = f.read()

    with open(os.path.join('cases',cname+'.out'),'r') as f:
        outdata = f.read()

    # first run the test
    result = wrapper.run_test(json.loads(indata))

    # then run the verifier
    vresult,vmsg = verify(result, json.loads(indata), json.loads(outdata))

    # if failure, alert the test system
    if not vresult:
        raise AssertionError(vmsg)
Example #3
0
    d = None
    g = None

    print "-----------------"
    print "Test %s.in" % case

    # Read inputs
    with open("cases/" + case + '.in', 'r') as f:
        d = json.loads(f.read().replace("\'",
                                        '"').replace("(",
                                                     '[').replace(")", ']'))

    print "Description: %s" % d["test"]

    # Run test
    r = wrapper.run_test(d)

    # JSON-encode and decode the result to mimic sandboxed autograder
    try:
        r = json.loads(json.dumps(r))
    except:
        print "WARNING: your return value in this test uses an unsupported type!"
        print "Stick to dictionaries, objects, arrays, strings, numbers, booleans, and null."

    # Read golden output
    with open("cases/" + case + '.out', 'r') as f:
        g = json.loads(f.read().replace("\'",
                                        '"').replace("(",
                                                     '[').replace(")", ']'))

    # Verify test output
Example #4
0
os.rename('/usr/testhost/wrapper.py', './wrapper.py')
os.chmod('./wrapper.py', 0o777)

os.rename('/usr/testhost/cases/' + os.environ['ITEM'] + '.in', './input')
os.environ['ITEM'] = '0'
os.environ['ITEMS'] = '0'
os.chmod('./input', 0o777)

os.rename('./code.py', './[[ module_name ]].py')
os.chmod('./[[ module_name ]].py', 0o777)

os.setgid(65534)
os.setuid(65534)
sys.path.insert(0, os.getcwd())

# DO NOT MOVE THE IMPORT STATEMENT TO THE TOP OF THE FILE!
import wrapper

# Read inputs
d = None
with open('input', 'r') as f:
    d = json.loads(f.read())

# Run test
r = wrapper.run_test(d)

# Save result
with open('output', 'w') as f:
    json.dump(r, f)
Example #5
0
passed = []
for case in cases:
    d = None
    g = None

    print("-----------------")
    print("Test %s.in" % case)

    # Read inputs
    with open("cases/" + case + '.in', 'r') as f:
        d = json.loads(f.read())

    print("Description: %s" % d["test"])

    # Run test
    r = wrapper.run_test(copy.deepcopy(d))

    # JSON-encode and decode the result to mimic sandboxed autograder
    try:
        r = json.loads(json.dumps(r))
    except:
        print(
            "WARNING: your return value in this test uses an unsupported type!"
        )
        print(
            "Stick to dictionaries, objects, arrays, strings, numbers, booleans, and null."
        )

    # Read golden output
    with open("cases/" + case + '.out', 'r') as f:
        g = json.loads(f.read())
Example #6
0
for case in cases:
    d = None
    g = None

    print "-----------------"
    print "Test %s.in" % case

    # Read inputs
    with open("cases/"+case+'.in', 'r') as f:
        d = json.loads(f.read())

    print "Description: %s" % d["test"]

    # Run test
    r = wrapper.run_test(copy.deepcopy(d))

    # JSON-encode and decode the result to mimic sandboxed autograder
    try:
        r = json.loads(json.dumps(r))
    except:
        print "WARNING: your return value in this test uses an unsupported type!"
        print "Stick to dictionaries, objects, arrays, strings, numbers, booleans, and null."

    # Read golden output
    with open("cases/"+case+'.out', 'r') as f:
        g = json.loads(f.read().replace("\'", '"').replace("(", '[').replace(")", ']'))

    # Verify test output
    ok, message = verifier.verify(r, d, g)