用于测试的模拟sftp服务器
mocksftp的Python项目详细描述
mocksftp-轻松测试sftp客户端代码
用于测试与sftp相关的客户端代码的进程内sftp服务器。
用法示例
对于pytest,使用sftp_server和sftp_clientfixtures:
fromcontextlibimportclosingimportpy.pathdeftest_open_file(sftp_server,sftp_client):# Write directly in the server root.root_path=py.path.local(sftp_server.root)root_path.join('file.txt').write('content')# Access the folder via the clientsftp=sftp_client.open_sftp()assertsftp.listdir('.')==['file.txt']withclosing(sftp.open('file.txt','r'))asdata:assertdata.read()==b'content'