[Asterisk-code-review] lib/python: asterisk.opensslversion support Python 3. (testsuite[16])
Friendly Automation
asteriskteam at digium.com
Mon Oct 25 09:45:25 CDT 2021
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/16646 )
Change subject: lib/python: asterisk.opensslversion support Python 3.
......................................................................
lib/python: asterisk.opensslversion support Python 3.
Add support to comparing version of opensslversion module in the
for Python 3 and adds self_test.
ASTERISK_26826
Change-Id: Ic66d845cc5e3375a0d556709bdf6d17cfea0016e
---
M lib/python/asterisk/opensslversion.py
A lib/python/asterisk/self_test/test_opensslversion.py
M lib/python/asterisk/test_config.py
3 files changed, 48 insertions(+), 3 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/lib/python/asterisk/opensslversion.py b/lib/python/asterisk/opensslversion.py
index 3fa5cd5..e82d84b 100644
--- a/lib/python/asterisk/opensslversion.py
+++ b/lib/python/asterisk/opensslversion.py
@@ -44,8 +44,16 @@
return self.version
def __cmp__(self, other):
- """Compare two SIPpVersion instances against each other"""
- return cmp(self.version, other.version)
+ """Compare two OpenSSLVersion instances against each other"""
+ return (int(self.version) > int(other.version)) - (int(self.version) < int(other.version))
+
+ def __le__(self, other):
+ """Determine if this OpenSSLVersion instance is less than or equal to another"""
+ return int(self.version) <= int(other.version)
+
+ def __lt__(self, other):
+ """Determine if this OpenSSLVersion instance is less than another"""
+ return int(self.version) < int(other.version)
def __ne__(self, other):
return self.version != other.version
diff --git a/lib/python/asterisk/self_test/test_opensslversion.py b/lib/python/asterisk/self_test/test_opensslversion.py
new file mode 100755
index 0000000..a00598f
--- /dev/null
+++ b/lib/python/asterisk/self_test/test_opensslversion.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+"""OpenSSLVersion String Handling Tests
+
+Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+from harness_shared import main
+import unittest
+from asterisk.opensslversion import OpenSSLVersion
+
+
+class OpenSSLVersionTests(unittest.TestCase):
+ def test_cmp_greater_than(self):
+ v1 = OpenSSLVersion("1.0.1", None)
+ v2 = OpenSSLVersion("1.0.0", None)
+ self.assertTrue(v1 > v2)
+
+ def test_cmp_less_than(self):
+ v1 = OpenSSLVersion("1.0.1", None)
+ v2 = OpenSSLVersion("1.0.0", None)
+ self.assertTrue(v2 < v1)
+
+ def test_cmp_equal(self):
+ v1 = OpenSSLVersion("1.0.0", None)
+ v2 = OpenSSLVersion("1.0.0", None)
+ self.assertTrue(v1 == v2)
+
+ def test_cmp_not_equal(self):
+ v1 = OpenSSLVersion("1.0.1", None)
+ v2 = OpenSSLVersion("1.0.0", None)
+ self.assertTrue(v1 != v2)
+
+if __name__ == "__main__":
+ main()
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index 64d8ffb..f4dc99f 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -165,7 +165,7 @@
self.met = True
elif "pcap" in dep:
self.name = "pcap"
- from test_case import PCAP_AVAILABLE
+ from .test_case import PCAP_AVAILABLE
self.met = PCAP_AVAILABLE
else:
print("Unknown dependency type specified:")
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/16646
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 16
Gerrit-Change-Id: Ic66d845cc5e3375a0d556709bdf6d17cfea0016e
Gerrit-Change-Number: 16646
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-CC: Rodrigo Ramirez Norambuena <a at rodrigoramirez.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211025/2db47580/attachment-0001.html>
More information about the asterisk-code-review
mailing list