Skip to content

Commit

Permalink
made small changes to the code
Browse files Browse the repository at this point in the history
  • Loading branch information
BrentBlanckaert committed Nov 15, 2024
1 parent 88904a8 commit 509a5ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
16 changes: 6 additions & 10 deletions tested/dsl/ast_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tested/dsl/translate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tested/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from tested.testsuite import parse_test_suite


import time


def run(config: DodonaConfig, judge_output: IO):
"""
Run the TESTed judge.
Expand All @@ -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:
Expand All @@ -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")

0 comments on commit 509a5ec

Please sign in to comment.