def generate(result, config): """ Runs Otter Generate on the directory ``result`` using the configurations provided in ``config``. Args: result (``pathlib.Path``): the path to the autograder directory config (``dict``): configurations for Otter Generate Raises: ``ImportError``: if Otter is not installed """ try: from otter.argparser import get_parser parser = get_parser() except ImportError: raise ImportError( "You must have otter-grader installed to generate a Gradescope zip file." ) curr_dir = os.getcwd() os.chdir(result) generate_cmd = ["generate", "autograder"] if config.get('points', None) is not None: generate_cmd += ["--points", config.get('points', None)] if config.get('threshold', None) is not None: generate_cmd += ["--threshold", config.get('threshold', None)] if config.get('show_stdout', False): generate_cmd += ["--show-stdout"] if config.get('show_hidden', False): generate_cmd += ["--show-hidden"] if config.get('grade_from_log', False): generate_cmd += ["--grade-from-log"] if config.get('seed', None) is not None: generate_cmd += ["--seed", str(config.get('seed', None))] if config.get('pdfs', {}): pdf_args = config.get('pdfs', {}) token = APIClient.get_token() generate_cmd += ["--token", token] generate_cmd += ["--course-id", str(pdf_args["course_id"])] generate_cmd += ["--assignment-id", str(pdf_args["assignment_id"])] if not pdf_args.get("filtering", True): generate_cmd += ["--unfiltered-pdfs"] if config.get('files', []): generate_cmd += config.get('files', []) if config.get('variables', {}): generate_cmd += ["--serialized-variables", str(config["variables"])] args = parser.parse_args(generate_cmd) args.func(args) os.chdir(curr_dir)
import datetime import testing.postgresql from unittest import mock from psycopg2 import connect, extensions from psycopg2.errors import DuplicateTable from otter.argparser import get_parser from otter.service.create import create_users, remove_users from otter.service.create import main as create from .. import TestCase TEST_FILES_PATH = "test/test_service/test-create/" parser = get_parser() class TestCreate(TestCase): @classmethod def setUpClass(cls): super().setUpClass() cls.postgresql = testing.postgresql.Postgresql() cls.conn = connect(**cls.postgresql.dsn()) cls.conn.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT) args = parser.parse_args(["service", "create"]) args.func = create args.func(args, conn=cls.conn)