[Git][NTPsec/ntpsec][master] Python3 fixes for new tests.
Ian Bruene
gitlab at mg.gitlab.com
Fri Mar 23 19:16:24 UTC 2018
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
54700eb9 by Ian Bruene at 2018-03-23T19:15:48Z
Python3 fixes for new tests.
- - - - -
2 changed files:
- pylib/agentx.py
- tests/pylib/test_agentx.py
Changes:
=====================================
pylib/agentx.py
=====================================
--- a/pylib/agentx.py
+++ b/pylib/agentx.py
@@ -173,7 +173,7 @@ class PacketControl:
self.packetLog = {} # Sent packets kept until response is received
self.loopCallback = None # called each loop in runforever mode
self.database = dbase # class for handling data requests
- self.receivedData = "" # buffer for data from incomplete packets
+ self.receivedData = b"" # buffer for data from incomplete packets
self.receivedPackets = [] # use as FIFO
self.timeout = timeout
self.sessionID = None # need this for all packets
@@ -268,7 +268,7 @@ class PacketControl:
def checkResponses(self):
"Check for expected responses that have timed out"
currentTime = time.time()
- for key in self.packetLog.keys():
+ for key in list(self.packetLog.keys()):
expiration, originalPkt, callback = self.packetLog[key]
if currentTime > expiration:
if callback is not None:
@@ -349,7 +349,7 @@ class PacketControl:
def pollSocket(self):
"Reads all currently available data from the socket, non-blocking"
- data = ""
+ data = b""
while True:
tmp = select.select([self.socket], [], [], 0)[0]
if len(tmp) == 0: # No socket, means no data available
=====================================
tests/pylib/test_agentx.py
=====================================
--- a/tests/pylib/test_agentx.py
+++ b/tests/pylib/test_agentx.py
@@ -150,7 +150,7 @@ class TestPacketControl(unittest.TestCase):
self.assertEqual(p.packetLog, {})
self.assertEqual(p.loopCallback, None)
self.assertEqual(p.database, "base")
- self.assertEqual(p.receivedData, "")
+ self.assertEqual(p.receivedData, b"")
self.assertEqual(p.timeout, 30)
self.assertEqual(p.sessionID, None)
self.assertEqual(p.highestTransactionID, 0)
@@ -354,7 +354,7 @@ class TestPacketControl(unittest.TestCase):
enc = pkt.encode()
part1, rest = ntp.util.slicedata(enc, 15)
part2, part3 = ntp.util.slicedata(rest, 6)
- pollReturns = [part1, part2, part3 + "blah"]
+ pollReturns = [part1, part2, part3 + b"blah"]
def pollSocket_jig(self):
self.receivedData += pollReturns.pop(0)
@@ -372,7 +372,7 @@ class TestPacketControl(unittest.TestCase):
# Test packet eaten
p.packetEater()
self.assertEqual(p.receivedPackets, [pkt])
- self.assertEqual(p.receivedData, "blah")
+ self.assertEqual(p.receivedData, b"blah")
def test_sendPacket(self):
sock = jigs.SocketJig()
@@ -380,18 +380,18 @@ class TestPacketControl(unittest.TestCase):
testpkt = AP.PingPDU(True, 0, 1, 2, "fake")
# Test not expecting reply
p.sendPacket(testpkt, False)
- self.assertEqual(sock.data, ["\x01\r\x18\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x01"
- "\x00\x00\x00\x02\x00\x00\x00\x08"
- "\x00\x00\x00\x04fake"])
+ self.assertEqual(sock.data, [b"\x01\r\x18\x00"
+ b"\x00\x00\x00\x00\x00\x00\x00\x01"
+ b"\x00\x00\x00\x02\x00\x00\x00\x08"
+ b"\x00\x00\x00\x04fake"])
self.assertEqual(p.packetLog, {})
sock.data = []
# Test expecting reply
p.sendPacket(testpkt, True, callback="foo")
- self.assertEqual(sock.data, ["\x01\r\x18\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x01"
- "\x00\x00\x00\x02\x00\x00\x00\x08"
- "\x00\x00\x00\x04fake"])
+ self.assertEqual(sock.data, [b"\x01\r\x18\x00"
+ b"\x00\x00\x00\x00\x00\x00\x00\x01"
+ b"\x00\x00\x00\x02\x00\x00\x00\x08"
+ b"\x00\x00\x00\x04fake"])
self.assertEqual(p.packetLog, {(0, 1, 2):(30.0, testpkt, "foo")})
def test_sendPing(self):
@@ -399,10 +399,10 @@ class TestPacketControl(unittest.TestCase):
p = AX.PacketControl(sock, None)
p.sessionID = 42
p.sendPing()
- self.assertEqual(sock.data, ["\x01\r\x10\x00"
- "\x00\x00\x00*\x00\x00\x00\x05"
- "\x00\x00\x00\x01\x00\x00\x00\x00"])
- self.assertEqual(p.packetLog.keys(), [(42, 5, 1)])
+ self.assertEqual(sock.data, [b"\x01\r\x10\x00"
+ b"\x00\x00\x00*\x00\x00\x00\x05"
+ b"\x00\x00\x00\x01\x00\x00\x00\x00"])
+ self.assertEqual(list(p.packetLog.keys()), [(42, 5, 1)])
def test_sendNotify(self):
sock = jigs.SocketJig()
@@ -411,14 +411,14 @@ class TestPacketControl(unittest.TestCase):
vb = AP.Varbind(AP.VALUE_INTEGER, (0, 1, 2), 23)
p.sendNotify([vb])
self.assertEqual(sock.data,
- ["\x01\x0c\x10\x00"
- "\x00\x00\x00*\x00\x00\x00\x05"
- "\x00\x00\x00\x01\x00\x00\x00\x18"
- "\x00\x02\x00\x00"
- "\x03\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x01\x00\x00\x00\x02"
- "\x00\x00\x00\x17"])
- self.assertEqual(p.packetLog.keys(), [(42, 5, 1)])
+ [b"\x01\x0c\x10\x00"
+ b"\x00\x00\x00*\x00\x00\x00\x05"
+ b"\x00\x00\x00\x01\x00\x00\x00\x18"
+ b"\x00\x02\x00\x00"
+ b"\x03\x00\x00\x00\x00\x00\x00\x00"
+ b"\x00\x00\x00\x01\x00\x00\x00\x02"
+ b"\x00\x00\x00\x17"])
+ self.assertEqual(list(p.packetLog.keys()), [(42, 5, 1)])
def test_sendErrorResponse(self):
sock = jigs.SocketJig()
@@ -428,10 +428,10 @@ class TestPacketControl(unittest.TestCase):
"transaction_id":32, "packet_id":100}
p.sendErrorResponse(header, AP.ERR_GENERR, 12)
self.assertEqual(sock.data,
- ["\x01\x12\x10\x00"
- "\x00\x00\x00*\x00\x00\x00 "
- "\x00\x00\x00d\x00\x00\x00\x08"
- "\x00\x00\x00\x00\x00\x05\x00\x0c"])
+ [b"\x01\x12\x10\x00"
+ b"\x00\x00\x00*\x00\x00\x00 "
+ b"\x00\x00\x00d\x00\x00\x00\x08"
+ b"\x00\x00\x00\x00\x00\x05\x00\x0c"])
self.assertEqual(p.packetLog, {})
def test_pollSocket(self):
@@ -443,13 +443,13 @@ class TestPacketControl(unittest.TestCase):
pkt = AP.ResponsePDU(True, 42, 23, 100, 0, 0, 0)
enc = pkt.encode()
part1, part2 = ntp.util.slicedata(enc, 15)
- sock.return_data = [part1, part2, "blah"]
+ sock.return_data = [part1, part2, b"blah"]
fakeselectmod.do_return = [True, True, True, False]
try:
selecttemp = AX.select
AX.select = fakeselectmod
p.pollSocket()
- self.assertEqual(p.receivedData, enc + "blah")
+ self.assertEqual(p.receivedData, enc + b"blah")
finally:
AX.select = selecttemp
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/54700eb933335d7864b562958244d9c7d8009beb
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/54700eb933335d7864b562958244d9c7d8009beb
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180323/b18d4b2c/attachment.html>
More information about the vc
mailing list