Skip to content

Commit

Permalink
added comments for descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Nov 16, 2024
1 parent da4c1a3 commit 57c3079
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase:
if "statement" in testcase and "return" in testcase:
testcase["expression"] = testcase.pop("statement")

print(f"testcase: {testcase}")
line_comment = ""
_validate_testcase_combinations(testcase)
if (expr_stmt := testcase.get("statement", testcase.get("expression"))) is not None:
Expand Down Expand Up @@ -639,6 +640,10 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase:
assert isinstance(
dd, str
), f"The description.description field must be a string, got {dd!r}."
line_comment = extract_comment(dd)
if line_comment and dd.endswith(line_comment):
dd = dd[:-len(line_comment)].rstrip().rstrip("#").rstrip()

df = description.get("format", "text")
assert isinstance(
df, str
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- tab: "Global variable"
testcases:
- expression: "GLOBAL_VAR # The name of the global variable"
return: "GLOBAL"
description:
description: "Hallo # This is a greeting"
format: "code"
4 changes: 4 additions & 0 deletions tests/exercises/global/evaluation/plan_no_description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- tab: "Global variable"
testcases:
- expression: "GLOBAL_VAR # The name of the global variable"
return: "GLOBAL"
59 changes: 57 additions & 2 deletions tests/test_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_global_variable_yaml(
updates = assert_valid_output(result, pytestconfig)
assert updates.find_status_enum() == ["correct"]


@pytest.mark.parametrize(
"language, comment_start",
[
Expand All @@ -76,7 +75,7 @@ def test_global_comment(
language: str, comment_start: str, tmp_path: Path, pytestconfig: pytest.Config
):
conf = configuration(
pytestconfig, "global", language, tmp_path, "plan.yaml", "correct"
pytestconfig, "global", language, tmp_path, "plan_no_description.yaml", "correct"
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
Expand All @@ -87,6 +86,62 @@ def test_global_comment(
f"{comment_start} The name of the global variable"
)

@pytest.mark.parametrize(
"language, comment_start",
[
("bash", "#"),
("python", "#"),
("kotlin", "//"),
("csharp", "//"),
("java", "//"),
("c", "//"),
("javascript", "//"),
("haskell", "--"),
],
)
def test_global_no_comment(
language: str, comment_start: str, tmp_path: Path, pytestconfig: pytest.Config
):
conf = configuration(
pytestconfig, "global", language, tmp_path, "plan.yaml", "correct"
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
description = updates.find_next("start-testcase")

assert "description" in description and "description" in description["description"]
assert not description["description"]["description"].endswith(
f"{comment_start} The name of the global variable"
)

@pytest.mark.parametrize(
"language, comment_start",
[
("bash", "#"),
("python", "#"),
("kotlin", "//"),
("csharp", "//"),
("java", "//"),
("c", "//"),
("javascript", "//"),
("haskell", "--"),
],
)
def test_global_comment_description(
language: str, comment_start: str, tmp_path: Path, pytestconfig: pytest.Config
):
conf = configuration(
pytestconfig, "global", language, tmp_path, "comment_description_plan.yaml", "correct"
)
result = execute_config(conf)
updates = assert_valid_output(result, pytestconfig)
description = updates.find_next("start-testcase")

assert "description" in description and "description" in description["description"]
assert description["description"]["description"].endswith(
f"{comment_start} This is a greeting"
)


@pytest.mark.parametrize("lang", EXCEPTION_LANGUAGES)
def test_generic_exception_wrong(
Expand Down

0 comments on commit 57c3079

Please sign in to comment.