Debian Codegraph @

testsuite/size-filter_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 """Coverage of --max-size / --min-size at depth.
3
4 A small and a large file at every level; --max-size must transfer only the
5 small ones and --min-size only the large ones, the selection holding all the
6 way down the tree.
7 """
8
9 import os
10
11 from rsyncfns import (
12 FROMDIR, TODIR,
13 assert_not_exists, assert_same, make_data_file, rmtree, run_rsync,
14 )
15
16 src = FROMDIR
17 SMALL = 500
18 LARGE = 5000
19
20
21 def seed():
22 rmtree(src)
23 rmtree(TODIR)
24 cur = src
25 for lvl in range(4):
26 cur.mkdir(parents=True, exist_ok=True)
27 make_data_file(cur / f'small{lvl}', SMALL)
28 make_data_file(cur / f'large{lvl}', LARGE)
29 cur = cur / f'd{lvl + 1}'
30
31
32 # --- --max-size keeps only the small files at every level -------------------
33 # Compare content (not just existence) so a kept file is proven to be the
34 # transferred source, not an empty/stale placeholder.
35 seed()
36 run_rsync('-a', '--max-size=1000', f'{src}/', f'{TODIR}/')
37 dcur, scur = TODIR, src
38 for lvl in range(4):
39 assert_same(dcur / f'small{lvl}', scur / f'small{lvl}',
40 label=f'--max-size kept small L{lvl}')
41 assert_not_exists(dcur / f'large{lvl}', label=f'--max-size dropped large L{lvl}')
42 dcur, scur = dcur / f'd{lvl + 1}', scur / f'd{lvl + 1}'
43
44 # --- --min-size keeps only the large files at every level -------------------
45 seed()
46 run_rsync('-a', '--min-size=1000', f'{src}/', f'{TODIR}/')
47 dcur, scur = TODIR, src
48 for lvl in range(4):
49 assert_same(dcur / f'large{lvl}', scur / f'large{lvl}',
50 label=f'--min-size kept large L{lvl}')
51 assert_not_exists(dcur / f'small{lvl}', label=f'--min-size dropped small L{lvl}')
52 dcur, scur = dcur / f'd{lvl + 1}', scur / f'd{lvl + 1}'
53
54 print("size-filter: --max-size / --min-size select correctly at depth")