Skip to content

Commit

Permalink
Merge pull request #445 from dodona-edu/feature/various
Browse files Browse the repository at this point in the history
Various small improvements
  • Loading branch information
niknetniko authored Oct 12, 2023
2 parents 573593c + 52ca54d commit 725659e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tested/dodona.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ def report_update(to: IO, update: Update):
"""
as_dict = dodona_converter.unstructure(update)
cleaned = _clean_dictionary(as_dict)
json.dump(cleaned, to)
json.dump(cleaned, to, ensure_ascii=False)
if __debug__:
print("", file=to)
3 changes: 2 additions & 1 deletion tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def _convert_assignment(node: ast.Assign) -> Assignment:
)
variable = node.targets[0]
if not isinstance(variable, ast.Name):
raise InvalidDslError("You can only assign to simple variables")
actual = ast.dump(node)
raise InvalidDslError(f"You can only assign to simple variables, got: {actual}")
value = _convert_expression(node.value, False)

# Support a few obvious ones, such as constructor calls or literal values.
Expand Down
25 changes: 25 additions & 0 deletions tested/dsl/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
"unevaluatedProperties" : false,
"description" : "An individual test for a statement or expression",
"properties" : {
"description": {
"$ref": "#/$defs/message"
},
"stdin" : {
"description" : "Stdin for this context",
"type" : [
Expand Down Expand Up @@ -519,6 +522,28 @@
"runhaskell",
"csharp"
]
},
"message": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"required" : [
"description"
],
"properties" : {
"description": {
"type" : "string"
},
"format": {
"type" : "string",
"default" : "text"
}
}
}
]
}
}
}
25 changes: 25 additions & 0 deletions tested/dsl/schema_draft7.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
"type" : "object",
"description" : "An individual test for a statement or expression",
"properties" : {
"description": {
"$ref": "#/definitions/message"
},
"stdin" : {
"description" : "Stdin for this context",
"type" : [
Expand Down Expand Up @@ -511,6 +514,28 @@
"runhaskell",
"csharp"
]
},
"message": {
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"required" : [
"description"
],
"properties" : {
"description": {
"type" : "string"
},
"format": {
"type" : "string",
"default" : "text"
}
}
}
]
}
}
}
32 changes: 30 additions & 2 deletions tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
StringTypes,
resolve_to_basic,
)
from tested.dodona import ExtendedMessage
from tested.dsl.ast_translator import parse_string
from tested.parsing import get_converter, suite_to_json
from tested.serialisation import (
Expand Down Expand Up @@ -328,7 +329,9 @@ def _convert_yaml_value(stream: YamlObject) -> Value | None:
value = parse_string(stream, is_return=True)
else:
return None
assert isinstance(value, Value)
assert isinstance(
value, Value
), f"{value} is not of type Value, got {type(value)} instead"
return value


Expand Down Expand Up @@ -427,7 +430,32 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase:
assert not return_channel
output.result = _convert_advanced_value_output_channel(result)

return Testcase(input=the_input, output=output, link_files=context.files)
if (description := testcase.get("description")) is not None:
if isinstance(description, str):
the_description = description
else:
assert isinstance(description, dict)
dd = description["description"]
assert isinstance(
dd, str
), f"The description.description field must be a string, got {dd!r}."
df = description.get("format", "text")
assert isinstance(
df, str
), f"The description.format field must be a string, got {df!r}."
the_description = ExtendedMessage(
description=dd,
format=df,
)
else:
the_description = None

return Testcase(
description=the_description,
input=the_input,
output=output,
link_files=context.files,
)


def _convert_context(context: YamlDict, dsl_context: DslContext) -> Context:
Expand Down
7 changes: 6 additions & 1 deletion tested/languages/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ def get_readable_input(
"""
format_ = "text" # By default, we use text as input.
if case.description:
text = case.description
if isinstance(case.description, ExtendedMessage):
text = case.description.description
format_ = case.description.format
else:
text = case.description
elif case.is_main_testcase():
assert isinstance(case.input, MainInput)
# See https://rouge-ruby.github.io/docs/Rouge/Lexers/ConsoleLexer.html
Expand All @@ -151,6 +155,7 @@ def get_readable_input(
else:
assert isinstance(case.input, LanguageLiterals)
text = case.input.get_for(bundle.config.programming_language)
format_ = bundle.config.programming_language

# If there are no files, return now. This means we don't need to do ugly stuff.
if not case.link_files:
Expand Down
2 changes: 1 addition & 1 deletion tested/languages/javascript/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def convert_value(value: Value) -> str:
else:
return "(-Infinity)"
elif value.type == BasicStringTypes.TEXT:
return json.dumps(value.data)
return json.dumps(value.data, ensure_ascii=False)
elif value.type == BasicBooleanTypes.BOOLEAN:
return str(value.data).lower()
elif value.type == BasicNothingTypes.NOTHING:
Expand Down
3 changes: 2 additions & 1 deletion tested/testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from attrs import define, field

from tested.datatypes import BasicStringTypes
from tested.dodona import Message
from tested.features import (
NOTHING,
Construct,
Expand Down Expand Up @@ -510,7 +511,7 @@ class Testcase(WithFeatures, WithFunctions):
"""

input: Statement | MainInput | LanguageLiterals
description: str | None = None
description: Message | None = None
output: Output = field(factory=Output)
link_files: list[FileUrl] = field(factory=list)

Expand Down
3 changes: 3 additions & 0 deletions tests/exercises/global/evaluation/plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
testcases:
- expression: "GLOBAL_VAR"
return: !v "GLOBAL"
description:
description: "Hallo"
format: "code"

0 comments on commit 725659e

Please sign in to comment.