Skip to content

Commit ccf92f4

Browse files
committed
adding tests
1 parent 7dbc5ac commit ccf92f4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

tests/unit/project/test_project.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,74 @@ def test_project_get_from_storage(project, mocker):
378378
result,
379379
same_instance(project.storage_configuration.initialize_by_name.return_value),
380380
)
381+
382+
383+
def test_get_pipelines_schema_single_pipeline(project, mocker):
384+
"""Test filtering schema for a single pipeline."""
385+
mock_schema = mocker.Mock(spec=Schema)
386+
387+
# Mock the pipeline initialization to avoid file system dependencies
388+
mocker.patch.object(project.__class__, "make_schema", return_value=mock_schema)
389+
mock_pipeline_init = mocker.patch(
390+
"nodestream.project.pipeline_definition.PipelineDefinition.initialize_for_introspection"
391+
)
392+
mock_pipeline = mocker.Mock()
393+
mock_pipeline.expand_schema = mocker.Mock()
394+
mock_pipeline_init.return_value = mock_pipeline
395+
396+
result = project.get_pipelines_schema(["test"])
397+
398+
# Verify the result
399+
assert_that(result, same_instance(mock_schema))
400+
401+
402+
def test_get_pipelines_schema_with_type_overrides(project, mocker):
403+
"""Test pipeline schema generation with type overrides."""
404+
mock_base_schema = mocker.Mock(spec=Schema)
405+
mock_overrides_schema = mocker.Mock(spec=Schema)
406+
407+
# Mock the pipeline initialization and schema loading
408+
mocker.patch.object(project.__class__, "make_schema", return_value=mock_base_schema)
409+
mock_pipeline_init = mocker.patch(
410+
"nodestream.project.pipeline_definition.PipelineDefinition.initialize_for_introspection"
411+
)
412+
mock_pipeline = mocker.Mock()
413+
mock_pipeline.expand_schema = mocker.Mock()
414+
mock_pipeline_init.return_value = mock_pipeline
415+
416+
Schema.read_from_file = mocker.Mock(return_value=mock_overrides_schema)
417+
418+
overrides_path = Path("some/overrides.yaml")
419+
result = project.get_pipelines_schema(["test"], overrides_path)
420+
421+
Schema.read_from_file.assert_called_once_with(overrides_path)
422+
mock_base_schema.merge.assert_called_once_with(mock_overrides_schema)
423+
assert_that(result, same_instance(mock_base_schema))
424+
425+
426+
def test_get_pipelines_schema_nonexistent_pipeline_raises_error(project):
427+
"""Test that specifying non-existent pipelines raises ValueError with helpful message."""
428+
with pytest.raises(ValueError) as exc_info:
429+
project.get_pipelines_schema(["nonexistent"])
430+
431+
error_message = str(exc_info.value)
432+
assert_that(
433+
error_message,
434+
equal_to(
435+
"None of the specified pipelines ['nonexistent'] were found. Available pipelines: ['test', 'test2']"
436+
),
437+
)
438+
439+
440+
def test_get_pipelines_schema_empty_list_raises_error(project):
441+
"""Test that providing an empty pipeline list raises ValueError."""
442+
with pytest.raises(ValueError) as exc_info:
443+
project.get_pipelines_schema([])
444+
445+
error_message = str(exc_info.value)
446+
assert_that(
447+
error_message,
448+
equal_to(
449+
"None of the specified pipelines [] were found. Available pipelines: ['test', 'test2']"
450+
),
451+
)

0 commit comments

Comments
 (0)