Example #1
0
    def run(self, runtime_context: RuntimeContext, sandbox: Sandbox):
        user_outputs = {}
        run_info = {}
        cmd_holder = "/workdir/judge_client {0} {1} ".format(runtime_context.problem_metadata.memory_limit,\
                                                             runtime_context.problem_metadata.time_limit)
        cmd_holder = cmd_holder + "/workdir/{0} " + \
                     "/workdir/outputs/{1}.out " + \
                     "/workdir/{1}.err /workdir/solution"

        for input_name, input in runtime_context.problem_metadata.inputs.items(
        ):
            basename = input_name.split('.')[0]
            cmd = cmd_holder.format(input_name, basename)
            run_info[basename + ".out"] = sandbox.exec(cmd).get('Output')

        outputs = sandbox.get_files_from_sandbox("/workdir/outputs/")
        for name, output in outputs:
            user_outputs[name] = str(output, 'UTF-8')

        return {'RunInfo': run_info, 'UserOutput': user_outputs}
Example #2
0
    def test_send_and_get_files_from_sandbox(self):
        sandbox = Sandbox(54321)

        # get .py files under tests/resources/
        files = []
        resources_path = self.PROJECT_ROOT.joinpath('./tests/resources')
        for path in resources_path.glob('*.py'):
            file_obj = open(path, 'rb')
            files.append((path.name, file_obj.read()))
            file_obj.close()

        # make directory for them
        res = sandbox.exec('mkdir /workdir/test_copy')
        self.assertEqual(0, res.get('ExitCode'))

        # send them all
        res = sandbox.write_files_in_sandbox(files, '/workdir/test_copy')
        self.assertTrue(res)

        # get and check
        res = sandbox.get_files_from_sandbox('/workdir/test_copy/.')
        self.assertListEqual(files, res)