Repository: kedro-org/kedro
File: tests/pipeline/test_node.py (Python)

Code before:
                func=self.dummy_function,
                inputs="input.dataset",
                outputs="output_dataset",
            )

    def test_invalid_outputs_with_dot_no_namespace(self):
        """Test that outputs with '.' but no namespace raise a ValueError."""
        with pytest.raises(ValueError, match="Invalid dataset name 'output.dataset'"):
            node(
                func=self.dummy_function,
                inputs="input_dataset",
                outputs="output.dataset",
            )

    def test_valid_multi_level_namespace(self):
        """Test that multi-level namespaces are accepted."""
        n = node(
            func=self.dummy_function,
            inputs="namespace.subnamespace.input_dataset",
            outputs="namespace.subnamespace.output_dataset",
            namespace="namespace.subnamespace",
        )
        assert n.inputs == ["namespace.subnamespace.input_dataset"]
        assert n.outputs == ["namespace.subnamespace.output_dataset"]

    def test_only_top_level_namespace_match(self):
        """Test that node level namespace specification doesn't throw the error."""
        n = node(
            func=self.dummy_function,
            inputs="namespace.input_dataset",
            outputs="namespace.output_dataset",
            namespace="namespace.other",
        )
        assert n.inputs == ["namespace.input_dataset"]
        assert n.outputs == ["namespace.output_dataset"]

    def test_mismatched_namespace(self):
        """Test that mismatched namespaces in inputs and outputs raise a ValueError."""
        with pytest.raises(
            ValueError, match="Invalid dataset name 'other_namespace.output_dataset'"
        ):
            node(
                func=self.dummy_function,
                inputs="namespace.input_dataset",
                outputs="other_namespace.output_dataset",
                namespace="namespace",
            )


Review comment (suggestion):
```suggestion
    def test_dataset_namespace_matches_pipeline_namespace(self):
```

Code after:
        assert n.outputs == ["output_dataset"]

    def test_invalid_inputs_with_dot_no_namespace(self):
        """Test that inputs with '.' but no namespace raise a ValueError."""
        with pytest.warns(
            UserWarning, match="Dataset name 'input.dataset' contains '.' characters"
        ):
            node(
                func=self.dummy_function,
                inputs="input.dataset",
                outputs="output_dataset",
            )

    def test_invalid_outputs_with_dot_no_namespace(self):
        """Test that outputs with '.' but no namespace raise a ValueError."""
        with pytest.warns(
            UserWarning, match="Dataset name 'output.dataset' contains '.' characters"
        ):
            node(
                func=self.dummy_function,
                inputs="input_dataset",
                outputs="output.dataset",
            )

    def test_valid_multi_level_namespace(self):
        """Test that multi-level namespaces are accepted."""
        n = node(
            func=self.dummy_function,
            inputs="namespace.subnamespace.input_dataset",
            outputs="namespace.subnamespace.output_dataset",
            namespace="namespace.subnamespace",
        )
        assert n.inputs == ["namespace.subnamespace.input_dataset"]
        assert n.outputs == ["namespace.subnamespace.output_dataset"]

    def test_dataset_namespace_matches_pipeline_namespace(self):
        """Test that node level namespace specification doesn't throw the error."""
        n = node(
            func=self.dummy_function,
            inputs="namespace.input_dataset",
            outputs="namespace.output_dataset",
            namespace="namespace.other",
        )
        assert n.inputs == ["namespace.input_dataset"]
        assert n.outputs == ["namespace.output_dataset"]

    def test_mismatched_namespace(self):
        """Test that mismatched namespaces in inputs and outputs raise a UserWarning."""
        with pytest.warns(
            UserWarning,
            match="Dataset name 'other_namespace.output_dataset' contains '.' characters",