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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Dec 6 20:50:09 CST 2010


Author: pabelanger
Date: Mon Dec  6 20:50:05 2010
New Revision: 1090

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1090
Log:
First version of SIPpVersion class

Added:
    asterisk/team/pabelanger/sipp/lib/python/sipp/
    asterisk/team/pabelanger/sipp/lib/python/sipp/version.py   (with props)

Added: 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=auto&rev=1090
==============================================================================
--- asterisk/team/pabelanger/sipp/lib/python/sipp/version.py (added)
+++ asterisk/team/pabelanger/sipp/lib/python/sipp/version.py Mon Dec  6 20:50:05 2010
@@ -1,0 +1,150 @@
+#!/usr/bin/env python
+"""SIPp Version String Handling
+
+Copyright (C) 2010, Digium, Inc.
+Paul Belanger <pabelanger at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import sys
+import re
+import unittest
+
+class SIPpVersion:
+    """A SIPp Version.
+
+    """
+
+    def __init__(self, version=None):
+        """Constructor
+
+        """
+        if version is not None:
+            self.version_str = version
+
+        if not self.version_str:
+            return
+
+        self.__parse_version()
+
+    def __str__(self):
+        return self.version_str
+
+    def __int__(self):
+        if self.svn is True:
+            return -1
+        else:
+            res = int(self.concept) * 10000000 + int(self.major) * 100000
+            if self.minor is not None:
+                res += int(self.minor) * 1000
+            return res
+
+    def __cmp__(self, other):
+        res = cmp(int(self), int(other))
+        return res
+
+    def __parse_version(self):
+        self.svn = False
+        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
+
+
+class SIPpVersionTests(unittest.TestCase):
+    def test_version(self):
+        v = SIPpVersion("v3.2")
+        self.assertFalse(v.svn)
+        self.assertEqual(str(v), "v3.2")
+        self.assertEqual(v.concept, "v3")
+        self.assertEqual(v.major, "2")
+        self.assertFalse(v.tls)
+        self.assertFalse(v.pcap)
+
+    def test_version2(self):
+        v = SIPpVersion("v2.0.1")
+        self.assertFalse(v.svn)
+        self.assertEqual(str(v), "v2.0.1")
+        self.assertEqual(v.concept, "v2")
+        self.assertEqual(v.major, "0")
+        self.assertEqual(v.minor, "1")
+        self.assertFalse(v.tls)
+        self.assertFalse(v.pcap)
+
+    def test_version3(self):
+        v = SIPpVersion("v3.1-TLS")
+        self.assertFalse(v.svn)
+        self.assertEqual(str(v), "v3.1-TLS")
+        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.assertFalse(v.svn)
+        self.assertEqual(str(v), "v2.0.1-TLS-PCAP")
+        self.assertEqual(v.concept, "v2")
+        self.assertEqual(v.major, "0")
+        self.assertEqual(v.minor, "1")
+        self.assertTrue(v.tls)
+        self.assertTrue(v.pcap)
+
+    def test_version5(self):
+        v = SIPpVersion("v3.2-PCAP")
+        self.assertFalse(v.svn)
+        self.assertEqual(str(v), "v3.2-PCAP")
+        self.assertEqual(v.concept, "v3")
+        self.assertEqual(v.major, "2")
+        self.assertFalse(v.tls)
+        self.assertTrue(v.pcap)
+
+    def test_cmp(self):
+        v1 = SIPpVersion("3.2")
+        v2 = SIPpVersion("3.1")
+        self.assertTrue(v1 > v2)
+
+    def test_cmp2(self):
+        v1 = SIPpVersion("2.0.1")
+        v2 = SIPpVersion("3.1")
+        self.assertTrue(v1 < v2)
+
+    def test_cmp3(self):
+        v1 = SIPpVersion("3.1")
+        v2 = SIPpVersion("3.1")
+        self.assertTrue(v1 == v2)
+
+    def test_cmp4(self):
+        v1 = SIPpVersion("2.0.1")
+        v2 = SIPpVersion("2.0.1")
+        self.assertTrue(v1 == v2)
+
+def main():
+    unittest.main()
+
+
+if __name__ == "__main__":
+    main()

Propchange: asterisk/team/pabelanger/sipp/lib/python/sipp/version.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/pabelanger/sipp/lib/python/sipp/version.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/pabelanger/sipp/lib/python/sipp/version.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list