[asterisk-commits] mjordan: testsuite/asterisk/trunk r3272 - in /asterisk/trunk: ./ lib/python/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 21 09:06:16 CDT 2012


Author: mjordan
Date: Thu Jun 21 09:06:06 2012
New Revision: 3272

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3272
Log:
Rework the Asterisk Test Suite version parsing

This patch does the following:
* Updates the Asterisk Test Suite version parsing to better handle the concept
  of features.  It adds understanding of two features: 'cert' and
  'digiumphones'.  Tests that have a feature of 'cert' automatically imply
  a feature of 'digiumphones'.  Tests can specify that they require the version
  under test to have a particular feature using the 'features' key in their
  test-config.yaml file.
* Updates version string parsing to handle feature tags.  Simplifies the logic
  somewhat by dropping support for 1.4 and 1.6.x branches.  Simplifies version
  handling as well by 'normalizing' versions of 1.8, 10, and 11 to internally
  use the same scheme.
* Updates all tests and internal documentation to refer to 'minversion' as
  an actual release version tag.  Hence, the appropriate way to refer to the
  minimum version of Asterisk needed to run a test would be '1.8.11.1' or
  '10.1.4' or '1.8.11-cert3'.

(closes issue ASTERISK-19818)
Repoted by: Matt Jordan
Tested by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/1982


Modified:
    asterisk/trunk/README.txt
    asterisk/trunk/lib/python/asterisk/TestConfig.py
    asterisk/trunk/lib/python/asterisk/version.py
    asterisk/trunk/runtests.py
    asterisk/trunk/tests/agi/exit_status/test-config.yaml
    asterisk/trunk/tests/apps/bridge/bridge_baseline/test-config.yaml
    asterisk/trunk/tests/apps/bridge/bridge_transfer_callee/test-config.yaml
    asterisk/trunk/tests/apps/confbridge/confbridge_nominal/test-config.yaml
    asterisk/trunk/tests/apps/confbridge/confbridge_recording/test-config.yaml
    asterisk/trunk/tests/apps/directory_attendant_exit/test-config.yaml
    asterisk/trunk/tests/apps/directory_context_operator_exit/test-config.yaml
    asterisk/trunk/tests/apps/directory_operator_exit/test-config.yaml
    asterisk/trunk/tests/apps/incomplete/sip_incomplete/test-config.yaml
    asterisk/trunk/tests/apps/page/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_callback/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_delete/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_dialout/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_envelope/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward_hangup/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward_with_prepend/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_new_user/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_new_user_hangup/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_nominal/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_change_password/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_busy/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_name/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_temp/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_unavail/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_reply/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/check_voicemail_while_leaving_msg/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/func_vmcount/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_external_notification/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml
    asterisk/trunk/tests/blind-transfer-parkingtimeout/test-config.yaml
    asterisk/trunk/tests/callparking/test-config.yaml
    asterisk/trunk/tests/callparking_retrieval/test-config.yaml
    asterisk/trunk/tests/cause_answered_elsewhere/test-config.yaml
    asterisk/trunk/tests/cdr/app_dial_G_flag/test-config.yaml
    asterisk/trunk/tests/cdr/app_queue/test-config.yaml
    asterisk/trunk/tests/cdr/blind-transfer-accountcode/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_accountcode/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_unanswered_yes/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_userfield/test-config.yaml
    asterisk/trunk/tests/cdr/console_dial_sip_answer/test-config.yaml
    asterisk/trunk/tests/cdr/console_dial_sip_busy/test-config.yaml
    asterisk/trunk/tests/cdr/console_dial_sip_congestion/test-config.yaml
    asterisk/trunk/tests/cdr/console_dial_sip_transfer/test-config.yaml
    asterisk/trunk/tests/cdr/console_fork_after_busy_forward/test-config.yaml
    asterisk/trunk/tests/cdr/console_fork_before_dial/test-config.yaml
    asterisk/trunk/tests/cdr/nocdr/test-config.yaml
    asterisk/trunk/tests/cdr/originate-cdr-disposition/test-config.yaml
    asterisk/trunk/tests/channels/SIP/custom_info/test-config.yaml
    asterisk/trunk/tests/channels/SIP/generic_ccss/test-config.yaml
    asterisk/trunk/tests/channels/SIP/handle_response_address_incomplete/test-config.yaml
    asterisk/trunk/tests/channels/SIP/handle_response_refer/test-config.yaml
    asterisk/trunk/tests/channels/SIP/hangupcause/test-config.yaml
    asterisk/trunk/tests/channels/SIP/info_dtmf/test-config.yaml
    asterisk/trunk/tests/channels/SIP/invite_no_totag/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_auth/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_auth_cust_hdr/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_disabled/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_from_call/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_mark_all_outbound/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_send_ami/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_unauth/test-config.yaml
    asterisk/trunk/tests/channels/SIP/message_unauth_from/test-config.yaml
    asterisk/trunk/tests/channels/SIP/nat_supertest/test-config.yaml
    asterisk/trunk/tests/channels/SIP/noload_res_srtp/test-config.yaml
    asterisk/trunk/tests/channels/SIP/noload_res_srtp_attempt_srtp/test-config.yaml
    asterisk/trunk/tests/channels/SIP/options/test-config.yaml
    asterisk/trunk/tests/channels/SIP/pcap_demo/test-config.yaml
    asterisk/trunk/tests/channels/SIP/realtime_nosipregs/test-config.yaml
    asterisk/trunk/tests/channels/SIP/realtime_sipregs/test-config.yaml
    asterisk/trunk/tests/channels/SIP/refer_replaces_to_self/test-config.yaml
    asterisk/trunk/tests/channels/SIP/secure_bridge_media/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip2cause/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_attended_transfer/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_attended_transfer_tcp/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_attended_transfer_v6/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_cause/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_channel_params/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/multiple_state_change/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/nominal_state_change/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/non_digium_state_change/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/resubscribe/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_one_legged_transfer/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_one_legged_transfer_v6/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_outbound_address/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_outbound_proxy/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_register/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_srtp/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_tls_call/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip_tls_register/test-config.yaml
    asterisk/trunk/tests/channels/SIP/tcpauthlimit/test-config.yaml
    asterisk/trunk/tests/channels/SIP/tcpauthtimeout/test-config.yaml
    asterisk/trunk/tests/channels/SIP/use_contact_from_200/test-config.yaml
    asterisk/trunk/tests/chanspy/chanspy_barge/test-config.yaml
    asterisk/trunk/tests/chanspy/chanspy_w_mixmonitor/test-config.yaml
    asterisk/trunk/tests/connected_line/macro/test-config.yaml
    asterisk/trunk/tests/connected_line/subroutine/test-config.yaml
    asterisk/trunk/tests/dialplan/test-config.yaml
    asterisk/trunk/tests/directed_pickup/test-config.yaml
    asterisk/trunk/tests/dynamic-modules/test-config.yaml
    asterisk/trunk/tests/example/test-config.yaml
    asterisk/trunk/tests/fastagi/channel-status/test-config.yaml
    asterisk/trunk/tests/fastagi/connect/test-config.yaml
    asterisk/trunk/tests/fastagi/control-stream-file/test-config.yaml
    asterisk/trunk/tests/fastagi/database/test-config.yaml
    asterisk/trunk/tests/fastagi/execute/test-config.yaml
    asterisk/trunk/tests/fastagi/get-data/test-config.yaml
    asterisk/trunk/tests/fastagi/hangup/test-config.yaml
    asterisk/trunk/tests/fastagi/record-file/test-config.yaml
    asterisk/trunk/tests/fastagi/say-alpha/test-config.yaml
    asterisk/trunk/tests/fastagi/say-date/test-config.yaml
    asterisk/trunk/tests/fastagi/say-datetime/test-config.yaml
    asterisk/trunk/tests/fastagi/say-digits/test-config.yaml
    asterisk/trunk/tests/fastagi/say-number/test-config.yaml
    asterisk/trunk/tests/fastagi/say-phonetic/test-config.yaml
    asterisk/trunk/tests/fastagi/say-time/test-config.yaml
    asterisk/trunk/tests/fastagi/stream-file/test-config.yaml
    asterisk/trunk/tests/fastagi/wait-for-digit/test-config.yaml
    asterisk/trunk/tests/fax/gateway_g711_t38/test-config.yaml
    asterisk/trunk/tests/fax/gateway_mix1/test-config.yaml
    asterisk/trunk/tests/fax/gateway_mix2/test-config.yaml
    asterisk/trunk/tests/fax/gateway_mix3/test-config.yaml
    asterisk/trunk/tests/fax/gateway_mix4/test-config.yaml
    asterisk/trunk/tests/fax/gateway_native_t38/test-config.yaml
    asterisk/trunk/tests/fax/gateway_native_t38_ced/test-config.yaml
    asterisk/trunk/tests/fax/gateway_no_t38/test-config.yaml
    asterisk/trunk/tests/fax/gateway_t38_g711/test-config.yaml
    asterisk/trunk/tests/fax/gateway_timeout1/test-config.yaml
    asterisk/trunk/tests/fax/gateway_timeout2/test-config.yaml
    asterisk/trunk/tests/fax/gateway_timeout3/test-config.yaml
    asterisk/trunk/tests/fax/gateway_timeout4/test-config.yaml
    asterisk/trunk/tests/fax/gateway_timeout5/test-config.yaml
    asterisk/trunk/tests/fax/local_channel_t38_queryoption/test-config.yaml
    asterisk/trunk/tests/feature_attended_transfer/test-config.yaml
    asterisk/trunk/tests/func_presencestate/test-config.yaml
    asterisk/trunk/tests/func_srv/test-config.yaml
    asterisk/trunk/tests/iax2/basic-call/test-config.yaml
    asterisk/trunk/tests/manager/action-events-response/test-config.yaml
    asterisk/trunk/tests/manager/authlimit/test-config.yaml
    asterisk/trunk/tests/manager/authtimeout/test-config.yaml
    asterisk/trunk/tests/manager/login/test-config.yaml
    asterisk/trunk/tests/manager/response-time/test-config.yaml
    asterisk/trunk/tests/masquerade/test-config.yaml
    asterisk/trunk/tests/mixmonitor/test-config.yaml
    asterisk/trunk/tests/mixmonitor_audiohook_inherit/test-config.yaml
    asterisk/trunk/tests/one-step-parking/test-config.yaml
    asterisk/trunk/tests/pbx/call-files/test-config.yaml
    asterisk/trunk/tests/pbx/call-files2/test-config.yaml
    asterisk/trunk/tests/pbx/merge_contexts/test-config.yaml
    asterisk/trunk/tests/pbx/pbx_lua_background/test-config.yaml
    asterisk/trunk/tests/pbx/pbx_lua_goto/test-config.yaml
    asterisk/trunk/tests/queues/position_priority_maxlen/test-config.yaml
    asterisk/trunk/tests/queues/queue_baseline/test-config.yaml
    asterisk/trunk/tests/queues/queue_transfer_callee/test-config.yaml
    asterisk/trunk/tests/queues/ringinuse_and_pause/test-config.yaml
    asterisk/trunk/tests/queues/set_penalty/test-config.yaml
    asterisk/trunk/tests/redirecting/macro/test-config.yaml
    asterisk/trunk/tests/redirecting/subroutine/test-config.yaml
    asterisk/trunk/tests/regressions/M18882/test-config.yaml
    asterisk/trunk/tests/rfc2833_dtmf_detect/test-config.yaml
    asterisk/trunk/tests/skeleton_test/test-config.yaml
    asterisk/trunk/tests/udptl/test-config.yaml
    asterisk/trunk/tests/udptl_v6/test-config.yaml

Modified: asterisk/trunk/README.txt
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/README.txt?view=diff&rev=3272&r1=3271&r2=3272
==============================================================================
--- asterisk/trunk/README.txt (original)
+++ asterisk/trunk/README.txt Thu Jun 21 09:06:06 2012
@@ -404,9 +404,14 @@
 # The properties section contains information about requirements and
 # dependencies for this test.
 properties:
-    minversion : '1.4' # minimum Asterisk version compatible with this test
+    minversion : '1.8.0.0' # minimum Asterisk version compatible with this test
     buildoption : 'TEST_FRAMEWORK' # OPTIONAL - Asterisk compilation flag
-    maxversion : '1.8' # OPTIONAL
+    maxversion : '10.5.1' # OPTIONAL
+    features:
+        # List features the Asterisk version under test must support for this test
+        # to execute.  All features must be satisfied for the test to run.
+        - 'digiumphones'
+        - 'cert'
     dependencies : |   # OPTIONAL
         # List dependencies that must be met for this test to run
         #

Modified: asterisk/trunk/lib/python/asterisk/TestConfig.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestConfig.py?view=diff&rev=3272&r1=3271&r2=3272
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestConfig.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestConfig.py Thu Jun 21 09:06:06 2012
@@ -82,20 +82,6 @@
             obj = m(self)
             return obj
         return None
-
-
-class SkipTest:
-    def __init__(self, skip):
-        self.name = ""
-        self.met = True
-        if "branch" in skip:
-            self.name = skip["branch"]
-            tmp = "%s-%s-%s" % ("SVN-branch", skip["branch"], "r12345")
-            ast_version = AsteriskVersion()
-            version = AsteriskVersion(tmp)
-            if ast_version.is_same_branch(version):
-                self.met = False
-
 
 class Dependency:
     """
@@ -258,10 +244,11 @@
         self.minversion = None
         self.minversion_check = False
         self.deps = []
-        self.skips = []
         self.tags = []
         self.expectPass = True
         self.excludedTests = []
+        self.features = []
+        self.feature_check = {}
         self.test_configuration = "(none)"
         self.condition_definitions = []
         self.global_test_config = global_test_config
@@ -320,6 +307,9 @@
                 self.can_run = False
                 print "ERROR: '%s' is not a valid minversion" % \
                         properties["minversion"]
+            if self.minversion.feature:
+                self.features.append(self.minversion.feature)
+                self.feature_check[self.minversion.feature] = False
         if "maxversion" in properties:
             try:
                 self.maxversion = AsteriskVersion(properties["maxversion"])
@@ -336,8 +326,10 @@
                         properties["expectedResult"]
         if "tags" in properties:
             self.tags = properties["tags"]
-        if "skip" in properties:
-            self.skip = properties["skip"]
+        if "feature" in properties:
+            self.features.extend(properties["features"])
+            for f in self.features:
+                self.feature_check[f] = False
 
     def __parse_config(self):
         test_config = "%s/test-config.yaml" % self.test_name
@@ -422,22 +414,15 @@
             self.maxversion_check = False
             return self.can_run
 
+        for f in self.features:
+            self.feature_check[f] = ast_version.has_feature(f)
+            if not self.feature_check[f]:
+                self.can_run = False
+
         for d in self.deps:
             if d.met is False:
                 self.can_run = False
                 break
-        return self.can_run
-
-    def check_skip(self, ast_version):
-        if not self.config:
-            return False
-
-        self.skips = [
-            SkipTest(s)
-                for s in self.config["properties"].get("skip") or []
-        ]
-
-        self.can_run = all([s.met for s in self.skips if s.met is False])
         return self.can_run
 
     def check_tags(self, requested_tags):

Modified: asterisk/trunk/lib/python/asterisk/version.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/version.py?view=diff&rev=3272&r1=3271&r2=3272
==============================================================================
--- asterisk/trunk/lib/python/asterisk/version.py (original)
+++ asterisk/trunk/lib/python/asterisk/version.py Thu Jun 21 09:06:06 2012
@@ -5,8 +5,9 @@
 This module implements an Asterisk version string parser.  It can also compare
 version strings to determine which version is considered newer.
 
-Copyright (C) 2010, Digium, Inc.
+Copyright (C) 2012, Digium, Inc.
 Russell Bryant <russell at digium.com>
+Matt Jordan <mjordan at digium.com>
 
 This program is free software, distributed under the terms of
 the GNU General Public License Version 2.
@@ -15,6 +16,7 @@
 import re
 import unittest
 import logging
+import sys
 import subprocess
 
 import TestSuiteUtils
@@ -26,124 +28,196 @@
 
     This class handles Asterisk version strings.
     """
+
+    supported_features = [ 'cert', 'digiumphones' ]
+
+    supported_modifiers = [ 'rc', 'beta' ]
+
     def __init__(self, version=None):
         """Construct an Asterisk Version parser.
 
         Keyword Arguments:
         version -- The Asterisk version string to parse.
         """
-        self.svn = False
-        self.phone = None
-
-        if version is not None:
-            self.version_str = version
+
+        if not version:
+            version = AsteriskVersion.get_asterisk_version_from_binary()
+
+        self.raw_version = version
+
+        (self.major,
+         self.minor,
+         self.patch,
+         self.iteration,
+         self.revision,
+         self.branch,
+         self.svn,
+         self.name,
+         self.feature,
+         self.modifier,
+         self.parent) = self._parse_version_string(self.raw_version)
+
+    def __str__(self):
+        return self.raw_version
+
+    def __int__(self):
+        if self.name:
+            return sys.maxint
+        elif (self.branch):
+            # Branches are a little odd.  The more you specify, the less your calculated
+            # value is.  This keeps the following relationships true:
+            # branch-1.8 > 1.8.12.0 > branch-1.8.11-cert
+            value = self.major * 100000000
+            if (self.minor == 0):
+                value += 9900000
+            else:
+                value += self.minor * 100000
+            if (self.patch == 0):
+                value += 99000
+            else:
+                value += self.patch * 1000
+            value += 999
+            return value
         else:
-            self.version_str = self.get_asterisk_version_from_binary()
-
-        if self.version_str[:3] == "SVN":
-            self.__parse_svn_version()
+            return self._modifier_weight() + self.patch * 1000 + self.minor * 100000 + self.major * 100000000
+
+    def __cmp__(self, other):
+        self_value = int(self)
+        other_value = int(other)
+        res = cmp(int(self), int(other))
+        if res == 0:
+            if self.svn and other.svn:
+                res = cmp(self.revision, other.revision)
+
+        return res
+
+    def _parse_version_string(self, raw_version):
+        branch = False
+        svn = False
+        feature = ''
+        parsed_numbers = [0, 0, 0]
+        name = ''
+        revision = 0
+        parent = ''
+        iteration = 0
+        modifier = ''
+
+        raw_version = raw_version.replace('Asterisk ', '')
+
+        tokens = raw_version.split('-')
+        count = 0
+        while (count < len(tokens)):
+            token = tokens[count]
+            # Determine if we're a subversion branch
+            if 'SVN' == token:
+                svn = True
+            elif 'branch' == token:
+                branch = True
+            else:
+                if svn and not branch and not name:
+                    # Team branch or trunk.  This will modify the current position
+                    # based on the number of tokens consumed
+                    (name, munched) = self._parse_branch_name(tokens[count:])
+                    count += munched
+                else:
+                    handled = False
+                    if (len([num for num in parsed_numbers if num != 0]) == 0):
+                        (parsed_numbers, handled) = self._parse_version(token)
+                    if not handled and revision == 0:
+                        (revision, handled) = self._parse_revision(token)
+                    if not handled and not feature:
+                        # If a feature returns back a number, its actually the 'patch' version
+                        # number (e.g., 1.8.11-cert3)
+                        (feature, temp, handled) = self._parse_feature(token)
+                        if (temp > 0):
+                            parsed_numbers[2] = temp
+                    if not handled and not modifier:
+                        (modifier, iteration, handled) = self._parse_version_modifier(token)
+                    if not handled and not parent:
+                        (parent, handled) = self._parse_parent_branch(token)
+                    if not handled:
+                        logger.error("Unable to parse token '%s' in version string '%s'" %
+                                     (token, raw_version))
+            count += 1
+        return (parsed_numbers[0], parsed_numbers[1], parsed_numbers[2], iteration,
+                revision, branch, svn, name, feature, modifier, parent)
+
+    def _parse_branch_name(self, branch_tokens):
+        name = branch_tokens[0]
+        munched = 0
+        for i in range(1, len(branch_tokens)):
+            # Stop when we hit the revision
+            if branch_tokens[i][0] == 'r':
+                candidate = branch_tokens[i].replace('r','').replace('M','').replace('m','')
+                if candidate.isdigit():
+                    break
+            name += '-' + branch_tokens[i]
+            munched += 1
+        return (name, munched)
+
+    def _parse_version(self, version_string):
+        parsed_numbers = [0,0,0]
+        version_tokens = version_string.split('.')
+        count = 0
+        if not version_tokens[0].isdigit():
+            return (parsed_numbers, False)
+        for token in version_tokens:
+            if count == 0 and int(token) == 1:
+                # Skip '1' in '1.8' branches - it adds no value
+                continue
+            parsed_numbers[count] = int(token)
+            count += 1
+        return (parsed_numbers, True)
+
+    def _parse_revision(self, revision_string):
+        candidate = revision_string.replace('M', '').replace('r','').replace('m','')
+        if candidate.isdigit():
+            return (int(candidate), True)
+        return (0, False)
+
+    def _parse_feature(self, feature_string):
+        for f in AsteriskVersion.supported_features:
+            if f in feature_string:
+                feature_string = feature_string.replace(f, '')
+                iteration = -1
+                if (len(feature_string) > 0):
+                    iteration = int(feature_string)
+                return (f, iteration, True)
+        return ('', -1, False)
+
+    def _parse_version_modifier(self, version_modifier):
+        for m in AsteriskVersion.supported_modifiers:
+            if m in version_modifier:
+                version_modifier = version_modifier.replace(m, '')
+                iteration = -1
+                if (len(version_modifier) > 0):
+                    iteration = int(version_modifier)
+                return (m, iteration, True)
+        return ('', -1, False)
+
+    def _parse_parent_branch(self, parent_branch):
+        # Parent branch can be just about anything, so just accept it.
+        # This should be the last thing called.
+        return (parent_branch, True)
+
+    def _modifier_weight(self):
+        if self.modifier:
+            if self.modifier == 'rc':
+                return self.iteration * 10
+            else:
+                return self.iteration
+        return 100
+
+    def has_feature(self, feature):
+        if (self.name or self.major == 11):
+            # Assume that 11 or trunk has all the features
+            return True
+        if feature == self.feature:
+            return True
         else:
-            self.__parse_version()
-
-    def __str__(self):
-        return self.version_str
-
-    def __int__(self):
-        if self.svn is True:
-            if self.branch == "trunk":
-                res = 9999999999
-            elif self.branch[:6] == "branch":
-                res = int(AsteriskVersion(self.branch[7:]))
-            else:
-                # team branch XXX (may not be off of trunk)
-                res = 9999999999
-        else:
-            res = int(self.concept) * 100000000
-            if self.major is not None:
-                res += int(self.major) * 1000000
-                if self.minor is not None:
-                    res += int(self.minor) * 10000
-                    if self.patch is not None:
-                        if isinstance(self.patch, (int, long)):
-                            res += self.patch
-                        else:
-                            res += int(self.__parse_version_patch(self.patch))
-                else:
-                    # If no minor version, assume that this is a branch
-                    res += 999999
-        return res
-
-    def __cmp__(self, other):
-        res = cmp(int(self), int(other))
-        if res == 0 and self.svn and other.svn:
-            res = cmp(int(self.revision.split("M")[0]),
-                      int(other.revision.split("M")[0]))
-        return res
-
-    def __parse_version(self):
-        self.svn = False
-        parts = self.version_str.split(".")
-        self.concept = parts[0]
-        self.major = None
-        self.minor = None
-        self.patch = None
-        self.branch = self.__parse_version_branch("branch-%s" % self.concept)
-
-        if len(parts) >= 2:
-            self.major = parts[1]
-        if len(parts) >= 3:
-            self.minor = parts[2]
-            if "-" in self.minor:
-                self.patch = self.__parse_version_patch(self.minor)
-                self.minor = self.minor[:self.minor.find("-")]
-        if len(parts) >= 4:
-            self.patch = parts[3]
-
-        if int(self.concept) == 1:
-            self.branch += ".%s" % self.major
-            if int(self.major) == 6:
-                self.branch += ".%s" % self.minor
-
-    def __parse_svn_version(self):
-        self.svn = True
-        match = re.search(
-                "SVN-(?P<branch>.*)-r(?P<revision>\d+M?)(?:-(?P<parent>.*))?",
-                self.version_str
-        )
-        if match is not None:
-            self.branch = self.__parse_version_branch(match.group("branch"))
-            self.revision = match.group("revision")
-            self.parent = match.group("parent")
-
-    def __parse_version_branch(self, branch):
-        self.phone = '-digiumphones' in branch
-        return branch.replace("-digiumphones", "")
-
-    def __parse_version_patch(self, patch):
-        parts = patch.split("-")
-        ret = int(parts[0])
-        if len(parts) >= 2:
-            versions = [
-                ["rc", 100],
-                ["beta", 10],
-                ["cert", 1000]
-            ]
-            for v, cost in versions:
-                match = re.search(
-                    "%s(?P<%s>.*)" % (v, v),
-                    patch
-                )
-                if match is not None:
-                    ret = int(match.group("%s" % v)) + cost
-                    continue
-        else:
-            ret = ret + 1000
-
-        return ret
-
-    def is_same_branch(self, version):
-        if (version.branch == self.branch) and (version.phone == self.phone):
-            return True
+            if feature == 'digiumphones' and self.feature == 'cert':
+                return True
+        return False
 
     @classmethod
     def get_asterisk_version_from_binary(cls):
@@ -171,207 +245,225 @@
 
 
 class AsteriskVersionTests(unittest.TestCase):
-    def test_version(self):
-        v = AsteriskVersion("1.4.30")
-        self.assertFalse(v.svn)
-        self.assertEqual(str(v), "1.4.30")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "4")
-        self.assertEqual(v.minor, "30")
-        self.assertEqual(v.branch, "branch-1.4")
-
-    def test_version2(self):
-        v = AsteriskVersion("1.4.30.1")
-        self.assertFalse(v.svn)
-        self.assertEqual(str(v), "1.4.30.1")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "4")
-        self.assertEqual(v.minor, "30")
-        self.assertEqual(v.patch, "1")
-        self.assertEqual(v.branch, "branch-1.4")
-
-    def test_version3(self):
-        v = AsteriskVersion("1.6.2")
-        self.assertFalse(v.svn)
-        self.assertEqual(str(v), "1.6.2")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "6")
-        self.assertEqual(v.minor, "2")
-        self.assertEqual(v.branch, "branch-1.6.2")
-
-    def test_version4(self):
+
+    def test_version_18_1(self):
         v = AsteriskVersion("1.8.6.0")
         self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
         self.assertEqual(str(v), "1.8.6.0")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "8")
-        self.assertEqual(v.minor, "6")
-        self.assertEqual(v.patch, "0")
-        self.assertEqual(v.branch, "branch-1.8")
-
-    def test_version5(self):
+        self.assertEqual(v.major, 8)
+        self.assertEqual(v.minor, 6)
+        self.assertEqual(v.patch, 0)
+
+    def test_version_18_2(self):
+        v = AsteriskVersion("Asterisk 1.8.13.1")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "Asterisk 1.8.13.1")
+        self.assertEqual(v.major, 8)
+        self.assertEqual(v.minor, 13)
+        self.assertEqual(v.patch, 1)
+
+    def test_version_10_1(self):
         v = AsteriskVersion("10.0")
         self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
         self.assertEqual(str(v), "10.0")
-        self.assertEqual(v.concept, "10")
-        self.assertEqual(v.major, "0")
-        self.assertEqual(v.branch, "branch-10")
-
-    def test_version6(self):
-        v = AsteriskVersion("10")
-        self.assertFalse(v.svn)
-        self.assertEqual(str(v), "10")
-        self.assertEqual(v.concept, "10")
-        self.assertEqual(v.branch, "branch-10")
-
-    def test_svn_version(self):
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+
+    def test_version_10_2(self):
+        v = AsteriskVersion("Asterisk 10.5.1")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "Asterisk 10.5.1")
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 5)
+        self.assertEqual(v.patch, 1)
+
+    def test_version_11_1(self):
+        v = AsteriskVersion("11")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "11")
+        self.assertEqual(v.major, 11)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+
+    def test_version_11_2(self):
+        v = AsteriskVersion("11.1.9")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "11.1.9")
+        self.assertEqual(v.major, 11)
+        self.assertEqual(v.minor, 1)
+        self.assertEqual(v.patch, 9)
+
+    def test_version_11_3(self):
+        v = AsteriskVersion("Asterisk 11.0")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "Asterisk 11.0")
+        self.assertEqual(v.major, 11)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+
+    def test_svn_version_trunk_1(self):
         v = AsteriskVersion("SVN-trunk-r252849")
         self.assertTrue(v.svn)
+        self.assertFalse(v.branch)
         self.assertEqual(str(v), "SVN-trunk-r252849")
-        self.assertEqual(v.branch, "trunk")
-        self.assertEqual(v.revision, "252849")
-
-    def test_svn_version2(self):
-        v = AsteriskVersion("SVN-branch-1.6.2-r245581M")
-        self.assertTrue(v.svn)
-        self.assertEqual(str(v), "SVN-branch-1.6.2-r245581M")
-        self.assertEqual(v.branch, "branch-1.6.2")
-        self.assertEqual(v.revision, "245581M")
-
-    def test_svn_version3(self):
+        self.assertEqual(v.name, "trunk")
+        self.assertEqual(v.revision, 252849)
+
+    def test_svn_version_trunk_2(self):
+        v = AsteriskVersion("Asterisk SVN-trunk-r252849M")
+        self.assertTrue(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "Asterisk SVN-trunk-r252849M")
+        self.assertEqual(v.name, "trunk")
+        self.assertEqual(v.revision, 252849)
+
+    def test_svn_version_teambranch_1(self):
         v = AsteriskVersion("SVN-russell-cdr-q-r249059M-/trunk")
         self.assertTrue(v.svn)
+        self.assertFalse(v.branch)
         self.assertEqual(str(v), "SVN-russell-cdr-q-r249059M-/trunk")
-        self.assertEqual(v.branch, "russell-cdr-q")
-        self.assertEqual(v.revision, "249059M")
+        self.assertEqual(v.name, "russell-cdr-q")
+        self.assertEqual(v.revision, 249059)
         self.assertEqual(v.parent, "/trunk")
 
-    def test_svn_version4(self):
-        v = AsteriskVersion("SVN-russell-rest-r12345")
-        self.assertTrue(v.svn)
-        self.assertEqual(str(v), "SVN-russell-rest-r12345")
-        self.assertEqual(v.branch, "russell-rest")
-        self.assertEqual(v.revision, "12345")
-
-    def test_svn_version5(self):
-        v = AsteriskVersion("SVN-branch-10-r12345")
-        self.assertTrue(v.svn)
-        self.assertEqual(str(v), "SVN-branch-10-r12345")
-        self.assertEqual(v.branch, "branch-10")
-        self.assertEqual(v.revision, "12345")
-        self.assertFalse(v.phone)
-
-    def test_svn_version6(self):
+    def test_svn_version_teambranch_2(self):
+        v = AsteriskVersion("Asterisk SVN-russell-rest-r12345")
+        self.assertTrue(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(str(v), "Asterisk SVN-russell-rest-r12345")
+        self.assertEqual(v.name, "russell-rest")
+        self.assertEqual(v.revision, 12345)
+
+    def test_svn_branch_10_1(self):
+        v = AsteriskVersion("SVN-branch-10-r11111")
+        self.assertTrue(v.svn)
+        self.assertTrue(v.branch)
+        self.assertEqual(str(v), "SVN-branch-10-r11111")
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+        self.assertEqual(v.revision, 11111)
+
+    def test_svn_branch_18_features_1(self):
         v = AsteriskVersion("SVN-branch-1.8-digiumphones-r357808-/branches/1.8")
         self.assertTrue(v.svn)
-        self.assertEqual(v.branch, "branch-1.8")
-        self.assertEqual(v.revision, "357808")
-        self.assertEqual(v.parent, "/branches/1.8")
-        self.assertTrue(v.phone)
-
-    def test_svn_version7(self):
+        self.assertTrue(v.branch)
+        self.assertEqual(v.major, 8)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+        self.assertEqual(v.revision, 357808)
+        self.assertEqual(v.parent, '/branches/1.8')
+        self.assertTrue(v.feature, 'digiumphones')
+
+    def test_svn_branch_10_features_1(self):
         v = AsteriskVersion("SVN-branch-10-digiumphones-r365402-/branches/10")
         self.assertTrue(v.svn)
-        self.assertEqual(v.branch, "branch-10")
-        self.assertEqual(v.revision, "365402")
-        self.assertEqual(v.parent, "/branches/10")
-        self.assertTrue(v.phone)
-
-    def test_svn_version8(self):
-        v = AsteriskVersion("1.8.11-cert1")
-        self.assertFalse(v.svn)
-        self.assertEqual(str(v), "1.8.11-cert1")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "8")
-        self.assertEqual(v.minor, "11")
-        self.assertEqual(v.patch, 1001)
-
-    def test_svn_version9(self):
+        self.assertTrue(v.branch)
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+        self.assertEqual(v.revision, 365402)
+        self.assertEqual(v.parent, '/branches/10')
+        self.assertEqual(v.feature, 'digiumphones')
+
+    def test_svn_branch_10_features_2(self):
+        v = AsteriskVersion("Asterisk SVN-branch-10-digiumphones-r365402")
+        self.assertTrue(v.svn)
+        self.assertTrue(v.branch)
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 0)
+        self.assertEqual(v.patch, 0)
+        self.assertEqual(v.revision, 365402)
+        self.assertEqual(v.feature, 'digiumphones')
+
+    def test_version_10_with_features_and_modifier(self):
+        v = AsteriskVersion("Asterisk 10.6.1-digiumphones-beta3")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(v.major, 10)
+        self.assertEqual(v.minor, 6)
+        self.assertEqual(v.patch, 1)
+        self.assertEqual(v.feature, 'digiumphones')
+        self.assertEqual(v.modifier, 'beta')
+        self.assertEqual(v.iteration, 3)
+
+    def test_svn_1811_certified_1(self):
+        v = AsteriskVersion("Asterisk 1.8.11-cert1")
+        self.assertFalse(v.svn)
+        self.assertFalse(v.branch)
+        self.assertEqual(v.major, 8)
+        self.assertEqual(v.minor, 11)
+        self.assertEqual(v.patch, 1)
+        self.assertEqual(v.feature, 'cert')
+
+    def test_svn_1811_certified_2(self):
         v = AsteriskVersion("1.8.11-cert2")
         self.assertFalse(v.svn)
-        self.assertEqual(str(v), "1.8.11-cert2")
-        self.assertEqual(v.concept, "1")
-        self.assertEqual(v.major, "8")
-        self.assertEqual(v.minor, "11")
-        self.assertEqual(v.patch, 1002)
-
-    def test_svn_version10(self):
-        v = AsteriskVersion("SVN-branch-1.8.11-r363674")
-        self.assertTrue(v.svn)
-        self.assertEqual(v.branch, "branch-1.8.11")
-        self.assertEqual(v.revision, "363674")
-
-    def test_cmp(self):
-        v1 = AsteriskVersion("1.4")
-        v2 = AsteriskVersion("1.6.0")
-        self.assertTrue(v1 < v2)

[... 2712 lines stripped ...]



More information about the asterisk-commits mailing list