From 4a59ae9b42de3614dc688ca6a7509982d3d0ae29 Mon Sep 17 00:00:00 2001 From: Ronnie Dutta <61982285+MetRonnie@users.noreply.github.com> Date: Wed, 3 Apr 2024 17:53:28 +0100 Subject: [PATCH] Fix bad doctests `IGNORE_EXCEPTION_DETAIL` ignores the exception message, so these tests were not working as they should have been --- cylc/flow/host_select.py | 6 +++--- cylc/flow/id.py | 2 +- cylc/flow/id_cli.py | 10 ++++++---- cylc/flow/parsec/validate.py | 16 ++++++++-------- cylc/flow/scripts/cat_log.py | 12 ++++-------- cylc/flow/scripts/set.py | 23 +++++++++-------------- pytest.ini | 1 - 7 files changed, 31 insertions(+), 39 deletions(-) diff --git a/cylc/flow/host_select.py b/cylc/flow/host_select.py index 83861d043d4..383855039fa 100644 --- a/cylc/flow/host_select.py +++ b/cylc/flow/host_select.py @@ -385,7 +385,7 @@ def _simple_eval(expr, **variables): If you try to get it to do something you're not allowed to: >>> _simple_eval('open("foo")') Traceback (most recent call last): - ValueError: + ValueError: >>> _simple_eval('import sys') Traceback (most recent call last): SyntaxError: ... @@ -394,12 +394,12 @@ def _simple_eval(expr, **variables): >>> answer = 42 # only variables explicitly passed in should work >>> _simple_eval('answer') Traceback (most recent call last): - NameError: name 'a' is not defined + NameError: name 'answer' is not defined If you try to do something which doesn't make sense: >>> _simple_eval('a.b.c') # no value "a.b.c" Traceback (most recent call last): - NameError: name 'answer' is not defined + NameError: name 'a' is not defined """ node = ast.parse(expr.strip(), mode='eval') diff --git a/cylc/flow/id.py b/cylc/flow/id.py index db6d5ca8d80..cba3c483366 100644 --- a/cylc/flow/id.py +++ b/cylc/flow/id.py @@ -276,7 +276,7 @@ def pop_token(self) -> Tuple[str, str]: >>> tokens.pop_token() Traceback (most recent call last): - KeyError: No defined tokens. + KeyError: 'No defined tokens.' """ for token in reversed(IDTokens): diff --git a/cylc/flow/id_cli.py b/cylc/flow/id_cli.py index b6d2a9c4150..f8dfa10ffca 100644 --- a/cylc/flow/id_cli.py +++ b/cylc/flow/id_cli.py @@ -99,19 +99,21 @@ def _parse_cli(*ids: str) -> List[Tokens]: # errors: >>> _parse_cli('////') Traceback (most recent call last): - InputError: Invalid ID: //// + cylc.flow.exceptions.InputError: Invalid ID: //// >>> parse_back('//cycle') Traceback (most recent call last): - InputError: Relative reference must follow an incomplete one. + cylc.flow.exceptions.InputError: Relative reference must follow an + incomplete one... >>> parse_back('workflow//cycle', '//cycle') Traceback (most recent call last): - InputError: Relative reference must follow an incomplete one. + cylc.flow.exceptions.InputError: Relative reference must follow an + incomplete one... >>> parse_back('workflow///cycle/') Traceback (most recent call last): - InputError: Invalid ID: workflow///cycle/ + cylc.flow.exceptions.InputError: Invalid ID: workflow///cycle/ """ # upgrade legacy ids if required diff --git a/cylc/flow/parsec/validate.py b/cylc/flow/parsec/validate.py index d728fd79d84..29e2c8a59c9 100644 --- a/cylc/flow/parsec/validate.py +++ b/cylc/flow/parsec/validate.py @@ -340,18 +340,18 @@ def coerce_range(cls, value, keys): (1, 3) >>> ParsecValidator.coerce_range('1..3, 5', 'k') Traceback (most recent call last): - cylc.flow.parsec.exceptions.ListValueError: \ + cylc.flow.parsec.exceptions.ListValueError: (type=list) k = 1..3, 5 - (Only one min..max pair is permitted) - >>> ParsecValidator.coerce_range('1..z', None) + >>> ParsecValidator.coerce_range('1..z', 'k') Traceback (most recent call last): - cylc.flow.parsec.exceptions.ListValueError: \ - (type=list) k = 1..3, 5 - \ - (Integer range must be in the format min..max) + cylc.flow.parsec.exceptions.ListValueError: + (type=list) k = 1..z - (Integer range must be in the + format min..max) >>> ParsecValidator.coerce_range('1', 'k') Traceback (most recent call last): - cylc.flow.parsec.exceptions.ListValueError: \ - (type=list) k = 1..3, 5 - \ - (Integer range must be in the format min..max) + cylc.flow.parsec.exceptions.ListValueError: + (type=list) k = 1 - (Integer range must be in the + format min..max) """ items = cls.strip_and_unquote_list(keys, value) diff --git a/cylc/flow/scripts/cat_log.py b/cylc/flow/scripts/cat_log.py index 044384b88a7..688f51ddd35 100755 --- a/cylc/flow/scripts/cat_log.py +++ b/cylc/flow/scripts/cat_log.py @@ -211,20 +211,16 @@ def _check_fs_path(path): # bad paths >>> _check_fs_path('/a') Traceback (most recent call last): - ... - InputError: ... + cylc.flow.exceptions.InputError: ... >>> _check_fs_path('a/../b') Traceback (most recent call last): - ... - InputError: ... + cylc.flow.exceptions.InputError: ... >>> _check_fs_path('../a') Traceback (most recent call last): - ... - InputError: ... + cylc.flow.exceptions.InputError: ... >>> _check_fs_path('./a') Traceback (most recent call last): - ... - InputError: ... + cylc.flow.exceptions.InputError: ... Raises: InputError diff --git a/cylc/flow/scripts/set.py b/cylc/flow/scripts/set.py index 88e9a177c1b..4f0cd19522f 100755 --- a/cylc/flow/scripts/set.py +++ b/cylc/flow/scripts/set.py @@ -264,20 +264,17 @@ def get_prereq_opts(prereq_options: List[str]): # Error: invalid format: >>> get_prereq_opts(["fish"]) Traceback (most recent call last): - ... - InputError: + cylc.flow.exceptions.InputError: ... # Error: invalid format: >>> get_prereq_opts(["1/foo::bar"]) Traceback (most recent call last): - ... - InputError: + cylc.flow.exceptions.InputError: ... # Error: "all" must be used alone: >>> get_prereq_opts(["all", "2/foo:baz"]) Traceback (most recent call last): - ... - InputError: + cylc.flow.exceptions.InputError: ... """ prereqs = split_opts(prereq_options) @@ -318,11 +315,10 @@ def get_output_opts(output_options: List[str]): Bad: >>> get_output_opts(["required", "a"]) # "required" must be used alone Traceback (most recent call last): - InputError: - # Error: "required" must be used alone + cylc.flow.exceptions.InputError: --out=required must be used alone >>> get_output_opts(["waiting"]) # cannot "reset" to waiting Traceback (most recent call last): - InputError: + cylc.flow.exceptions.InputError: Tasks cannot be set to waiting... """ outputs = split_opts(output_options) @@ -335,7 +331,7 @@ def get_output_opts(output_options: List[str]): raise InputError("--out=required must be used alone") if "waiting" in outputs: raise InputError( - "Tasks can not be set to waiting, use a new flow to re-run" + "Tasks cannot be set to waiting, use a new flow to re-run" ) return outputs @@ -351,8 +347,7 @@ def validate_opts(output_opt: List[str], prereq_opt: List[str]): >>> validate_opts(["a"], ["1/a:failed"]) Traceback (most recent call last): - ... - InputError: + cylc.flow.exceptions.InputError: ... """ if output_opt and prereq_opt: @@ -372,10 +367,10 @@ def validate_tokens(tokens_list): Bad: >>> validate_tokens([Tokens('w//c:s')]) Traceback (most recent call last): - cylc.flow.exceptions.InputError + cylc.flow.exceptions.InputError: ... >>> validate_tokens([Tokens('w//c/t:s')]) Traceback (most recent call last): - cylc.flow.exceptions.InputError + cylc.flow.exceptions.InputError: ... """ for tokens in tokens_list: diff --git a/pytest.ini b/pytest.ini index 9be86cb507c..04d12d224b4 100644 --- a/pytest.ini +++ b/pytest.ini @@ -34,7 +34,6 @@ testpaths = tests/integration/ doctest_optionflags = NORMALIZE_WHITESPACE - IGNORE_EXCEPTION_DETAIL ELLIPSIS asyncio_mode = auto markers=