From 88904a8421d6041bc79310b6b20995b17b706293 Mon Sep 17 00:00:00 2001 From: breblanc Date: Fri, 25 Oct 2024 17:16:14 +0200 Subject: [PATCH] Fixed linting issues and removed comments when provided comment is an empty string --- tested/dsl/ast_translator.py | 9 ++++++--- tested/languages/generation.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tested/dsl/ast_translator.py b/tested/dsl/ast_translator.py index 7ffe405a..e90a6fb6 100644 --- a/tested/dsl/ast_translator.py +++ b/tested/dsl/ast_translator.py @@ -334,6 +334,7 @@ def _translate_to_ast(node: ast.Interactive, is_return: bool) -> Statement: else: return _convert_statement(statement_or_expression) + def extract_comment(code: str) -> str: """ Extract the comment from the code. @@ -341,15 +342,17 @@ 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))) + 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() + @overload def parse_string(code: str, is_return: Literal[True]) -> Value: ... diff --git a/tested/languages/generation.py b/tested/languages/generation.py index 866ad30b..7be0d2e3 100644 --- a/tested/languages/generation.py +++ b/tested/languages/generation.py @@ -151,7 +151,8 @@ def get_readable_input( text = case.input.get_for(bundle.config.programming_language) format_ = bundle.config.programming_language - text = f"{text} {bundle.language.comment(case.line_comment)}" + if case.line_comment: + text = f"{text} {bundle.language.comment(case.line_comment)}" # If there are no files, return now. This means we don't need to do ugly stuff. if not case.link_files: