Skip to content

Commit

Permalink
filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Jan 22, 2025
1 parent c5477bc commit a4d6f07
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def component_check_command(
**global_options: object,
) -> None:
"""Check component files against their schemas, showing validation errors."""
resolved_paths = [Path(path).absolute() for path in paths]
top_level_component_validator = Draft202012Validator(schema=COMPONENT_FILE_SCHEMA)

cli_config = normalize_cli_config(global_options, context)
Expand All @@ -286,6 +287,11 @@ def component_check_command(
for component_dir in (
dg_context.root_path / dg_context.root_package_name / "components"
).iterdir():
if resolved_paths and not any(
path == component_dir or path in component_dir.parents for path in resolved_paths
):
continue

component_path = component_dir / "component.yaml"

if component_path.exists():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from pathlib import Path

import pytest
from dagster._core.test_utils import new_cwd
from dagster_components.utils import ensure_dagster_components_tests_import
from dagster_components_tests.integration_tests.validation_tests.test_cases import (
BASIC_INVALID_VALUE,
BASIC_MISSING_VALUE,
COMPONENT_VALIDATION_TEST_CASES,
ComponentValidationTestCase,
)
Expand Down Expand Up @@ -41,81 +45,67 @@ def test_validation_cli(test_case: ComponentValidationTestCase) -> None:
assert result.exit_code == 0


# @pytest.mark.parametrize(
# "scope_check_run",
# [True, False],
# )
# def test_validation_cli_multiple_components(scope_check_run: bool) -> None:
# """Ensure that the check CLI can validate multiple components in a single code location, and
# that error messages from all components are displayed.

# The parameter `scope_check_run` determines whether the check CLI is run pointing at both
# components or none (defaulting to the entire workspace) - the output should be the same in
# either case, this just tests that the CLI can handle multiple filters.
# """
# runner = CliRunner()

# with create_code_location_from_components(
# BASIC_MISSING_VALUE.component_path,
# BASIC_INVALID_VALUE.component_path,
# local_component_defn_to_inject=BASIC_MISSING_VALUE.component_type_filepath,
# ) as tmpdir:
# with new_cwd(str(tmpdir)):
# result = runner.invoke(
# cli,
# [
# "--builtin-component-lib",
# "dagster_components.test",
# "check",
# "component",
# *(
# [
# str(
# Path("my_location") / "components" / "basic_component_missing_value"
# ),
# str(
# Path("my_location") / "components" / "basic_component_invalid_value"
# ),
# ]
# if scope_check_run
# else []
# ),
# ],
# catch_exceptions=False,
# )
# assert result.exit_code != 0, str(result.stdout)
@pytest.mark.parametrize(
"scope_check_run",
[True, False],
)
def test_validation_cli_multiple_components(scope_check_run: bool) -> None:
"""Ensure that the check CLI can validate multiple components in a single code location, and
that error messages from all components are displayed.
# assert BASIC_INVALID_VALUE.validate_error_msg and BASIC_MISSING_VALUE.validate_error_msg
# BASIC_INVALID_VALUE.validate_error_msg(str(result.stdout))
# BASIC_MISSING_VALUE.validate_error_msg(str(result.stdout))
The parameter `scope_check_run` determines whether the check CLI is run pointing at both
components or none (defaulting to the entire workspace) - the output should be the same in
either case, this just tests that the CLI can handle multiple filters.
"""
with (
ProxyRunner.test() as runner,
create_code_location_from_components(
BASIC_MISSING_VALUE.component_path,
BASIC_INVALID_VALUE.component_path,
local_component_defn_to_inject=BASIC_MISSING_VALUE.component_type_filepath,
) as tmpdir,
):
with new_cwd(str(tmpdir)):
result = runner.invoke(
"component",
"check",
*(
[
str(Path("my_location") / "components" / "basic_component_missing_value"),
str(Path("my_location") / "components" / "basic_component_invalid_value"),
]
if scope_check_run
else []
),
)
assert result.exit_code != 0, str(result.stdout)

assert BASIC_INVALID_VALUE.check_error_msg and BASIC_MISSING_VALUE.check_error_msg
BASIC_INVALID_VALUE.check_error_msg(str(result.stdout))
BASIC_MISSING_VALUE.check_error_msg(str(result.stdout))

# def test_validation_cli_multiple_components_filter() -> None:
# """Ensure that the check CLI filters components to validate based on the provided paths."""
# runner = CliRunner()

# with create_code_location_from_components(
# BASIC_MISSING_VALUE.component_path,
# BASIC_INVALID_VALUE.component_path,
# local_component_defn_to_inject=BASIC_MISSING_VALUE.component_type_filepath,
# ) as tmpdir:
# with new_cwd(str(tmpdir)):
# result = runner.invoke(
# cli,
# [
# "--builtin-component-lib",
# "dagster_components.test",
# "check",
# "component",
# str(Path("my_location") / "components" / "basic_component_missing_value"),
# ],
# catch_exceptions=False,
# )
# assert result.exit_code != 0, str(result.stdout)
def test_validation_cli_multiple_components_filter() -> None:
"""Ensure that the check CLI filters components to validate based on the provided paths."""
with (
ProxyRunner.test() as runner,
create_code_location_from_components(
BASIC_MISSING_VALUE.component_path,
BASIC_INVALID_VALUE.component_path,
local_component_defn_to_inject=BASIC_MISSING_VALUE.component_type_filepath,
) as tmpdir,
):
with new_cwd(str(tmpdir)):
result = runner.invoke(
"component",
"check",
str(Path("my_location") / "components" / "basic_component_missing_value"),
)
assert result.exit_code != 0, str(result.stdout)

# assert BASIC_INVALID_VALUE.validate_error_msg and BASIC_MISSING_VALUE.validate_error_msg
assert BASIC_INVALID_VALUE.check_error_msg and BASIC_MISSING_VALUE.check_error_msg

# BASIC_MISSING_VALUE.validate_error_msg(str(result.stdout))
# # We exclude the invalid value test case
# with pytest.raises(AssertionError):
# BASIC_INVALID_VALUE.validate_error_msg(str(result.stdout))
BASIC_MISSING_VALUE.check_error_msg(str(result.stdout))
# We exclude the invalid value test case
with pytest.raises(AssertionError):
BASIC_INVALID_VALUE.check_error_msg(str(result.stdout))

0 comments on commit a4d6f07

Please sign in to comment.