@@ -22,46 +22,50 @@ def assets_path(tmp_path, fixtures_path):
2222 # Avoid `dirs_exist_ok=True` missing in python 2
2323 subdir = tmp_path / 'sub'
2424 shutil .copytree (templatepath .as_posix (), subdir .as_posix ())
25- return subdir . as_posix ()
25+ return subdir
2626
2727
2828def test_filtered_path_default (assets_path ):
2929 assert filtered_paths (assets_path ) == {
30- Path (assets_path , '1.txt' ),
31- Path (assets_path , 'ignore.dir' ),
32- Path (assets_path , 'ignore.dir' , 'file.txt' ),
33- Path (assets_path , 'ignore.me' ),
30+ assets_path / '1.txt' ,
31+ assets_path / 'ignore.dir' / 'file.txt' ,
32+ assets_path / 'ignore.me' ,
3433 }
3534
3635
3736def test_filtered_path_no_default (assets_path ):
3837 assert filtered_paths (assets_path , exclude_default = False ) == {
39- Path (assets_path , '1.txt' ),
40- Path (assets_path , 'ignore.dir' ),
41- Path (assets_path , 'ignore.dir' , 'file.txt' ),
42- Path (assets_path , 'ignore.me' ),
43- Path (assets_path , '.gitlab-ci.yml' ),
38+ assets_path / '1.txt' ,
39+ assets_path / 'ignore.dir' / 'file.txt' ,
40+ assets_path / 'ignore.me' ,
41+ assets_path / '.gitlab-ci.yml' ,
4442 }
4543
4644
47- def test_filtered_path_exclude_file (assets_path ):
45+ def test_filtered_path_exclude_file_and_empty_dirs (assets_path ):
4846 assert filtered_paths (assets_path , exclude = ['**/file.txt' ]) == {
49- Path (assets_path , '1.txt' ),
50- Path (assets_path , 'ignore.dir' ),
51- Path (assets_path , 'ignore.me' ),
47+ assets_path / '1.txt' ,
48+ assets_path / 'ignore.me' ,
5249 }
5350
5451
55- def test_filtered_path_keep_empty_dir (assets_path ):
52+ def test_filtered_path_exclude_file_and_empty_dir_kept (assets_path ):
53+ assert filtered_paths (assets_path , exclude = ['**/file.txt' ], include = ['ignore.dir' ]) == {
54+ assets_path / '1.txt' ,
55+ assets_path / 'ignore.me' ,
56+ assets_path / 'ignore.dir' ,
57+ }
58+
59+
60+ def test_filtered_path_removes_empty_dir (assets_path ):
5661 assert filtered_paths (
5762 assets_path ,
5863 exclude = [
5964 'ignore.dir/**/*' ,
6065 ],
6166 ) == {
62- Path (assets_path , '1.txt' ),
63- Path (assets_path , 'ignore.me' ),
64- Path (assets_path , 'ignore.dir' ),
67+ assets_path / '1.txt' ,
68+ assets_path / 'ignore.me' ,
6569 }
6670
6771
@@ -73,29 +77,38 @@ def test_filtered_path_exclude_empty_dir(assets_path):
7377 'ignore.dir/*' ,
7478 ],
7579 ) == {
76- Path ( assets_path , '1.txt' ) ,
77- Path ( assets_path , 'ignore.me' ) ,
80+ assets_path / '1.txt' ,
81+ assets_path / 'ignore.me' ,
7882 }
7983
8084
8185def test_filtered_path_exclude_dir_with_file (assets_path ):
82- extra_path = Path ( assets_path , 'ignore.dir' , 'extra' ). as_posix ()
83- os .mkdir (extra_path )
84- one_more = os . path . join ( extra_path , 'one_more.txt' )
85- shutil .copy (os . path . join ( assets_path , '1.txt' ) , one_more )
86+ extra_path = assets_path / 'ignore.dir' / 'extra'
87+ extra_path .mkdir (exist_ok = True )
88+ one_more = extra_path / 'one_more.txt'
89+ shutil .copy (assets_path / '1.txt' , one_more )
8690
87- assert os . path . exists (one_more )
91+ assert one_more . exists ()
8892
8993 assert filtered_paths (
9094 assets_path ,
9195 exclude = [
9296 'ignore.dir/*' ,
9397 ],
9498 ) == {
95- Path (assets_path , '1.txt' ),
96- Path (assets_path , 'ignore.dir' ),
97- Path (assets_path , 'ignore.dir' , 'extra' , 'one_more.txt' ),
98- Path (assets_path , 'ignore.me' ),
99+ assets_path / '1.txt' ,
100+ assets_path / 'ignore.dir' / 'extra' / 'one_more.txt' ,
101+ assets_path / 'ignore.me' ,
102+ }
103+
104+
105+ def test_filtered_with_default_path (tmp_path ):
106+ (tmp_path / 'build_all.sh' ).touch ()
107+ (tmp_path / 'build_me' ).mkdir ()
108+ (tmp_path / 'build_me' / 'file' ).touch ()
109+
110+ assert filtered_paths (tmp_path , exclude_default = True ) == {
111+ tmp_path / 'build_all.sh' ,
99112 }
100113
101114
0 commit comments