[asterisk-commits] kmoore: testsuite/asterisk/trunk r2724 - in /asterisk/trunk: ./ lib/python/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 14 13:37:48 CST 2011


Author: kmoore
Date: Mon Nov 14 13:37:45 2011
New Revision: 2724

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=2724
Log:
TestSuite: Add ability for tests to be executed in subsets based on tags

(closes issue ASTERISK-18427)

Modified:
    asterisk/trunk/README.txt
    asterisk/trunk/lib/python/asterisk/TestConfig.py
    asterisk/trunk/runtests.py

Modified: asterisk/trunk/README.txt
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/README.txt?view=diff&rev=2724&r1=2723&r2=2724
==============================================================================
--- asterisk/trunk/README.txt (original)
+++ asterisk/trunk/README.txt Mon Nov 14 13:37:45 2011
@@ -453,6 +453,12 @@
             # test execution are tracked throughout the test; if any additional file descriptors
             # after test execution are detected, the test condition fails.
             name: 'file-descriptors'
+    tags: # OPTIONAL
+        #
+        # List of tags used to select a subset of tests to run.  A test must have all tags to run.
+        #
+        -   core # This test is part of the core support level.
+        -   voicemail # This test involves voicemail functionality.
 
 
 --------------------------------------------------------------------------------

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=2724&r1=2723&r2=2724
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestConfig.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestConfig.py Mon Nov 14 13:37:45 2011
@@ -242,6 +242,7 @@
         self.minversion = None
         self.minversion_check = False
         self.deps = []
+        self.tags = []
         self.expectPass = True
         self.excludedTests = []
         self.test_configuration = "(none)"
@@ -404,4 +405,42 @@
             if d.met is False:
                 self.can_run = False
                 break
-        return self.can_run
+        return self.can_run
+
+    def check_tags(self, requested_tags):
+        """
+        Check whether or not a test should execute based on its tags
+
+        Keyword arguments:
+        requested_tags -- The list of tags used for selecting a subset of
+            tests.  The test must have all tags to run.
+        returns can_run - True if the test can execute, False otherwise
+        """
+
+        if not self.config:
+            return False
+
+        if "properties" in self.config:
+            self.tags = self.config["properties"].get("tags")
+
+        # if no tags are requested, this test's tags don't matter
+        if not requested_tags or not len(requested_tags):
+            return self.can_run
+
+        for tag in requested_tags:
+            if tag.startswith("-"):
+                try:
+                    self.tags.index(tag[1:])
+                    self.can_run = False
+                    return self.can_run
+                except:
+                    pass
+            else:
+                try:
+                    self.tags.index(tag)
+                except:
+                    self.can_run = False
+                    return self.can_run
+
+        # all tags matched successfully
+        return self.can_run

Modified: asterisk/trunk/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/runtests.py?view=diff&rev=2724&r1=2723&r2=2724
==============================================================================
--- asterisk/trunk/runtests.py (original)
+++ asterisk/trunk/runtests.py Mon Nov 14 13:37:45 2011
@@ -38,7 +38,7 @@
         self.options = options
         self.test_config = TestConfig(test_name)
         self.failure_message = ""
-        self.__check_deps(ast_version)
+        self.__check_can_run(ast_version)
         self.stdout = ""
 
     def run(self):
@@ -179,8 +179,11 @@
                 break
             i += 1
 
-    def __check_deps(self, ast_version):
-        self.can_run = self.test_config.check_deps(ast_version)
+    def __check_can_run(self, ast_version):
+        """Check tags and dependencies in the test config."""
+        if self.test_config.check_deps(ast_version) and \
+                self.test_config.check_tags(self.options.tags):
+            self.can_run = True
 
     def __parse_run_output(self, output):
         self.failure_message = output
@@ -264,6 +267,7 @@
                 if t.test_config.maxversion is not None:
                     print "--- --> Maximum Version: %s (%s)" % \
                         (str(t.test_config.maxversion), str(t.test_config.maxversion_check))
+                print "--- --> Tags: %s" % (t.test_config.tags)
                 for d in t.test_config.deps:
                     print "--- --> Dependency: %s - %s" % (d.name, str(d.met))
                 print
@@ -372,6 +376,9 @@
     parser.add_option("-t", "--test",
             dest="test",
             help="Run a single specified test instead of all tests.")
+    parser.add_option("-g", "--tag", action="append",
+            dest="tags",
+            help="Specify one or more tags to select a subset of tests.")
     parser.add_option("-v", "--version",
             dest="version", default=None,
             help="Specify the version of Asterisk rather then detecting it.")




More information about the asterisk-commits mailing list