Adding testcases for new file-like input and output
This commit is contained in:
parent
792e849d20
commit
b57e583798
1 changed files with 14 additions and 4 deletions
18
t/test.py
18
t/test.py
|
@ -141,12 +141,14 @@ class TestTftpyState(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
tftpy.setLogLevel(logging.DEBUG)
|
tftpy.setLogLevel(logging.DEBUG)
|
||||||
|
|
||||||
def clientServerUploadOptions(self, options, transmitname=None):
|
def clientServerUploadOptions(self, options, input=None, transmitname=None):
|
||||||
"""Fire up a client and a server and do an upload."""
|
"""Fire up a client and a server and do an upload."""
|
||||||
root = '/tmp'
|
root = '/tmp'
|
||||||
home = os.path.dirname(os.path.abspath(__file__))
|
home = os.path.dirname(os.path.abspath(__file__))
|
||||||
filename = '100KBFILE'
|
filename = '100KBFILE'
|
||||||
input_path = os.path.join(home, filename)
|
input_path = os.path.join(home, filename)
|
||||||
|
if not input:
|
||||||
|
input = input_path
|
||||||
if transmitname:
|
if transmitname:
|
||||||
filename = transmitname
|
filename = transmitname
|
||||||
server = tftpy.TftpServer(root)
|
server = tftpy.TftpServer(root)
|
||||||
|
@ -160,7 +162,7 @@ class TestTftpyState(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
client.upload(filename,
|
client.upload(filename,
|
||||||
input_path)
|
input)
|
||||||
finally:
|
finally:
|
||||||
os.kill(child_pid, 15)
|
os.kill(child_pid, 15)
|
||||||
os.waitpid(child_pid, 0)
|
os.waitpid(child_pid, 0)
|
||||||
|
@ -168,7 +170,7 @@ class TestTftpyState(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
server.listen('localhost', 20001)
|
server.listen('localhost', 20001)
|
||||||
|
|
||||||
def clientServerDownloadOptions(self, options):
|
def clientServerDownloadOptions(self, options, output='/tmp/out'):
|
||||||
"""Fire up a client and a server and do a download."""
|
"""Fire up a client and a server and do a download."""
|
||||||
root = os.path.dirname(os.path.abspath(__file__))
|
root = os.path.dirname(os.path.abspath(__file__))
|
||||||
server = tftpy.TftpServer(root)
|
server = tftpy.TftpServer(root)
|
||||||
|
@ -182,7 +184,7 @@ class TestTftpyState(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
client.download('100KBFILE',
|
client.download('100KBFILE',
|
||||||
'/tmp/out')
|
output)
|
||||||
finally:
|
finally:
|
||||||
os.kill(child_pid, 15)
|
os.kill(child_pid, 15)
|
||||||
os.waitpid(child_pid, 0)
|
os.waitpid(child_pid, 0)
|
||||||
|
@ -193,6 +195,10 @@ class TestTftpyState(unittest.TestCase):
|
||||||
def testClientServerNoOptions(self):
|
def testClientServerNoOptions(self):
|
||||||
self.clientServerDownloadOptions({})
|
self.clientServerDownloadOptions({})
|
||||||
|
|
||||||
|
def testClientFileObject(self):
|
||||||
|
output = open('/tmp/out', 'w')
|
||||||
|
self.clientServerDownloadOptions({}, output)
|
||||||
|
|
||||||
def testClientServerBlksize(self):
|
def testClientServerBlksize(self):
|
||||||
for blksize in [512, 1024, 2048, 4096]:
|
for blksize in [512, 1024, 2048, 4096]:
|
||||||
self.clientServerDownloadOptions({'blksize': blksize})
|
self.clientServerDownloadOptions({'blksize': blksize})
|
||||||
|
@ -200,6 +206,10 @@ class TestTftpyState(unittest.TestCase):
|
||||||
def testClientServerUploadNoOptions(self):
|
def testClientServerUploadNoOptions(self):
|
||||||
self.clientServerUploadOptions({})
|
self.clientServerUploadOptions({})
|
||||||
|
|
||||||
|
def testClientServerUploadFileObj(self):
|
||||||
|
fileobj = open('/tmp/100KBFILE', 'r')
|
||||||
|
self.clientServerUploadOptions({}, input=fileobj)
|
||||||
|
|
||||||
def testClientServerUploadWithSubdirs(self):
|
def testClientServerUploadWithSubdirs(self):
|
||||||
self.clientServerUploadOptions({}, transmitname='foo/bar/100KBFILE')
|
self.clientServerUploadOptions({}, transmitname='foo/bar/100KBFILE')
|
||||||
|
|
||||||
|
|
Reference in a new issue