Skip to content

Commit cb01f34

Browse files
committed
Support permission field on tab
1 parent f787f38 commit cb01f34

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

tested/dodona.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,7 @@
1717
from attrs import define
1818
from cattrs.preconf.json import make_converter
1919

20-
21-
@unique
22-
class Permission(StrEnum):
23-
"""To which level of user this message is visible."""
24-
25-
STAFF = auto()
26-
STUDENT = auto()
27-
ZEUS = auto()
28-
20+
from testsuite import Permission
2921

3022
@define
3123
class ExtendedMessage:

tested/dsl/schema-strict.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@
105105
},
106106
"hidden" : {
107107
"type" : "boolean",
108-
"description" : "Defines if the unit/tab is hidden for the student or not"
108+
"description" : "Tab is only shown if it has tests that failed"
109+
},
110+
"permission": {
111+
"$ref" : "#/definitions/permission"
109112
},
110113
"tab" : {
111114
"type" : "string",
@@ -142,6 +145,14 @@
142145
}
143146
]
144147
},
148+
"permission": {
149+
"type" : "string",
150+
"description" : "One of the permission levels supported by Dodona",
151+
"enum" : [
152+
"student",
153+
"staff"
154+
]
155+
},
145156
"unit" : {
146157
"type" : "object",
147158
"description" : "A unit in the test suite.",

tested/dsl/schema.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@
105105
},
106106
"hidden" : {
107107
"type" : "boolean",
108-
"description" : "Defines if the unit/tab is hidden for the student or not"
108+
"description" : "Tab is only shown if it has tests that failed"
109+
},
110+
"permission": {
111+
"$ref" : "#/definitions/permission"
109112
},
110113
"tab" : {
111114
"type" : "string",
@@ -142,6 +145,14 @@
142145
}
143146
]
144147
},
148+
"permission": {
149+
"type" : "string",
150+
"description" : "One of the permission levels supported by Dodona",
151+
"enum" : [
152+
"student",
153+
"staff"
154+
]
155+
},
145156
"unit" : {
146157
"type" : "object",
147158
"description" : "A unit in the test suite.",

tested/judge/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def _process_results(
324324
collector.add(CloseTab(), currently_open_tab)
325325
currently_open_tab = currently_open_tab + 1
326326
tab = bundle.suite.tabs[currently_open_tab]
327-
collector.add(StartTab(title=tab.name, hidden=tab.hidden))
327+
collector.add(StartTab(title=tab.name, hidden=tab.hidden, permission=tab.permission))
328328

329329
# Handle the contexts.
330330
collector.add(StartContext(description=planned.context.description))

tested/judge/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def complete_evaluation(bundle: Bundle, collector: OutputManager):
487487

488488
for tab in bundle.suite.tabs[tab_start:]:
489489
if context_start == 0 and testcase_start == 0:
490-
collector.add(StartTab(title=tab.name, hidden=tab.hidden))
490+
collector.add(StartTab(title=tab.name, hidden=tab.hidden, permission=tab.permission))
491491
assert tab.contexts
492492
for context in tab.contexts[context_start:]:
493493
updates: list[Update] = [

tested/testsuite.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,13 @@ def _runs_to_tab_converter(runs: list | None):
683683
contexts.append(context)
684684
return contexts
685685

686+
@unique
687+
class Permission(StrEnum):
688+
"""To which level of user this message is visible."""
689+
690+
STAFF = auto()
691+
STUDENT = auto()
692+
ZEUS = auto()
686693

687694
@custom_fallback_field(get_converter(), {"runs": ("contexts", _runs_to_tab_converter)})
688695
@define
@@ -692,6 +699,7 @@ class Tab(WithFeatures, WithFunctions):
692699
name: str
693700
contexts: list[Context] = field()
694701
hidden: bool | None = None
702+
permission: Permission | None = None
695703

696704
def get_used_features(self) -> FeatureSet:
697705
assert self.contexts is not None

tests/test_dsl_yaml.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
GenericValueOracle,
3838
LanguageLiterals,
3939
LanguageSpecificOracle,
40+
Permission,
4041
SupportedLanguage,
4142
TextOutputChannel,
4243
ValueOutputChannel,
@@ -1326,6 +1327,26 @@ def test_programming_language_can_be_globally_configured():
13261327
assert testcase.input.type == "expression"
13271328
assert testcase.input.literals.keys() == {"java"}
13281329

1330+
def test_tabs_can_be_given_permission():
1331+
yaml_str = """
1332+
namespace: "solution"
1333+
tabs:
1334+
- tab: "Ctx"
1335+
permission: "staff"
1336+
testcases:
1337+
- arguments: [ "--arg", "argument" ]
1338+
stdin: "Input string"
1339+
stdout: "Output string"
1340+
stderr: "Error string"
1341+
exit_code: 1
1342+
"""
1343+
json_str = translate_to_test_suite(yaml_str)
1344+
suite = parse_test_suite(json_str)
1345+
assert len(suite.tabs) == 1
1346+
tab = suite.tabs[0]
1347+
assert tab.permission == Permission.STAFF
1348+
assert isinstance(testcase.input, LanguageLiterals)
1349+
assert testcase.input.type == "expression"
13291350

13301351
def test_strict_json_schema_is_valid():
13311352
path_to_schema = Path(__file__).parent / "tested-draft7.json"

0 commit comments

Comments
 (0)