[Git][NTPsec/ntpsec][master] Added >= and <= comparison functions to OID class
Ian Bruene
gitlab at mg.gitlab.com
Tue Oct 24 20:40:50 UTC 2017
Ian Bruene pushed to branch master at NTPsec / ntpsec
Commits:
654b37a7 by Ian Bruene at 2017-10-24T15:39:33-05:00
Added >= and <= comparison functions to OID class
- - - - -
2 changed files:
- pylib/agentx.py
- tests/pylib/test_agentx.py
Changes:
=====================================
pylib/agentx.py
=====================================
--- a/pylib/agentx.py
+++ b/pylib/agentx.py
@@ -814,9 +814,15 @@ class OID:
def __lt__(self, other):
return self.compareOID(other) == -1
+ def __le__(self, other):
+ return self.compareOID(other) in (-1, 0)
+
def __gt__(self, other):
return self.compareOID(other) == 1
+ def __ge__(self, other):
+ return self.compareOID(other) in (0, 1)
+
def compareOID(self, other):
if self.subids == other.subids:
return 0
=====================================
tests/pylib/test_agentx.py
=====================================
--- a/tests/pylib/test_agentx.py
+++ b/tests/pylib/test_agentx.py
@@ -1706,6 +1706,21 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
a = target((1, 2, 2, 4))
b = target((1, 2, 3))
self.assertEqual(a.compareOID(b), -1)
+ # Test direct comparisons
+ # Test ==
+ self.assertEqual(target((1, 2, 3)), target((1, 2, 3)))
+ # Test !=
+ self.assertNotEqual(target((1, 2, 3)), target((1, 2)))
+ # Test <
+ self.assertLess(target((1, 2)), target((1, 2, 3)))
+ # Test >
+ self.assertGreater(target((1, 2, 3)), target((1, 2)))
+ # Test <=
+ self.assertLessEqual(target((1, 2)), target((1, 2, 3)))
+ self.assertLessEqual(target((1, 2, 3)), target((1, 2, 3)))
+ # Test >=
+ self.assertGreaterEqual(target((1, 2, 3)), target((1, 2)))
+ self.assertGreaterEqual(target((1, 2, 3)), target((1, 2, 3)))
def test_searchrange(self):
target = ntp.agentx.SearchRange
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/654b37a74f96fa5e618db2ec5fd223412866ade2
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/654b37a74f96fa5e618db2ec5fd223412866ade2
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/20171024/b78c7914/attachment.html>
More information about the vc
mailing list