Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ testpaths = [
pythonpath = [
"tests/utils",
]
filterwarnings = [
"error",
]
6 changes: 2 additions & 4 deletions tests/rapids_pre_commit_hooks/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,11 @@ def test_fix_disabled(self):
pytest.param(
"""\
+ # prapids-pre-commit-hooks: enable
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0
: >0
+ # rapids-pre-commit-hooks: enabled
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0
+ # rapids-pre-commit-hooks: enable-next-lines
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0
+ Hello
: ~~~~~~0
: !0
""",
"test",
[True],
Expand Down
159 changes: 139 additions & 20 deletions tests/test_testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rapids_pre_commit_hooks.utils.yaml import load_with_anchors
from rapids_pre_commit_hooks_test_utils import (
ParseError,
ParseWarning,
find_yaml_node_for_span,
parse_named_spans,
zip_expected_warnings,
Expand Down Expand Up @@ -312,6 +313,42 @@
contextlib.nullcontext(),
id="joined-span-reverse",
),
pytest.param(
"""\
+ Hello
: ~~~~span1
+ world
: ~~span1
""",
dict,
"Hello\nworld\n",
{
"span1": (2, 8),
},
contextlib.nullcontext(),
id="joined-span-2-lines",
),
pytest.param(
"""\
+ Hello
: ~~~~span1
+ world
: ~~~~~~span1
+ !
: ~span1
""",
dict,
"Hello\nworld\n!\n",
{
"span1": (2, 13),
},
pytest.warns(
ParseWarning,
match=r'^Span "span1" spans 3 lines, consider using '
r">/! notation instead$",
),
id="joined-span-3-lines",
),
pytest.param(
"""\
+ Hello
Expand Down Expand Up @@ -442,6 +479,24 @@
contextlib.nullcontext(),
id="root-type-none-list",
),
pytest.param(
"""\
+ Hello
: >hello
: !hello
""",
dict,
"Hello\n",
{"hello": (0, 5)},
pytest.warns(
ParseWarning,
match=(
r'^Large span "hello" is on a single line, '
r"consider using ~ notation instead$"
),
),
id="single-line-large-span",
),
pytest.param(
"""\
+ Hello
Expand All @@ -452,7 +507,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Attempted to create non-contiguous span "span1"$',
),
id="broken-multiline-span-first",
),
pytest.param(
Expand All @@ -465,7 +523,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Attempted to create non-contiguous span "span1"$',
),
id="broken-multiline-span-second",
),
pytest.param(
Expand All @@ -477,7 +538,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Attempted to create non-contiguous span "s"$',
),
id="overlapping-span",
),
pytest.param(
Expand All @@ -488,7 +552,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^End of span "span1" overruns previous line$',
),
id="past-line-end",
),
pytest.param(
Expand All @@ -499,7 +566,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Invalid directive line character: "a"$',
),
id="invalid-before",
),
pytest.param(
Expand All @@ -510,7 +580,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Invalid directive line character: "a"$',
),
id="invalid-after",
),
pytest.param(
Expand All @@ -521,7 +594,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Invalid line start: "@ "$',
),
id="invalid-first-character",
),
pytest.param(
Expand All @@ -531,7 +607,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Invalid line start: "\+H"$',
),
id="content-missing-space",
),
pytest.param(
Expand All @@ -541,7 +620,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Invalid line start: ":\^"$',
),
id="directive-missing-space",
),
pytest.param(
Expand All @@ -553,7 +635,10 @@
list,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Path "0" is a span, but attempted to access "0\.a"$',
),
id="overwrite-span-with-dict",
),
pytest.param(
Expand All @@ -565,7 +650,10 @@
list,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Path "0" is not a span$',
),
id="overwrite-dict-with-span",
),
pytest.param(
Expand All @@ -577,7 +665,10 @@
list,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Path "0" is not a list, but got an integer key 0$',
),
id="overwrite-dict-with-list",
),
pytest.param(
Expand All @@ -589,7 +680,10 @@
list,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Path "0" is not a dict, but got a string key "a"$',
),
id="overwrite-list-with-dict",
),
pytest.param(
Expand All @@ -600,7 +694,13 @@
list,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=(
r'^List "<root>" is missing items at the following '
r"indices: 0$"
),
),
id="incomplete-list",
),
pytest.param(
Expand All @@ -611,7 +711,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r"^Expected root type to be dict, got list$",
),
id="wrong-root-type",
),
pytest.param(
Expand All @@ -621,7 +724,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^End of span "invalid" overruns previous line$',
),
id="span-on-no-content",
),
pytest.param(
Expand All @@ -632,7 +738,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^End of span "invalid" overruns previous line$',
),
id="newline-on-no-newline",
),
pytest.param(
Expand All @@ -645,20 +754,27 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Large span "s" already in progress$',
),
id="duplicate-large-span",
),
pytest.param(
"""\
+ Hello
: >s
+ world
: !s
: !s
""",
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Large span "s" not started yet$',
),
id="double-terminate-large-span",
),
pytest.param(
Expand All @@ -669,7 +785,10 @@
dict,
None,
None,
pytest.raises(ParseError),
pytest.raises(
ParseError,
match=r'^Unfinished large spans: "s"$',
),
id="unterminated-large-span",
),
],
Expand Down
Loading
Loading