Starting on unit tests

git-svn-id: https://tftpy.svn.sourceforge.net/svnroot/tftpy/trunk@19 63283fd4-ec1e-0410-9879-cb7f675518da
master
msoulier 2006-10-08 13:58:41 +00:00
parent e771f670fb
commit 6db1b2cfda
2 changed files with 27 additions and 0 deletions

View File

@ -144,6 +144,7 @@ class TftpPacketInitial(TftpPacket):
logger.debug("size of struct is %d" % struct.calcsize(format))
self.buffer = struct.pack(format, self.opcode, self.filename, self.mode, *options_list)
logger.debug("buffer is " + self.buffer)
return self
def decode(self):
@ -172,6 +173,7 @@ class TftpPacketInitial(TftpPacket):
# length should now be the end of the mode.
tftpassert(nulls == 2, "malformed packet")
shortbuf = self.buffer[2:tlength]
logger.debug("about to unpack buffer with format: %s" % format)
mystruct = struct.unpack(format, shortbuf)
for key in mystruct:
logger.debug("option name is %s, value is %s"

25
test/test.py Normal file
View File

@ -0,0 +1,25 @@
"""Unit tests for tftpy."""
import unittest
import tftpy
class TestTftpy(unittest.TestCase):
def setUp(self):
pass
def testTftpPacketRRQ(self):
options = {}
rrq = tftpy.TftpPacketRRQ()
rrq.filename = 'myfilename'
rrq.mode = 'octet'
rrq.options = options
rrq.encode()
self.assert_(rrq.buffer != None, "Buffer populated")
rrq.decode()
self.assertEqual(rrq.filename, "myfilename", "Filename correct")
self.assertEqual(rrq.mode, "octet", "Mode correct")
self.assertEqual(rrq.options, options, "Options correct")
if __name__ == '__main__':
unittest.main()