[asterisk-commits] pabelanger: branch pabelanger/SWP-2533 r1586 - /asterisk/team/pabelanger/SWP-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 25 10:36:13 CDT 2011


Author: pabelanger
Date: Wed May 25 10:36:09 2011
New Revision: 1586

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1586
Log:
Convert test to TestCase

Modified:
    asterisk/team/pabelanger/SWP-2533/tests/dynamic-modules/run-test

Modified: asterisk/team/pabelanger/SWP-2533/tests/dynamic-modules/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/SWP-2533/tests/dynamic-modules/run-test?view=diff&rev=1586&r1=1585&r2=1586
==============================================================================
--- asterisk/team/pabelanger/SWP-2533/tests/dynamic-modules/run-test (original)
+++ asterisk/team/pabelanger/SWP-2533/tests/dynamic-modules/run-test Wed May 25 10:36:09 2011
@@ -9,40 +9,18 @@
 
 import sys
 import os
-import shutil
-import time
-from twisted.application import service, internet
-from twisted.internet import reactor, defer
-from starpy import manager
+
+from twisted.internet import reactor
 
 sys.path.append("lib/python")
 from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
 
-workingdir = "/tmp/asterisk-testsuite/dynamic-modules"
-testdir = "tests/dynamic-modules"
 
-class moduleLoadUnloadTest:
-    def __init__(self):
-        self.passed = False
-        self.last_step = ""
-
-        reactor.callWhenRunning(self.run)
-
-        print "Creating Asterisk instance ..."
-        self.asterisk = Asterisk(base=workingdir)
-        self.asterisk.install_configs("%s/configs/ast1" % (testdir))
-
-    def stop_reactor(self):
-        print "Stopping Reactor ..."
-        if reactor.running:
-            reactor.stop()
-
-    def start_asterisk(self):
-        print "Starting Asterisk ..."
-        self.asterisk.start()
-
-    def stop_asterisk(self):
-        self.asterisk.stop()
+class moduleLoadUnloadTest(TestCase):
+    def __init__(self, argv):
+        TestCase.__init__(self, argv)
+        self.create_asterisk()
 
     def load_module(self, module):
         if not self.check_file(module):
@@ -50,19 +28,20 @@
             return False
 
         text = "Loaded " + module[0]
-        res = self.asterisk.cli_exec("module load " + module[0])
+        res = self.ast[0].cli_exec("module load " + module[0])
         if res.count(text) > 0:
             module[2] = True
         return module[2]
 
     def unload_module(self, module):
         text = "Unloaded " + module[0]
-        res = self.asterisk.cli_exec("module unload " + module[0])
+        res = self.ast[0].cli_exec("module unload " + module[0])
         if res.count(text) > 0:
             module[3] = True
 
     def check_file(self, module):
-        module[1] = os.path.isfile(self.asterisk.base + "/usr/lib/asterisk/modules/" + module[0])
+        module[1] = (os.path.isfile(self.ast[0].base +
+            "/usr/lib/asterisk/modules/" + module[0]))
         return module[1]
 
     def check_failures(self, module):
@@ -75,12 +54,10 @@
             self.passed = False
 
     def run(self):
+        TestCase.run(self)
         self.passed = True
         preload_res = []
         res = []
-
-        # A timeout in case things hang and fail
-        reactor.callLater(20, self.stop_reactor)
 
         # TODO: Do not hardcode, read from source code. 
         preload_resources = ["res_calendar", "res_curl", "res_fax", "res_odbc"]
@@ -92,7 +69,7 @@
         # TODO: Fixed res_http_post crash
         resources = ["res_adsi", "res_ael_share", "res_agi", "res_ais", "res_calendar_caldav", "res_calendar_exchange", "res_calendar_icalendar", "res_clialiases", "res_clioriginate", "res_config_curl", "res_config_ldap", "res_config_odbc", "res_config_pgsql", "res_config_sqlite", "res_convert", "res_crypto", "res_fax_spandsp", "res_jabber", "res_limit", "res_monitor", "res_musiconhold", "res_mutestream", "res_phoneprov", "res_pktccops", "res_realtime", "res_rtp_asterisk", "res_rtp_multicast", "res_security_log", "res_smdi", "res_snmp", "res_speech", "res_timing_dahdi", "res_timing_kqueue", "res_timing_pthread", "res_timing_timerfd"]
 
-        res = [ (module + ".so", False, False, False) for module in resources ]
+        res = [ [module + ".so", False, False, False] for module in resources ]
 
         for module in preload_res:
             self.load_module(module)
@@ -169,8 +146,11 @@
 
             self.check_failures(module);
 
-def main():
-    test = moduleLoadUnloadTest()
+def main(argv=None):
+    if argv is None:
+        argv = sys.argv
+
+    test = moduleLoadUnloadTest(argv)
     test.start_asterisk()
     reactor.run()
     test.stop_asterisk()




More information about the asterisk-commits mailing list