diff --git a/tested/dsl/ast_translator.py b/tested/dsl/ast_translator.py index e90a6fb6..af57e23c 100644 --- a/tested/dsl/ast_translator.py +++ b/tested/dsl/ast_translator.py @@ -27,9 +27,9 @@ """ import ast +import io import tokenize from decimal import Decimal -from io import BytesIO from typing import Literal, cast, overload from attrs import evolve @@ -342,15 +342,11 @@ def extract_comment(code: str) -> str: :param code: The code to extract the comment from. :return: The comment if it exists, otherwise an empty string. """ - tokens = tokenize.tokenize(BytesIO(code.encode("utf-8")).readline) - comments = list( - map(lambda t: t.string, filter(lambda t: t.type == tokenize.COMMENT, tokens)) - ) - if len(comments) == 0: - return "" - comment = comments[0][1:] - assert isinstance(comment, str) - return comment.strip() + comment = "" + tokens = tuple(tokenize.generate_tokens(io.StringIO(code).readline)) + if len(tokens) and tokens[-3].type == tokenize.COMMENT: + comment = tokens[-3].string.lstrip('#').strip() + return comment @overload diff --git a/tested/dsl/translate_parser.py b/tested/dsl/translate_parser.py index 6f589799..53f4810d 100644 --- a/tested/dsl/translate_parser.py +++ b/tested/dsl/translate_parser.py @@ -584,7 +584,7 @@ def _convert_testcase(testcase: YamlDict, context: DslContext) -> Testcase: the_input = LanguageLiterals(literals=the_dict, type=the_type) else: assert isinstance(expr_stmt, str) - line_comment = extract_comment(expr_stmt) + # line_comment = extract_comment(expr_stmt) the_input = parse_string(expr_stmt) return_channel = IgnoredChannel.IGNORED if "statement" in testcase else None else: diff --git a/tested/main.py b/tested/main.py index b4549028..4e3f3266 100644 --- a/tested/main.py +++ b/tested/main.py @@ -10,6 +10,9 @@ from tested.testsuite import parse_test_suite +import time + + def run(config: DodonaConfig, judge_output: IO): """ Run the TESTed judge. @@ -27,6 +30,8 @@ def run(config: DodonaConfig, judge_output: IO): ) raise e + start_time = time.time() + _, ext = os.path.splitext(config.test_suite) is_yaml = ext.lower() in (".yaml", ".yml") if is_yaml: @@ -37,3 +42,8 @@ def run(config: DodonaConfig, judge_output: IO): from .judge import judge judge(pack) + + end_time = time.time() + + with open("times.txt", "a") as myfile: + myfile.write(f"{end_time - start_time}\n")