@@ -38,19 +38,24 @@ def test_loader_with_valid_data_path(
3838
3939
4040@pytest .mark .parametrize ("collect_only" , [True , False ])
41- @pytest .mark .parametrize ("invalid_path" , ["." , ".." , ROOT_DIR ])
41+ @pytest .mark .parametrize (
42+ "invalid_path" , ["." , ".." , ROOT_DIR , Path (ROOT_DIR , "dir" ), Path (ROOT_DIR , "dir" , "test.txt" )]
43+ )
4244def test_loader_with_invalid_data_path (test_context : TestContext , invalid_path : str , collect_only : bool ) -> None :
4345 """Test that invalid relative paths are handled properly"""
4446 result = run_pytest_with_context (test_context , path = invalid_path , collect_only = collect_only )
4547 _check_result_with_invalid_path (result , test_context .loader , invalid_path )
4648
4749
4850@pytest .mark .parametrize ("collect_only" , [True , False ])
51+ @pytest .mark .parametrize ("is_abs_path" , [False , True ])
4952def test_loader_with_unmatched_data_path_type (
50- test_context : TestContext , loader : DataLoader , collect_only : bool
53+ test_context : TestContext , loader : DataLoader , loader_dir_name : str , is_abs_path : bool , collect_only : bool
5154) -> None :
5255 """Test that relative path type that isn't allowed for each loader is handled properly"""
53- file_path = create_test_data_in_loader_dir (test_context .pytester , "some_dir" , Path ("other_dir" , "foo.txt" ))
56+ file_path = create_test_data_in_loader_dir (
57+ test_context .pytester , loader_dir_name , Path ("other_dir" , "foo.txt" ), return_abs_path = is_abs_path
58+ )
5459 if loader .is_file_loader :
5560 unmatched_path = file_path .parent
5661 else :
@@ -86,8 +91,17 @@ def _check_result_with_invalid_path(result: RunResult, loader: DataLoader, inval
8691 assert result .ret == ExitCode .INTERRUPTED
8792 stdout = str (result .stdout )
8893 result .assert_outcomes (errors = 1 )
89- if str (invalid_path ) in ("." , ".." , ROOT_DIR ):
90- assert f"Invalid path value: { str (invalid_path )!r} " in stdout
94+ path = Path (invalid_path )
95+ if str (path ) in ("." , ".." , ROOT_DIR ):
96+ assert f"Invalid path value: '{ path } '" in stdout
97+ elif path .is_absolute ():
98+ if path .exists ():
99+ assert (
100+ f"Invalid path: @{ loader .__name__ } loader must take a "
101+ f"{ 'file' if loader .is_file_loader and path .is_dir () else 'directory' } path, not '{ path } '"
102+ ) in stdout
103+ else :
104+ assert f"The provided path does not exist: '{ path } '" in stdout
91105 else :
92106 file_or_dir = "directory" if loader == parametrize_dir else "file"
93- assert f"Unable to locate the specified { file_or_dir } '{ invalid_path } '" in stdout
107+ assert f"Unable to locate the specified { file_or_dir } '{ path } '" in stdout
0 commit comments