-
-
Notifications
You must be signed in to change notification settings - Fork 311
/
test_cli.py
64 lines (46 loc) · 2.05 KB
/
test_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import sys
import unittest
from importlib import reload
from shutil import copyfile
from unittest.mock import patch
from typing import Callable, Optional, List, Set, Tuple, Any
from tests.utils import (CaptureOutput, assemble_for_selfie,
for_all_test_results, list_files)
import self as grader
from lib.checks import execute
from lib.model import Assignment, Check, CheckResult
from self import baseline_assignments, main
class TestCli(unittest.TestCase):
def setUp(self):
self.assignments = grader.assignments
self.baseline_assignments = grader.baseline_assignments
grader.baseline_assignments = [
# capture index in closure with python default value of lambda
Assignment(a.name, a.lecture, a.category, a.description, lambda i=i: self.check_baseline_assignment_mock(i))
for i, a in enumerate(grader.baseline_assignments)
]
grader.assignments = [
Assignment(a.name, a.lecture, a.category, a.description, self.check_assignment_mock)
for a in grader.assignments
]
self.count = 0
def tearDown(self):
grader.assignments = self.assignments
grader.baseline_assignments = self.baseline_assignments
def check_baseline_assignment_mock(self, n_th_baseline) -> List[Check]:
def assert_order(i) -> CheckResult:
self.assertEqual(self.count, i)
self.count = self.count + 1
return CheckResult(True, '', '', '')
return [Check('', '', lambda: assert_order(n_th_baseline))]
def check_assignment_mock(self) -> List[Check]:
def assert_executed_after_baseline() -> CheckResult:
self.assertEqual(self.count, len(self.baseline_assignments))
return CheckResult(True, '', '', '')
return [Check('', '', assert_executed_after_baseline)]
def test_baseline_execution_order(self):
with CaptureOutput():
grader.main([sys.argv[0], list(self.assignments)[0].name])
if __name__ == '__main__':
unittest.main()