[Git][NTPsec/ntpsec][master] AgentX packets now have working __repr__ function, and tests
Ian Bruene
gitlab at mg.gitlab.com
Thu Aug 3 18:09:15 UTC 2017
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
bd1778d8 by Ian Bruene at 2017-08-03T12:59:37-05:00
AgentX packets now have working __repr__ function, and tests
- - - - -
2 changed files:
- pylib/agentx.py
- tests/pylib/test_agentx.py
Changes:
=====================================
pylib/agentx.py
=====================================
--- a/pylib/agentx.py
+++ b/pylib/agentx.py
@@ -73,10 +73,14 @@ class AgentXPDU:
return pktvars
def __repr__(self):
- s = self.__name__ + "("
+ s = self.__class__.__name__ + "("
v = []
- for var in self.printvars:
- v.append(repr(var))
+ myvars = self.packetVars()
+ keys = myvars.keys()
+ keys.sort() # they will always be in the same order: testable
+ for name in keys:
+ value = myvars[name]
+ v.append("%s=%s" % (name, repr(value)))
s += ", ".join(v) + ")"
return s
=====================================
tests/pylib/test_agentx.py
=====================================
--- a/tests/pylib/test_agentx.py
+++ b/tests/pylib/test_agentx.py
@@ -82,6 +82,28 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
#
# PDU tests
#
+ def test_AgentXPDU(self):
+
+ # Test basic, without context
+ test = ntp.agentx.AgentXPDU(0, True, 1, 2, 3, context=extraData)
+ self.assertEqual(repr(test),
+ "AgentXPDU(bigEndian=True, packetID=3, "
+ "pduType=0, sessionID=1, transactionID=2)")
+ # Test basic, with context
+ test = ntp.agentx.AgentXPDU(0, True, 1, 2, 3, hascontext=True)
+ self.assertEqual(repr(test),
+ "AgentXPDU(bigEndian=True, context=None, packetID=3, "
+ "pduType=0, sessionID=1, transactionID=2)")
+ # Test with added variables
+ test.foo = 42
+ test._wyk = extraData # this should be ignored
+ test.context = "jabber jabber jabber"
+ self.assertEqual(repr(test),
+ "AgentXPDU(bigEndian=True, "
+ "context='jabber jabber jabber', "
+ "foo=42, packetID=3, "
+ "pduType=0, sessionID=1, transactionID=2)")
+
def test_OpenPDU(self):
dec = ntp.agentx.decode_OpenPDU
cls = ntp.agentx.OpenPDU
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/bd1778d893502a1adad06b547e47b48a62805d49
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/bd1778d893502a1adad06b547e47b48a62805d49
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/20170803/11a7125f/attachment.html>
More information about the vc
mailing list