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
77 changes: 61 additions & 16 deletions tests/rapids_pre_commit_hooks/dependencies/test_cuda_suffixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ def test_handle_output_type(self, output_type, expected):
assert context.has_python_output_type is True

def test_handle_common(self):
composed, _ = load_with_anchors(
content, spans = parse_named_spans(
"""\
common:
packages: []
+ common:
: ~~~~~~common_key
+ packages: []
: ~~~~~~~~~~~~~common
"""
)
common_key, common = composed.value[0]
composed, _ = load_with_anchors(content)
common_key = find_yaml_node_for_span(composed, spans["common_key"])
common = find_yaml_node_for_span(composed, spans["common"])

handler = CUDASuffixedHandler(Mock(), Mock())
with handler.handle_common(Mock(), common_key, common) as context:
Expand All @@ -71,13 +75,16 @@ def test_handle_common(self):
+ common:
: ~~~~~~warnings.0.notes.0
: ~~~~~~warnings.1.notes.0
: ~~~~~~common_key
+ packages:
: >common
+ - package-cu12
: ~~~~~~~~~~~~suffixed.0
: ~~~~~~~~~~~~warnings.0.warning
: ~~~~~~~~~~~~suffixed.0
+ - package
: ~~~~~~~unsuffixed.0
: ~~~~~~~warnings.1.warning
: ~~~~~~~unsuffixed.0
: !common
""",
True,
["package"],
Expand Down Expand Up @@ -105,11 +112,14 @@ def test_handle_common(self):
pytest.param(
"""\
+ common:
: ~~~~~~common_key
+ packages:
: >common
+ - package-cu12
: ~~~~~~~~~~~~suffixed.0
+ - package
: ~~~~~~~unsuffixed.0
: !common
""",
False,
["package"],
Expand All @@ -120,7 +130,9 @@ def test_handle_common(self):
pytest.param(
"""\
+ common:
: ~~~~~~common_key
+ packages: []
: ~~~~~~~~~~~~~common
""",
True,
[],
Expand All @@ -140,7 +152,8 @@ def test_handle_common_item(
):
content, spans = parse_named_spans(content, dict)
composed, _ = load_with_anchors(content)
common_key, common = composed.value[0]
common_key = find_yaml_node_for_span(composed, spans["common_key"])
common = find_yaml_node_for_span(composed, spans["common"])
linter = lint.Linter(
"dependencies.yaml", content, "verify-dependencies"
)
Expand Down Expand Up @@ -676,10 +689,12 @@ def test_handle_matrix(self):
+ matrix:
: ~~~~~~matrix_key
+ cuda_suffixed: "true"
: ~~~~~~~~~~~~~~~~~~~~~~matrix
"""
)
composed, _ = load_with_anchors(content)
matrix_key, matrix = composed.value[0]
matrix_key = find_yaml_node_for_span(composed, spans["matrix_key"])
matrix = find_yaml_node_for_span(composed, spans["matrix"])
context = CUDASuffixedHandler.MatricesItemContext()
handler = CUDASuffixedHandler(Mock(), Mock())

Expand All @@ -701,55 +716,83 @@ def test_handle_matrix(self):
],
[
pytest.param(
'cuda_suffixed: "true"',
"""\
+ cuda_suffixed: "true"
: ~~~~~~~~~~~~~key
: ~~~~~~value
""",
True,
True,
None,
False,
id="cuda-suffixed-true",
),
pytest.param(
'cuda_suffixed: "false"',
"""\
+ cuda_suffixed: "false"
: ~~~~~~~~~~~~~key
: ~~~~~~~value
""",
False,
True,
None,
False,
id="cuda-suffixed-false",
),
pytest.param(
'cuda_suffixed: "other"',
"""\
+ cuda_suffixed: "other"
: ~~~~~~~~~~~~~key
: ~~~~~~~value
""",
None,
True,
None,
False,
id="cuda-suffixed-other",
),
pytest.param(
'cuda: "12.8"',
"""\
+ cuda: "12.8"
: ~~~~key
: ~~~~~~value
""",
None,
False,
12,
True,
id="cuda-version",
),
pytest.param(
'cuda: "12.*"',
"""\
+ cuda: "12.*"
: ~~~~key
: ~~~~~~value
""",
None,
False,
12,
True,
id="cuda-version-wildcard",
),
pytest.param(
'cuda: "invalid"',
"""\
+ cuda: "invalid"
: ~~~~key
: ~~~~~~~~~value
""",
None,
False,
None,
False,
id="cuda-version-invalid",
),
pytest.param(
'other: "value"',
"""\
+ other: "value"
: ~~~~~key
: ~~~~~~~value
""",
None,
False,
None,
Expand All @@ -766,8 +809,10 @@ def test_handle_matrix_item(
expected_cuda_major,
has_cuda_node,
):
content, spans = parse_named_spans(content)
composed, _ = load_with_anchors(content)
key, value = composed.value[0]
key = find_yaml_node_for_span(composed, spans["key"])
value = find_yaml_node_for_span(composed, spans["value"])
context = CUDASuffixedHandler.MatricesItemContext()
handler = CUDASuffixedHandler(Mock(), Mock())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rapids_pre_commit_hooks.utils import dependencies_yaml
from rapids_pre_commit_hooks.utils.yaml import load_with_anchors
from rapids_pre_commit_hooks_test_utils import (
find_yaml_node_for_span,
parse_named_spans,
zip_expected_warnings,
)
Expand All @@ -27,15 +28,18 @@ class TestNamingConventionsHandler:
+ wrong_name:
: ~~~~~~~~~~warnings.0.warning
: ~~~~~~~~~~warnings.0.replacements.0
: ~~~~~~~~~~file_key
+ output: pyproject
: ~~~~~~~~~warnings.0.notes.0
: >file_value
+ pyproject_dir: python/dask-cuda
: ~~~~~~~~~~~~~~~~warnings.0.notes.1
+ extras:
+ table: project.optional-dependencies
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~warnings.0.notes.2
+ key: test
: ~~~~warnings.0.notes.3
: !file_value
""",
[
{
Expand All @@ -58,13 +62,16 @@ class TestNamingConventionsHandler:
+ wrong_name:
: ~~~~~~~~~~warnings.0.warning
: ~~~~~~~~~~warnings.0.replacements.0
: ~~~~~~~~~~file_key
+ output: pyproject
: ~~~~~~~~~warnings.0.notes.0
: >file_value
+ pyproject_dir: python/dask-cuda
: ~~~~~~~~~~~~~~~~warnings.0.notes.1
+ extras:
+ table: project
: ~~~~~~~warnings.0.notes.2
: !file_value
""",
[
{
Expand All @@ -84,10 +91,13 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/dask-cuda
+ extras:
+ table: unknown
: !file_value
""",
[],
id="mismatched-table",
Expand All @@ -96,11 +106,14 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/dask-cuda
+ extras:
+ table: project.optional-dependencies
+ key: docs
: !file_value
""",
[],
id="mismatched-key",
Expand All @@ -109,10 +122,13 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: requirements
: >file_value
+ pyproject_dir: python/dask-cuda
+ extras:
+ table: project
: !file_value
""",
[],
id="non-pyproject-output",
Expand All @@ -121,10 +137,13 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/
+ extras:
+ table: project
: !file_value
""",
[],
id="empty-python-dir",
Expand All @@ -133,9 +152,12 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ extras:
+ table: project
: !file_value
""",
[],
id="no-pyproject-dir",
Expand All @@ -144,8 +166,11 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ wrong_name:
: ~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/dask-cuda
: !file_value
""",
[],
id="no-extras-table",
Expand All @@ -154,10 +179,13 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ py_run_dask_cuda:
: ~~~~~~~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/dask-cuda
+ extras:
+ table: project
: !file_value
""",
[],
id="correct-naming-convention-without-key",
Expand All @@ -166,11 +194,14 @@ class TestNamingConventionsHandler:
"""\
+ files:
+ py_test_dask_cuda:
: ~~~~~~~~~~~~~~~~~file_key
+ output: pyproject
: >file_value
+ pyproject_dir: python/dask-cuda
+ extras:
+ table: project.optional-dependencies
+ key: test
: !file_value
""",
[],
id="correct-naming-convention-with-key",
Expand All @@ -180,8 +211,8 @@ class TestNamingConventionsHandler:
def test_handle_files_item(self, content, expected_warnings):
content, spans = parse_named_spans(content, dict)
root, _ = load_with_anchors(content)
files = root.value[0][1]
file_key, file_value = files.value[0]
file_key = find_yaml_node_for_span(root, spans["file_key"])
file_value = find_yaml_node_for_span(root, spans["file_value"])
file_fields = {key.value: value for key, value in file_value.value}
extras_fields = (
{key.value: value for key, value in file_fields["extras"].value}
Expand Down
Loading
Loading