-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_put_r.py
80 lines (66 loc) · 1.96 KB
/
test_put_r.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'''test pysftp.Connection.put_r - uses py.test'''
from __future__ import print_function
import os
import shutil
from tempfile import mkdtemp
import pytest
from blddirs import build_dir_struct
from common import SKIP_IF_CI
from pysftp import walktree, reparent
import pysftp
@SKIP_IF_CI
def test_put_r(lsftp):
'''test put_r'''
localpath = mkdtemp()
print(localpath)
remote_dir = os.path.split(localpath)[1]
build_dir_struct(localpath)
localpath = os.path.join(localpath, 'pub')
print(localpath)
# make a tidy place to put them
lsftp.mkdir(remote_dir)
# run the op
lsftp.put_r(localpath, remote_dir)
# inspect results
rfs = pysftp.WTCallbacks()
with lsftp.cd(remote_dir):
lsftp.walktree('.', rfs.file_cb, rfs.dir_cb, rfs.unk_cb)
lfs = pysftp.WTCallbacks()
save_dir = os.getcwd()
os.chdir(localpath)
walktree('.', lfs.file_cb, lfs.dir_cb, lfs.unk_cb)
os.chdir(save_dir)
# cleanup remote
for fname in rfs.flist:
lsftp.remove(reparent(remote_dir, fname))
for dname in reversed(rfs.dlist):
lsftp.rmdir(reparent(remote_dir, dname))
lsftp.rmdir(remote_dir)
# cleanup local
shutil.rmtree(os.path.split(localpath)[0])
# if assertions fail, give some meaningful debug out
print("rfs", remote_dir)
print(rfs.flist)
print(rfs.dlist)
print(rfs.ulist)
print("lfs", localpath)
print(lfs.flist)
print(lfs.dlist)
print(lfs.ulist)
# check results
assert rfs.flist == lfs.flist
assert rfs.dlist == lfs.dlist
assert rfs.ulist == lfs.ulist
assert rfs.ulist == []
# TODO
# def test_put_r_ro(psftp):
# '''test put_r failure on remote read-only srvr'''
# # run the op
# with pytest.raises(IOError):
# psftp.put_r('.', '.')
@SKIP_IF_CI
def test_put_r_bad_local(lsftp):
'''test put_r failure on non-existing local directory'''
# run the op
with pytest.raises(OSError):
lsftp.put_r('/non-existing', '.')