@@ -379,73 +379,79 @@ def test_project_get_from_storage(project, mocker):
379
379
same_instance (project .storage_configuration .initialize_by_name .return_value ),
380
380
)
381
381
382
-
383
- def test_get_pipelines_schema_single_pipeline (project , mocker ):
384
- """Test filtering schema for a single pipeline."""
382
+ def test_get_pipelines_schema_multiple_pipelines (project , mocker ):
385
383
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
384
+ mock_coordinator = mocker .Mock ()
385
+ mock_coordinator .schema = mock_schema
386
+
387
+ mocker .patch ('nodestream.project.project.SchemaExpansionCoordinator' , return_value = mock_coordinator )
388
+
389
+ mock_pipeline1 = mocker .Mock ()
390
+ mock_pipeline1 .initialize_for_introspection = mocker .Mock ()
391
+ mock_pipeline1 .expand_schema = mocker .Mock ()
392
+
393
+ mock_pipeline2 = mocker .Mock ()
394
+ mock_pipeline2 .initialize_for_introspection = mocker .Mock ()
395
+ mock_pipeline2 .expand_schema = mocker .Mock ()
396
+
397
+ mocker .patch .object (project , 'get_pipeline_by_names' , return_value = [mock_pipeline1 , mock_pipeline2 ])
398
+
399
+ result = project .get_pipelines_schema (["test" , "test2" ])
400
+
401
+ mock_pipeline1 .initialize_for_introspection .assert_called_once ()
402
+ mock_pipeline1 .expand_schema .assert_called_once_with (coordinator = mock_coordinator )
403
+ mock_pipeline2 .initialize_for_introspection .assert_called_once ()
404
+ mock_pipeline2 .expand_schema .assert_called_once_with (coordinator = mock_coordinator )
399
405
assert_that (result , same_instance (mock_schema ))
400
406
401
407
402
408
def test_get_pipelines_schema_with_type_overrides (project , mocker ):
403
- """Test pipeline schema generation with type overrides."""
404
409
mock_base_schema = mocker .Mock (spec = Schema )
405
410
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
- )
411
+ mock_coordinator = mocker . Mock ()
412
+ mock_coordinator . schema = mock_base_schema
413
+
414
+ mocker .patch ('nodestream.project.project.SchemaExpansionCoordinator' , return_value = mock_coordinator )
415
+ Schema . read_from_file = mocker . Mock ( return_value = mock_overrides_schema )
416
+
412
417
mock_pipeline = mocker .Mock ()
418
+ mock_pipeline .initialize_for_introspection = mocker .Mock ()
413
419
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
-
420
+ mocker .patch .object (project , 'get_pipeline_by_names' , return_value = [mock_pipeline ])
421
+
418
422
overrides_path = Path ("some/overrides.yaml" )
419
423
result = project .get_pipelines_schema (["test" ], overrides_path )
420
-
424
+
421
425
Schema .read_from_file .assert_called_once_with (overrides_path )
422
426
mock_base_schema .merge .assert_called_once_with (mock_overrides_schema )
423
427
assert_that (result , same_instance (mock_base_schema ))
424
428
425
429
426
- def test_get_pipelines_schema_nonexistent_pipeline_raises_error (project ):
427
- """Test that specifying non-existent pipelines raises ValueError with helpful message."""
430
+ def test_get_pipelines_schema_nonexistent_pipeline_raises_error (project , mocker ):
431
+ mocker .patch .object (project , 'get_pipeline_by_names' , return_value = [])
432
+
428
433
with pytest .raises (ValueError ) as exc_info :
429
434
project .get_pipelines_schema (["nonexistent" ])
430
-
435
+
431
436
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
- )
437
+ assert_that (error_message , equal_to (
438
+ "None of the specified pipelines ['nonexistent'] were found. Available pipelines: ['test', 'test2']"
439
+ ))
438
440
441
+ def test_get_pipeline_by_names (project ):
442
+ pipelines = list (project .get_pipeline_by_names (["test" , "test2" ]))
443
+
444
+ assert_that (pipelines , has_length (2 ))
445
+ assert_that ([p .name for p in pipelines ], contains_inanyorder ("test" , "test2" ))
439
446
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
447
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
- )
448
+ def test_get_pipeline_by_names_nonexistent_pipeline (project ):
449
+ pipelines = list (project .get_pipeline_by_names (["nonexistent" ]))
450
+ assert_that (pipelines , has_length (0 ))
451
+
452
+
453
+ def test_get_pipeline_by_names_mixed_existing_nonexisting (project ):
454
+ pipelines = list (project .get_pipeline_by_names (["test" , "nonexistent" , "test2" ]))
455
+
456
+ assert_that (pipelines , has_length (2 ))
457
+ assert_that ([p .name for p in pipelines ], contains_inanyorder ("test" , "test2" ))
0 commit comments