[asterisk-commits] pabelanger: branch pabelanger/sipp r1150 - /asterisk/team/pabelanger/sipp/lib...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 10 14:36:23 CST 2010


Author: pabelanger
Date: Fri Dec 10 14:36:19 2010
New Revision: 1150

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1150
Log:
SIPpVerison now takes 2 parameters

Modified:
    asterisk/team/pabelanger/sipp/lib/python/sipp/version.py

Modified: asterisk/team/pabelanger/sipp/lib/python/sipp/version.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/sipp/lib/python/sipp/version.py?view=diff&rev=1150&r1=1149&r2=1150
==============================================================================
--- asterisk/team/pabelanger/sipp/lib/python/sipp/version.py (original)
+++ asterisk/team/pabelanger/sipp/lib/python/sipp/version.py Fri Dec 10 14:36:19 2010
@@ -20,13 +20,17 @@
     """A SIPp Version.
 
     """
-    def __init__(self, version=None):
+    def __init__(self, version=None, feature=None):
         """Construct a SIPp Version parser.
 
         Keyword Arguments:
         version -- The SIPp version string to parse.
         """
-        self.version_str = ""
+        self.version_str = None
+        self.feature_str = None
+        self.tls = False
+        self.pcap = False
+
         if version is None:
             sipp = utils.which("sipp")
             if sipp is None:
@@ -45,30 +49,43 @@
                     ver = line.strip().lstrip('SIPp ')
                     ver = ver.split(',', 1)
                     self.version_str = ver[0]
+
+        if version[:1] == "v":
+            self.__parse_version(version, feature)
         else:
-            self.version_str = version
-
-        if not self.version_str:
-            return
-
-        self.__parse_version()
+            self.__parse_feature(version)
 
     def __str__(self):
         return self.version_str
 
     def __int__(self):
-        concept = self.concept.strip('v')
-        res = int(concept) * 10000000 + int(self.major) * 100000
-        if self.minor is not None:
-            res += int(self.minor) * 1000
+        res = 0
+        if self.version_str:
+            concept = self.concept.strip('v')
+            res = int(concept) * 10000000 + int(self.major) * 100000
+            if self.minor is not None:
+                res += int(self.minor) * 1000
+
         if self.tls:
             res += 100
         if self.pcap:
             res += 100
+
         return res
 
     def __cmp__(self, other):
         res = cmp(int(self), int(other))
+        if res > 0:
+            if self.tls is False and other.tls is True:
+                res = False
+            elif self.pcap is False and other.pcap is True:
+                res = False
+        elif res < 1:
+            if other.tls is False and self.tls is True:
+                res = False
+            elif other.pcap is False and self.pcap is True:
+                res = False
+
         return res
 
     def __ne__(self, other):
@@ -85,33 +102,27 @@
                 return True
         return False
 
-    def __parse_version(self):
-        self.tls = False
-        self.pcap = False
-        parts = self.version_str.split(".")
-        self.concept = parts[0]
-        self.major = parts[1]
-        self.minor = None
-        if len(parts) >= 3:
-            self.minor = parts[2]
-        if self.minor is not None:
-            self.minor = self.__parse_addons(self.minor)
-        else:
-            self.major = self.__parse_addons(self.major)
-
-    def __parse_addons(self, value):
-        addons = value.split("-", 1)
-        if len(addons) >= 2:
-            if addons[1] == "TLS":
-                self.tls = True
-            elif addons[1] == "PCAP":
-                self.pcap = True
-            elif addons[1] == "TLS-PCAP":
-                self.tls = True
-                self.pcap = True
-            return addons[0]
-        return value
-
+    def __parse_version(self, version, feature):
+        self.version_str = version
+        if version is not None:
+            parts = self.version_str.split(".")
+            self.concept = parts[0]
+            self.major = parts[1]
+            self.minor = None
+            if len(parts) >= 3:
+                self.minor = parts[2]
+
+        if feature is not None:
+            self.__parse_feature(feature)
+
+    def __parse_feature(self, value):
+        if value == "TLS":
+            self.tls = True
+        elif value == "PCAP":
+            self.pcap = True
+        elif value == "TLS-PCAP":
+            self.tls = True
+            self.pcap = True
 
 class SIPpVersionTests(unittest.TestCase):
     def test_version(self):
@@ -132,16 +143,16 @@
         self.assertFalse(v.pcap)
 
     def test_version3(self):
-        v = SIPpVersion("v3.1-TLS")
-        self.assertEqual(str(v), "v3.1-TLS")
+        v = SIPpVersion("v3.1", "TLS")
+        self.assertEqual(str(v), "v3.1")
         self.assertEqual(v.concept, "v3")
         self.assertEqual(v.major, "1")
         self.assertTrue(v.tls)
         self.assertFalse(v.pcap)
 
     def test_version4(self):
-        v = SIPpVersion("v2.0.1-TLS-PCAP")
-        self.assertEqual(str(v), "v2.0.1-TLS-PCAP")
+        v = SIPpVersion("v2.0.1", "TLS-PCAP")
+        self.assertEqual(str(v), "v2.0.1")
         self.assertEqual(v.concept, "v2")
         self.assertEqual(v.major, "0")
         self.assertEqual(v.minor, "1")
@@ -149,13 +160,28 @@
         self.assertTrue(v.pcap)
 
     def test_version5(self):
-        v = SIPpVersion("v3.2-PCAP")
-        self.assertEqual(str(v), "v3.2-PCAP")
+        v = SIPpVersion("v3.2", "PCAP")
+        self.assertEqual(str(v), "v3.2")
         self.assertEqual(v.concept, "v3")
         self.assertEqual(v.major, "2")
         self.assertFalse(v.tls)
         self.assertTrue(v.pcap)
 
+    def test_version6(self):
+        v = SIPpVersion("PCAP")
+        self.assertFalse(v.tls)
+        self.assertTrue(v.pcap)
+
+    def test_version6(self):
+        v = SIPpVersion("TLS")
+        self.assertTrue(v.tls)
+        self.assertFalse(v.pcap)
+
+    def test_version6(self):
+        v = SIPpVersion("TLS-PCAP")
+        self.assertTrue(v.tls)
+        self.assertTrue(v.pcap)
+
     def test_cmp(self):
         v1 = SIPpVersion("v3.2")
         v2 = SIPpVersion("v3.1")
@@ -177,64 +203,109 @@
         self.assertFalse(v1 != v2)
 
     def test_cmp5(self):
-        v1 = SIPpVersion("v3.1-TLS")
-        v2 = SIPpVersion("v3.1-TLS")
+        v1 = SIPpVersion("v3.1", "TLS")
+        v2 = SIPpVersion("v3.1", "TLS")
         self.assertTrue(v1 == v2)
 
     def test_cmp6(self):
+        v1 = SIPpVersion("TLS")
+        v2 = SIPpVersion("TLS")
+        self.assertTrue(v1 == v2)
+
+    def test_cmp7(self):
         v1 = SIPpVersion("v2.0.1")
         v2 = SIPpVersion("v2.0.1")
         self.assertTrue(v1 == v2)
 
-    def test_cmp7(self):
-        v1 = SIPpVersion("v3.2-TLS")
-        v2 = SIPpVersion("v3.2-PCAP")
+    def test_cmp8(self):
+        v1 = SIPpVersion("v3.2", "TLS")
+        v2 = SIPpVersion("v3.2", "PCAP")
         self.assertTrue(v1 != v2)
 
-    def test_cmp8(self):
-        v1 = SIPpVersion("v3.2-TLS")
-        v2 = SIPpVersion("v3.2-PCAP")
+    def test_cmp9(self):
+        v1 = SIPpVersion("TLS")
+        v2 = SIPpVersion("PCAP")
+        self.assertTrue(v1 != v2)
+
+    def test_cmp10(self):
+        v1 = SIPpVersion("v3.2", "TLS")
+        v2 = SIPpVersion("v3.2", "PCAP")
         self.assertFalse(v1 == v2)
 
-    def test_cmp9(self):
-        v1 = SIPpVersion("v3.2-TLS-PCAP")
-        v2 = SIPpVersion("v3.2-TLS")
-        self.assertTrue(v1 > v2)
-
-    def test_cmp10(self):
-        v1 = SIPpVersion("v3.2-TLS-PCAP")
-        v2 = SIPpVersion("v3.2-PCAP")
-        self.assertTrue(v1 > v2)
-
     def test_cmp11(self):
-        v1 = SIPpVersion("v3.2-TLS-PCAP")
-        v2 = SIPpVersion("v3.2-TLS")
+        v1 = SIPpVersion("TLS")
+        v2 = SIPpVersion("PCAP")
+        self.assertFalse(v1 == v2)
+
+    def test_cmp12(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("v3.2", "TLS")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp13(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("TLS")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp14(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("v3.2", "PCAP")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp15(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("PCAP")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp16(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("v3.2", "TLS")
         self.assertTrue(v1 != v2)
 
-    def test_cmp12(self):
-        v1 = SIPpVersion("v3.2-TLS-PCAP")
-        v2 = SIPpVersion("v3.2-TLS")
+    def test_cmp17(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("TLS")
+        self.assertTrue(v1 != v2)
+
+    def test_cmp18(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("v3.2", "TLS")
         self.assertFalse(v1 == v2)
 
-    def test_cmp13(self):
-        v1 = SIPpVersion("v3.2-TLS-PCAP")
-        v2 = SIPpVersion("v2.0.1-PCAP")
-        self.assertTrue(v1 > v2)
-
-    def test_cmp14(self):
-        v1 = SIPpVersion("v3.1-TLS")
-        v2 = SIPpVersion("v3.1-PCAP")
+    def test_cmp19(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("TLS")
+        self.assertFalse(v1 == v2)
+
+    def test_cmp20(self):
+        v1 = SIPpVersion("v3.1", "PCAP")
+        v2 = SIPpVersion("v3.0", "TLS")
         self.assertFalse(v1 > v2)
 
-    def test_cmp15(self):
-        v1 = SIPpVersion("v3.1-TLS")
-        v2 = SIPpVersion("v3.1-PCAP")
+    def test_cmp21(self):
+        v1 = SIPpVersion("v3.2", "TLS-PCAP")
+        v2 = SIPpVersion("v2.0.1", "PCAP")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp22(self):
+        v1 = SIPpVersion("v3.1", "TLS")
+        v2 = SIPpVersion("v3.1", "PCAP")
+        self.assertFalse(v1 > v2)
+
+    def test_cmp23(self):
+        v1 = SIPpVersion("v3.1", "TLS")
+        v2 = SIPpVersion("v3.1", "PCAP")
         self.assertFalse(v1 < v2)
 
-    def test_cmp16(self):
-        v1 = SIPpVersion("v3.2-TLS")
-        v2 = SIPpVersion("v3.1-TLS-PCAP")
-        self.assertTrue(v1 > v2)
+    def test_cmp24(self):
+        v1 = SIPpVersion("v3.2", "TLS")
+        v2 = SIPpVersion("v3.1", "TLS-PCAP")
+        self.assertTrue(v1 >= v2)
+
+    def test_cmp25(self):
+        v1 = SIPpVersion("v3.1", "TLS-PCAP")
+        v2 = SIPpVersion("v3.2", "PCAP")
+        self.assertTrue(v1 <= v2)
 
 
 def main():




More information about the asterisk-commits mailing list