예제 #1
0
def _runJavaTest(ctx, studentDir: str, codeDir: str, assignment: Assignment,
                 testId: str, testDir: str, filter: Optional[str],
                 hasTests: bool, isStudent: bool):
    cfg = ctx.cfg
    if filter is None:
        filter = '*'
    gradleProps = {
        'testFilter': filter,
        'testDir': testDir,
        'studentDir': codeDir
    }
    gradlePropArgs = []
    for k, v in gradleProps.items():
        gradlePropArgs.append(f'-P{k}={v}')
    print()
    print(blue(f"Starting test {testId}"))
    with shell.workingDir(cfg.baseDir):
        if not shell.isFile('build.gradle'):
            abort(f'No build.gradle file in {cfg.baseDir}, aborting')
        if not hasTests:
            gradleCmd = 'compileJava'
        else:
            gradleCmd = 'test'
        cmd = [cfg.gradlePath] + gradlePropArgs + [gradleCmd, '--rerun-tasks']
        print(f'Executing {" ".join(cmd)}')
        logFileName = shell.pjoin(studentDir, f'OUTPUT_{testId}.txt')
        with shell.createTee([shell.TEE_STDOUT, logFileName]) as tee:
            result = shell.run(cmd,
                               onError='ignore',
                               stderrToStdout=True,
                               captureStdout=tee)
        output = open(logFileName, 'r').read()
    if result.exitcode == 0:
        print(green(f'Test {testId} OK'))
    else:
        print(red(f'Test {testId} FAILED, see above'))
    result = Result.parseResult(output)
    prefix = 'S' if isStudent else ''
    ctx.storeTestResultInSpreadsheet(studentDir, assignment, testId,
                                     [prefix + 'C'],
                                     0 if result.compileError else 1)
    if hasTests:
        ctx.storeTestResultInSpreadsheet(studentDir, assignment, testId,
                                         [prefix + 'T'], result.ratio())
예제 #2
0
def runJavaTests(cfg: Config, args: TestArgs, studentDir: str, assignment: Assignment):
    gradleProps = {
        'testFilter': assignment.getValue('test-filter'),
        'testDir': cfg.testDir,
        'studentDir': studentDir
    }
    gradlePropArgs = []
    for k, v in gradleProps.items():
        gradlePropArgs.append(f'-P{k}={v}')
    print()
    with shell.workingDir(cfg.baseDir):
        if not shell.isFile('build.gradle'):
            abort(f'No build.gradle file in {cfg.baseDir}, aborting')
        cmd = [cfg.gradlePath] + gradlePropArgs + ['test', '--rerun-tasks']
        print(f'Executing {" ".join(cmd)}')
        result = shell.run(cmd, onError='ignore')
    if result.exitcode == 0:
        print(green(f'Tests for {assignment.id} OK'))
    else:
        print(red(f'Tests for {assignment.id} FAILED, see above'))
예제 #3
0
def assertFileNotEmpty(path):
    assertExists(path)
    s = shell.readBinaryFile(path, )
    if not s:
        abort(f'File {path} is empty')


def assertEqual(expected, given):
    if expected != given:
        abort(f'Expected {expected}, given {given}')


with shell.tempDir(onException=False) as tmp:
    print(f'tmp={tmp}')
    shell.cp(shell.pjoin(topDir, 'test-data'), tmp)
    with shell.workingDir(shell.pjoin(tmp, 'test-data/submissions')):

        print('### import ###')
        shell.run([checkAssignments, 'import', '../rating-moodle.csv'])
        assertExists('rating.xlsx')

        print('### unzip ###')
        barFoo = 'Bar Foo_1234_assignsubmission_file_/'
        shell.run([checkAssignments, 'unzip'])
        assertExists(barFoo + 'assignment_01.py')

        print('### checkFilenames ###')
        shell.run([checkAssignments, 'checkFilenames'])
        shell.run([checkAssignments, 'fixFilenames'])

        print('### addComment ###')
예제 #4
0
def findFiles(dir, glob):
    with shell.workingDir(dir):
        l = shell.run(['find', '.', '-name', glob],
                      captureStdout=shell.splitLines).stdout
        return [utils.stripLeading(x, './') for x in l]
예제 #5
0
def runHaskellTests(ctx, studentDir: str, assignment: Assignment):
    with shell.workingDir(studentDir):
        runHaskellTestsInStudentDir(ctx, studentDir, assignment)