Skip to content

Commit

Permalink
Fix bad doctests
Browse files Browse the repository at this point in the history
`IGNORE_EXCEPTION_DETAIL` ignores the exception message, so these tests were not working as they should have been
  • Loading branch information
MetRonnie committed Apr 3, 2024
1 parent 6ba2f8c commit 4a59ae9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 39 deletions.
6 changes: 3 additions & 3 deletions cylc/flow/host_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <class '_ast.Call'>
ValueError: <class '...Call'>
>>> _simple_eval('import sys')
Traceback (most recent call last):
SyntaxError: ...
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion cylc/flow/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def pop_token(self) -> Tuple[str, str]:
<id: >
>>> tokens.pop_token()
Traceback (most recent call last):
KeyError: No defined tokens.
KeyError: 'No defined tokens.'
"""
for token in reversed(IDTokens):
Expand Down
10 changes: 6 additions & 4 deletions cylc/flow/id_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions cylc/flow/parsec/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions cylc/flow/scripts/cat_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions cylc/flow/scripts/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ testpaths =
tests/integration/
doctest_optionflags =
NORMALIZE_WHITESPACE
IGNORE_EXCEPTION_DETAIL
ELLIPSIS
asyncio_mode = auto
markers=
Expand Down

0 comments on commit 4a59ae9

Please sign in to comment.