Debian Codegraph @

testsuite/prune-empty-dirs_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of -m / --prune-empty-dirs at depth.
3
4 --prune-empty-dirs drops directory chains that would end up empty at the
5 destination -- both chains that are empty in the source and chains that become
6 empty because a filter excluded their only files. Populated chains are kept.
7 """
8
9 from rsyncfns import (
10 FROMDIR, TODIR,
11 assert_not_exists, assert_same, makepath, rmtree, run_rsync,
12 )
13
14 src = FROMDIR
15
16
17 def reseed():
18 rmtree(src)
19 rmtree(TODIR)
20
21
22 # --- a deep empty chain is pruned; a deep populated chain is kept ------------
23 reseed()
24 makepath(src / 'empty' / 'e1' / 'e2', src / 'full' / 'd1' / 'd2')
25 (src / 'full' / 'd1' / 'd2' / 'file').write_text("data\n")
26
27 run_rsync('-a', '-m', f'{src}/', f'{TODIR}/')
28 assert_not_exists(TODIR / 'empty', label='-m pruned an empty chain')
29 assert_same(TODIR / 'full' / 'd1' / 'd2' / 'file',
30 src / 'full' / 'd1' / 'd2' / 'file', label='-m kept populated chain')
31
32 # --- a chain emptied by an exclude filter is also pruned --------------------
33 reseed()
34 makepath(src / 'mixed' / 'sub', src / 'onlylogs' / 'sub')
35 (src / 'mixed' / 'sub' / 'keep.txt').write_text("k\n")
36 (src / 'mixed' / 'sub' / 'drop.log').write_text("d\n")
37 (src / 'onlylogs' / 'sub' / 'a.log').write_text("a\n")
38
39 run_rsync('-a', '-m', '--exclude=*.log', f'{src}/', f'{TODIR}/')
40 assert_same(TODIR / 'mixed' / 'sub' / 'keep.txt',
41 src / 'mixed' / 'sub' / 'keep.txt', label='-m kept non-empty dir')
42 assert_not_exists(TODIR / 'onlylogs',
43 label='-m pruned a dir emptied by an exclude')
44
45 print("prune-empty-dirs: empty and filter-emptied chains pruned, populated kept")