Coverage for nilearn/_utils/tests/test_path_finding.py: 0%

28 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-20 10:58 +0200

1from pathlib import Path 

2 

3import pytest 

4 

5from nilearn._utils.path_finding import resolve_globbing 

6 

7 

8def test_resolve_globbing(tmp_path): 

9 assert resolve_globbing(tmp_path) == [tmp_path] 

10 assert resolve_globbing([]) == [] 

11 

12 

13def test_resolve_globbing_path_expanded(): 

14 tmp_home = Path("~/some_user") 

15 tmp_home.expanduser().mkdir(parents=True, exist_ok=True) 

16 assert resolve_globbing(tmp_home) == [tmp_home.expanduser()] 

17 

18 

19def test_resolve_globbing_nested(tmp_path): 

20 (tmp_path / "spam.txt").touch() 

21 (tmp_path / "foo.txt").touch() 

22 (tmp_path / "spam").mkdir(parents=True, exist_ok=True) 

23 (tmp_path / "spam" / "foo.txt").touch() 

24 (tmp_path / "foo").mkdir(parents=True, exist_ok=True) 

25 (tmp_path / "foo" / "foo.txt").touch() 

26 

27 results = resolve_globbing(tmp_path / "foo.txt") 

28 assert len(results) == 1 

29 assert all(isinstance(x, Path) for x in results) 

30 assert results == [tmp_path / "foo.txt"] 

31 

32 results = resolve_globbing(tmp_path / "**/foo.txt") 

33 assert len(results) == 2 

34 assert all(isinstance(x, Path) for x in results) 

35 assert results == [ 

36 tmp_path / "foo" / "foo.txt", 

37 tmp_path / "spam" / "foo.txt", 

38 ] 

39 

40 

41def test_resolve_globbing_error(tmp_path): 

42 with pytest.raises(ValueError, match="No files matching path"): 

43 assert resolve_globbing(tmp_path / "does_not_exist.txt")