Gradescope

From PrattWiki
Jump to navigation Jump to search

Autograding

This is currently a sandbox for autograding tips and tricks

tests

  • @weight(N) -- no partial credit - self.assertEqual(out, out_c)
  • @partial_credit(N) -- use a pts counter to get partial, use set_score(pts) to set score, use self.assertEqual(pts, N) to give results
  • np.testing.assert_allclose(out_t, out_c, verbose=True) -- checks to see if all elements are close; fails if wrong sizes so use in try:
    try: 
        np.testing.assert_allclose(out_t, out_c, verbose=True)
        pts += 3
    except Exception as ex:
        print('Failed: {}'.format(ex))


Other Required Items

tests folder

test_files: change file names that are needed

import unittest
from gradescope_utils.autograder_utils.decorators import weight
from gradescope_utils.autograder_utils.files import check_submitted_files


class TestFiles(unittest.TestCase):
    @weight(0)
    def test_submitted_files(self):
        """Check submitted files"""
        missing_files = check_submitted_files(['diffint.py'])
        for path in missing_files:
            print('Missing {0}'.format(path))
        self.assertEqual(len(missing_files), 0, 'Missing some required files!')
        print('All required files submitted!')

test_outputs: other tests - see below

run_autograder

run_autograder Change names of files here.

#!/usr/bin/env bash

# Set up autograder files

cp /autograder/submission/diffint.py /autograder/source/diffint.py

cd /autograder/source

python3 run_tests.py > /autograder/results/results.json

requirements

requirements Include includes here

gradescope-utils>=0.3.1
subprocess32
numpy

setup

setup

#!/usr/bin/env bash

apt-get install -y python3 python3-pip python3-dev

pip3 install -r /autograder/source/requirements.txt

run_tests

run_tests.py

import unittest
from gradescope_utils.autograder_utils.json_test_runner import JSONTestRunner

if __name__ == '__main__':
    suite = unittest.defaultTestLoader.discover('tests')
    JSONTestRunner(visibility='visible', stdout_visibility='visible').run(suite)