def test_limit(self): with shell.tempDir() as d: shell.mkdir(d + "/A/K/X", createParents=True) shell.mkdir(d + "/A/K/Y", createParents=True) shell.mkdir(d + "/A/L", createParents=True) shell.mkdir(d + "/B") shell.mkdir(d + "/C") shell.touch(d + "/A/L/x.txt") shell.touch(d + "/A/K/x.txt") shell.touch(d + "/A/K/X/x.txt") shell.touch(d + "/A/K/Y/x.txt") shell.touch(d + "/B/x.txt") shell.touch(d + "/C/x.txt") def action(d): self.assertTrue(shell.isFile(d + "/A/K/x.txt")) self.assertTrue(shell.isFile(d + "/A/K/X/x.txt")) self.assertTrue(shell.isFile(d + "/A/K/Y/x.txt")) self.assertTrue(shell.isFile(d + "/C/x.txt")) self.assertFalse(shell.isFile(d + "/B/x.txt")) self.assertFalse(shell.isFile(d + "/A/L/x.txt")) self.assertFalse(shell.isDir(d + "/B")) self.assertFalse(shell.isDir(d + "/A/L")) utils.withLimitedDir(d, ['./C', 'A/K/'], action)
def runTest(files, fun): with shell.tempDir() as d: c = mkConfig(d) studDir = shell.pjoin(d, student) shell.mkdir(studDir) for f in files: shell.touch(shell.pjoin(studDir, f)) fun(c)
def spreadsheetTest(action, check=None, path='test-data/bewertung.xlsx', sheetName=None): with shell.tempDir(delete=False, dir='.') as d: name = f'test_{uuid.uuid4()}.xlsx' p = shell.pjoin(d, name) shell.cp(path, p) x = action(p) if check: wb = exc.load_workbook(filename=p) if sheetName: sheet = wb[sheetName] else: sheet = wb.active check(sheet) return x
abort(f'File {path} does not contain "{s}"') 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'])