Port send file mapping tests

This commit is contained in:
Kovid Goyal
2023-04-29 09:17:14 +05:30
parent be7f276d3e
commit 55bbf175c6
5 changed files with 109 additions and 52 deletions

View File

@@ -427,51 +427,3 @@ class TestFileTransmission(BaseTest):
self.assertEqual(files[1].remote_target, files[2].remote_id)
self.assertEqual(files[3].ftype, FileType.link)
self.assertEqual(files[3].remote_target, files[2].remote_id)
def test_path_mapping_send(self):
opts = parse_transfer_args([])[0]
b = Path(os.path.join(self.tdir, 'b'))
os.makedirs(b)
open(b / 'r', 'w').close()
os.mkdir(b / 'd')
open(b / 'd' / 'r', 'w').close()
def gm(*args):
return files_for_send(opts, list(map(str, args)))
def am(files, kw):
m = {f.expanded_local_path: f.remote_path for f in files}
kw = {str(k): str(v) for k, v in kw.items()}
self.ae(m, kw)
def tf(args, expected):
files = gm(*args)
self.ae(len(files), len(expected))
am(files, expected)
opts.mode = 'mirror'
with set_paths(cwd=b, home='/foo/bar'):
tf(['r', 'd'], {b/'r': b/'r', b/'d': b/'d', b/'d'/'r': b/'d'/'r'})
tf(['r', 'd/r'], {b/'r': b/'r', b/'d'/'r': b/'d'/'r'})
with set_paths(cwd=b, home=self.tdir):
tf(['r', 'd'], {b/'r': '~/b/r', b/'d': '~/b/d', b/'d'/'r': '~/b/d/r'})
opts.mode = 'normal'
with set_paths(cwd='/some/else', home='/foo/bar'):
tf([b/'r', b/'d', '/dest'], {b/'r': '/dest/r', b/'d': '/dest/d', b/'d'/'r': '/dest/d/r'})
tf([b/'r', b/'d', '~/dest'], {b/'r': '~/dest/r', b/'d': '~/dest/d', b/'d'/'r': '~/dest/d/r'})
with set_paths(cwd=b, home='/foo/bar'):
tf(['r', 'd', '/dest'], {b/'r': '/dest/r', b/'d': '/dest/d', b/'d'/'r': '/dest/d/r'})
os.symlink('/foo/b', b / 'e')
os.symlink('r', b / 's')
os.link(b / 'r', b / 'h')
with set_paths(cwd='/some/else', home='/foo/bar'):
files = gm(b / 'e', 'dest')
self.ae(files[0].symbolic_link_target, 'path:/foo/b')
files = gm(b / 's', b / 'r', 'dest')
self.ae(files[0].symbolic_link_target, 'fid:2')
files = gm(b / 'h', 'dest')
self.ae(files[0].file_type, FileType.regular)
files = gm(b / 'h', b / 'r', 'dest')
self.ae(files[1].file_type, FileType.link)
self.ae(files[1].hard_link_target, '1')