diff --git a/tests/parse/templates.py b/tests/parse/templates.py index c108c1e..d718e18 100644 --- a/tests/parse/templates.py +++ b/tests/parse/templates.py @@ -6,7 +6,7 @@ from src.parse import ParseErrorException from src.token import TokenStream -from tests.parse.test_parse import static_parse_context +from tests.parse.test_error import static_parse_context from tests.test_token import static_token_by_value diff --git a/tests/parse/test_conditional.py b/tests/parse/test_conditional.py index bb2defc..070d88d 100644 --- a/tests/parse/test_conditional.py +++ b/tests/parse/test_conditional.py @@ -56,7 +56,7 @@ draw_token_random, static_token_by_value, ) -from tests.parse.test_parse import static_parse_context +from tests.parse.test_error import static_parse_context # # Helper functions diff --git a/tests/parse/test_directive.py b/tests/parse/test_directive.py index bdc4859..edc4cb0 100644 --- a/tests/parse/test_directive.py +++ b/tests/parse/test_directive.py @@ -41,7 +41,7 @@ draw_token_unknown, static_token_by_value, ) -from tests.parse.test_parse import static_parse_context +from tests.parse.test_error import static_parse_context # # Helper functions diff --git a/tests/parse/test_error.py b/tests/parse/test_error.py new file mode 100644 index 0000000..5df69c1 --- /dev/null +++ b/tests/parse/test_error.py @@ -0,0 +1,84 @@ +# SPDX-License-Identifier: LGPL-2.1-only +# Copyright 2022 Jookia + +from hypothesis.strategies import composite, sampled_from, text + +from src.parse import ( + ParseContext, + ParseError, + ParseErrorException, + ParseTask, +) +from tests.templates import template_test_structure +from tests.test_token import draw_token_random, static_token + +# +# Helper functions +# + + +# Draws a random parse task +@composite +def draw_parse_task(draw): + return draw(sampled_from(list(ParseTask))) + + +# Draws a random parse context without a parent +@composite +def draw_parse_context(draw): + task = draw(draw_parse_task()) + token = draw(draw_token_random()) + return ParseContext(task, token, None) + + +# Static parse context +def static_parse_context(): + task = ParseTask.TEST_TASK + token = static_token() + return ParseContext(task, token, None) + + +# Draws a random parse error +@composite +def draw_parse_error(draw): + return draw(sampled_from(list(ParseError))) + + +# Draws a random parse error exception +@composite +def draw_parse_error_exception(draw): + error = draw(draw_parse_error()) + token = draw(draw_token_random()) + expected = draw(text()) + context = draw(draw_parse_context()) + return ParseErrorException(error, token, expected, context) + + +# +# Test functions +# + + +# Test parse context structure +@template_test_structure( + ParseContext, + draw_parse_context(), + task=draw_parse_task(), + token=draw_token_random(), + parent=text(), +) +def test_parse_context_structure(): + pass + + +# Test parse error exception structure +@template_test_structure( + ParseErrorException, + draw_parse_error_exception(), + error=draw_token_random(), + token=draw_token_random(), + expected=text(), + context=draw_parse_context(), +) +def test_parse_error_exception_structure(): + pass diff --git a/tests/parse/test_file.py b/tests/parse/test_file.py index c7ce368..a68a9ce 100644 --- a/tests/parse/test_file.py +++ b/tests/parse/test_file.py @@ -37,7 +37,7 @@ draw_token_random, static_token_by_value, ) -from tests.parse.test_parse import static_parse_context +from tests.parse.test_error import static_parse_context # # Helper functions diff --git a/tests/parse/test_parse.py b/tests/parse/test_parse.py index 2ffa53d..2725beb 100644 --- a/tests/parse/test_parse.py +++ b/tests/parse/test_parse.py @@ -2,87 +2,17 @@ # Copyright 2022 Jookia from hypothesis import given -from hypothesis.strategies import ( - composite, - lists, - sampled_from, - text, -) +from hypothesis.strategies import lists from src.parse import ( NoteSkipper, - ParseError, ParseErrorException, - ParseTask, - ParseContext, Parser, parse, ) from src.token import TokenStream -from tests.templates import template_test_structure -from tests.test_token import draw_token_random, static_token - - -# Draws a random parse task -@composite -def draw_parse_task(draw): - return draw(sampled_from(list(ParseTask))) - - -# Draws a random parse context without a parent -@composite -def draw_parse_context(draw): - task = draw(draw_parse_task()) - token = draw(draw_token_random()) - return ParseContext(task, token, None) - - -# Static parse context -def static_parse_context(): - task = ParseTask.TEST_TASK - token = static_token() - return ParseContext(task, token, None) - - -# Test parse context structure -@template_test_structure( - ParseContext, - draw_parse_context(), - task=draw_parse_task(), - token=draw_token_random(), - parent=text(), -) -def test_parse_context_structure(): - pass - - -# Draws a random parse error -@composite -def draw_parse_error(draw): - return draw(sampled_from(list(ParseError))) - - -# Draws a random parse error exception -@composite -def draw_parse_error_exception(draw): - error = draw(draw_parse_error()) - token = draw(draw_token_random()) - expected = draw(text()) - context = draw(draw_parse_context()) - return ParseErrorException(error, token, expected, context) - - -# Test parse error exception structure -@template_test_structure( - ParseErrorException, - draw_parse_error_exception(), - error=draw_token_random(), - token=draw_token_random(), - expected=text(), - context=draw_parse_context(), -) -def test_parse_error_exception_structure(): - pass +from tests.test_token import draw_token_random +from tests.parse.test_error import draw_parse_context # Tests the parser wrapper works correctly diff --git a/tests/parse/test_set.py b/tests/parse/test_set.py index e200200..809c4c2 100644 --- a/tests/parse/test_set.py +++ b/tests/parse/test_set.py @@ -55,7 +55,7 @@ draw_token_unknown, static_token_by_value, ) -from tests.parse.test_parse import static_parse_context +from tests.parse.test_error import static_parse_context # # Helper functions