diff --git a/judge/translator.py b/judge/translator.py index c6613bc..4590507 100755 --- a/judge/translator.py +++ b/judge/translator.py @@ -22,26 +22,12 @@ class Language(Enum): class Text(Enum): """Text message content enum.""" - ADD_A_SEMICOLON = auto() - INVALID_SINGLE_QUOTE_TABLE_NAME = auto() - SUBMISSION_WRONG_QUERY_TYPE = auto() - SUBMISSION_FORBIDDEN_SYMBOLREGEX = auto() - SUBMISSION_MANDATORY_SYMBOLREGEX = auto() - SUBMISSION_FORBIDDEN_FULLREGEX = auto() - SUBMISSION_MANDATORY_FULLREGEX = auto() - SUBMISSION_CONTAINS_MORE_QUERIES = auto() - SUBMISSION_CONTAINS_LESS_QUERIES = auto() - DIFFERENT_ROW_COUNT = auto() - DIFFERENT_COLUMN_COUNT = auto() - COMPARING_QUERY_OUTPUT_CSV_CONTENT = auto() - COMPARING_QUERY_OUTPUT_TYPES = auto() - QUERY_SHOULD_ORDER_ROWS = auto() - QUERY_SHOULD_NOT_ORDER_ROWS = auto() - ROWS_ARE_BEING_ORDERED = auto() - ROWS_ARE_NOT_BEING_ORDERED = auto() - CORRECT_ROWS_WRONG_ORDER = auto() - COMPARING_TABLE_LAYOUT = auto() - COMPARING_TABLE_CONTENT = auto() + COMPARING_IMAGES = auto() + SOLUTION_EXECUTION_ERROR = auto() + SUBMISSION_EXECUTION_ERROR = auto() + SOLUTION_TITLE = auto() + SUBMISSION_TITLE = auto() + FOREGROUND_PIXELS_CORRECT = auto() def __init__(self, language: Language) -> None: """Create Translator. @@ -136,9 +122,21 @@ def translate(self, message: Text, **kwargs: Any) -> str: text_translations = { Language.EN: { - Text.ADD_A_SEMICOLON: "Add a semicolon ';' at the end of each SQL query.", + Text.COMPARING_IMAGES: "Comparing images", + Text.SOLUTION_EXECUTION_ERROR: "Error executing solution script:\n {error}", + Text.SUBMISSION_EXECUTION_ERROR: "Error executing submission script:\n {error}", + Text.SOLUTION_TITLE: "Submission:", + Text.SUBMISSION_TITLE: "Solution:", + Text.FOREGROUND_PIXELS_CORRECT: "{correct_pixels}/{total_pixels} " + "({fraction:.1%}) visible pixels correct", }, Language.NL: { - Text.ADD_A_SEMICOLON: "Voeg een puntkomma ';' toe aan het einde van elke SQL query.", + Text.COMPARING_IMAGES: "Afbeeldingen vergelijken", + Text.SOLUTION_EXECUTION_ERROR: "Error bij het uitvoeren van het oplossingsscript:\n {error}", + Text.SUBMISSION_EXECUTION_ERROR: "Error bij het uitvoeren van het ingediende script:\n {error}", + Text.SOLUTION_TITLE: "Indiening:", + Text.SUBMISSION_TITLE: "Oplossing:", + Text.FOREGROUND_PIXELS_CORRECT: "{correct_pixels}/{total_pixels} " + "({fraction:.1%}) zichtbare pixels correct", }, } diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_dir_read.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_dir_read.stdout index 18681ad..613a292 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_dir_read.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_dir_read.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,8 +18,8 @@ { "command": "append-message", "message": { - "description": "Error executing submission script: ''NoneType' object is not callable'.", - "format": "text" + "description": "Error bij het uitvoeren van het oplossingsscript:\n 'NoneType' object is not callable", + "format": "code" } } { diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_error.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_error.stdout index cb771c9..6c21486 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_error.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_error.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,8 +18,8 @@ { "command": "append-message", "message": { - "description": "Error executing submission script: 'name 'i' is not defined'.", - "format": "text" + "description": "Error bij het uitvoeren van het oplossingsscript:\n name 'i' is not defined", + "format": "code" } } { diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_exit.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_exit.stdout index 3600cbc..3639c0c 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_exit.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_exit.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,8 +18,8 @@ { "command": "append-message", "message": { - "description": "Error executing submission script: '1'.", - "format": "text" + "description": "Error bij het uitvoeren van het oplossingsscript:\n 1", + "format": "code" } } { diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_noImport.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_noImport.stdout index c7c2cde..01a9115 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_noImport.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_noImport.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "400/400 (100.0%) foreground pixels correct" + "expected": "400/400 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "0/400 (0.0%) foreground pixels correct", + "generated": "0/400 (0.0%) zichtbare pixels correct", "status": { "enum": "wrong", "human": "Test gefaald" diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_non_transparent.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_non_transparent.stdout index 3cdf66b..5aed8da 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_non_transparent.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_non_transparent.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "400/400 (100.0%) foreground pixels correct" + "expected": "400/400 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "0/100000 (0.0%) foreground pixels correct", + "generated": "0/100000 (0.0%) zichtbare pixels correct", "status": { "enum": "wrong", "human": "Test gefaald" diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_print.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_print.stdout index d42656a..7b9029b 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_print.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_print.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "400/400 (100.0%) foreground pixels correct" + "expected": "400/400 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "400/400 (100.0%) foreground pixels correct", + "generated": "400/400 (100.0%) zichtbare pixels correct", "status": { "enum": "correct", "human": "Alle testen geslaagd" diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_sleep.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_sleep.stdout index c7c2cde..01a9115 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_sleep.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_sleep.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "400/400 (100.0%) foreground pixels correct" + "expected": "400/400 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "0/400 (0.0%) foreground pixels correct", + "generated": "0/400 (0.0%) zichtbare pixels correct", "status": { "enum": "wrong", "human": "Test gefaald" diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_solution.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_solution.stdout index d42656a..7b9029b 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_solution.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_solution.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "400/400 (100.0%) foreground pixels correct" + "expected": "400/400 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "400/400 (100.0%) foreground pixels correct", + "generated": "400/400 (100.0%) zichtbare pixels correct", "status": { "enum": "correct", "human": "Alle testen geslaagd" diff --git a/tests/e2e_stdout/test-turtle-judge/oef1_syntaxError.stdout b/tests/e2e_stdout/test-turtle-judge/oef1_syntaxError.stdout index c347548..1732c7d 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef1_syntaxError.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef1_syntaxError.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,8 +18,8 @@ { "command": "append-message", "message": { - "description": "Error executing submission script: 'unterminated string literal (detected at line 2) (, line 2)'.", - "format": "text" + "description": "Error bij het uitvoeren van het oplossingsscript:\n unterminated string literal (detected at line 2) (, line 2)", + "format": "code" } } { diff --git a/tests/e2e_stdout/test-turtle-judge/oef2_solution.stdout b/tests/e2e_stdout/test-turtle-judge/oef2_solution.stdout index 270418f..30498e1 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef2_solution.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef2_solution.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "20/20 (100.0%) foreground pixels correct" + "expected": "20/20 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "20/20 (100.0%) foreground pixels correct", + "generated": "20/20 (100.0%) zichtbare pixels correct", "status": { "enum": "correct", "human": "Alle testen geslaagd" diff --git a/tests/e2e_stdout/test-turtle-judge/oef3_solution.stdout b/tests/e2e_stdout/test-turtle-judge/oef3_solution.stdout index 71679d0..fcb8c70 100644 --- a/tests/e2e_stdout/test-turtle-judge/oef3_solution.stdout +++ b/tests/e2e_stdout/test-turtle-judge/oef3_solution.stdout @@ -3,7 +3,7 @@ } { "command": "start-tab", - "title": "Comparing PNGs" + "title": "Afbeeldingen vergelijken" } { "command": "start-context" @@ -18,14 +18,14 @@ { "command": "start-test", "description": { - "description": "

Submission:

\"submission

Solution:

\"solution
", + "description": "

Oplossing:

\"submission

Indiening:

\"solution
", "format": "html" }, - "expected": "10000/10000 (100.0%) foreground pixels correct" + "expected": "10000/10000 (100.0%) zichtbare pixels correct" } { "command": "close-test", - "generated": "0/10000 (0.0%) foreground pixels correct", + "generated": "0/10000 (0.0%) zichtbare pixels correct", "status": { "enum": "wrong", "human": "Test gefaald" diff --git a/tests/test_translator.py b/tests/test_translator.py index d655434..9df4407 100644 --- a/tests/test_translator.py +++ b/tests/test_translator.py @@ -11,13 +11,13 @@ class TestTranslator(unittest.TestCase): def test_translate(self): self.assertEqual( - Translator.from_str("nl").translate(Translator.Text.ADD_A_SEMICOLON), - "Voeg een puntkomma ';' toe aan het einde van elke SQL query.", + Translator.from_str("nl").translate(Translator.Text.COMPARING_IMAGES), + "Afbeeldingen vergelijken", ) self.assertEqual( - Translator.from_str("en").translate(Translator.Text.ADD_A_SEMICOLON), - "Add a semicolon ';' at the end of each SQL query.", + Translator.from_str("en").translate(Translator.Text.COMPARING_IMAGES), + "Comparing images", ) def test_human_error(self): diff --git a/turtle_judge.py b/turtle_judge.py index 707ae8d..a9027b9 100755 --- a/turtle_judge.py +++ b/turtle_judge.py @@ -45,28 +45,28 @@ format=MessageFormat.TEXT, ) - with Tab("Comparing PNGs"): + with Tab(config.translator.translate(Translator.Text.COMPARING_IMAGES)): with Context(), TestCase( format=MessageFormat.PYTHON, description="", ): try: svg_submission = generate_svg_byte_stream(config.source, config.canvas_width, config.canvas_height) - except BaseException as e: + except BaseException as error: raise DodonaException( config.translator.error_status(ErrorType.COMPILATION_ERROR), - description=f"Error executing submission script: '{e}'.", - format=MessageFormat.TEXT, - ) from e + description=config.translator.translate(Translator.Text.SOLUTION_EXECUTION_ERROR, error=error), + format=MessageFormat.CODE, + ) from error try: svg_solution = generate_svg_byte_stream(config.solution_file, config.canvas_width, config.canvas_height) - except BaseException as e: + except BaseException as error: raise DodonaException( config.translator.error_status(ErrorType.COMPILATION_ERROR), permission=MessagePermission.STAFF, - description=f"Error executing solution script: '{e}'.", - format=MessageFormat.TEXT, - ) from e + description=config.translator.translate(Translator.Text.SUBMISSION_EXECUTION_ERROR, error=error), + format=MessageFormat.CODE, + ) from error png_submission = generate_png_image(svg_submission, config.canvas_width, config.canvas_height) png_solution = generate_png_image(svg_solution, config.canvas_width, config.canvas_height) @@ -78,14 +78,14 @@ html = f"""
-

Submission:

+

{config.translator.translate(Translator.Text.SUBMISSION_TITLE)}

submission result
-

Solution:

+

{config.translator.translate(Translator.Text.SOLUTION_TITLE)}