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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 14 09:43:44 CST 2014


Author: mjordan
Date: Tue Jan 14 09:43:30 2014
New Revision: 4556

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4556
Log:
PEP 8-ify the Asterisk Testsuite python libraries

This patch does a reasonable job of making the Python code in
lib/python/asterisk compliant with PEP 8. (Reasonable being > 9 on the
pylint "how am I doing?" code rating)

A few disclaimers:
(1) This patch does not go into the python code for the tests themselves, other
    than to make the tests run. Making the individual tests PEP 8 compliant
    would be nice, but it's a whole lot more work with less benefit.
(2) Not *everything* was cleaned up in the libraries. In general, this patch
    tries to get the vast majority of findings, but there are a few minor
    nitpicks here and there.
(3) This patch is scarier than it looks. No semantics (hopefully!) were changed
    in the process of doing this: this is all just formatting/guidelines/etc.

Note that this patch does break the world as it renames a number of python
modules, functions, etc.

Next time we'll pay a bit more attention to style when we start these kinds of
projects.... really. I promise.

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



Added:
    asterisk/trunk/lib/python/asterisk/bridge_test_case.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/BridgeTestCase.py
    asterisk/trunk/lib/python/asterisk/channel_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/ChannelTestCondition.py
    asterisk/trunk/lib/python/asterisk/fd_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/FdTestCondition.py
    asterisk/trunk/lib/python/asterisk/lock_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/LockTestCondition.py
    asterisk/trunk/lib/python/asterisk/pluggable_modules.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/PluggableModules.py
    asterisk/trunk/lib/python/asterisk/sip_channel_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
    asterisk/trunk/lib/python/asterisk/sip_dialog_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/SipDialogTestCondition.py
    asterisk/trunk/lib/python/asterisk/test_case.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/lib/python/asterisk/test_conditions.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestConditions.py
    asterisk/trunk/lib/python/asterisk/test_config.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestConfig.py
    asterisk/trunk/lib/python/asterisk/test_runner.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestRunner.py
    asterisk/trunk/lib/python/asterisk/test_state.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestState.py
    asterisk/trunk/lib/python/asterisk/test_suite_utils.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/TestSuiteUtils.py
    asterisk/trunk/lib/python/asterisk/thread_test_condition.py
      - copied, changed from r4509, asterisk/trunk/lib/python/asterisk/ThreadTestCondition.py
Removed:
    asterisk/trunk/lib/python/asterisk/BridgeTestCase.py
    asterisk/trunk/lib/python/asterisk/CDRTestCase.py
    asterisk/trunk/lib/python/asterisk/ChannelTestCondition.py
    asterisk/trunk/lib/python/asterisk/FdTestCondition.py
    asterisk/trunk/lib/python/asterisk/LockTestCondition.py
    asterisk/trunk/lib/python/asterisk/PluggableModules.py
    asterisk/trunk/lib/python/asterisk/SimpleTestCase.py
    asterisk/trunk/lib/python/asterisk/SipChannelTestCondition.py
    asterisk/trunk/lib/python/asterisk/SipDialogTestCondition.py
    asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/lib/python/asterisk/TestConditions.py
    asterisk/trunk/lib/python/asterisk/TestConfig.py
    asterisk/trunk/lib/python/asterisk/TestRunner.py
    asterisk/trunk/lib/python/asterisk/TestState.py
    asterisk/trunk/lib/python/asterisk/TestSuiteUtils.py
    asterisk/trunk/lib/python/asterisk/ThreadTestCondition.py
Modified:
    asterisk/trunk/lib/python/asterisk/ami.py
    asterisk/trunk/lib/python/asterisk/apptest.py
    asterisk/trunk/lib/python/asterisk/ari.py
    asterisk/trunk/lib/python/asterisk/astcsv.py
    asterisk/trunk/lib/python/asterisk/asterisk.py
    asterisk/trunk/lib/python/asterisk/buildoptions.py
    asterisk/trunk/lib/python/asterisk/cdr.py
    asterisk/trunk/lib/python/asterisk/cel.py
    asterisk/trunk/lib/python/asterisk/confbridge.py
    asterisk/trunk/lib/python/asterisk/config.py
    asterisk/trunk/lib/python/asterisk/sipp.py
    asterisk/trunk/lib/python/asterisk/sippversion.py
    asterisk/trunk/lib/python/asterisk/syncami.py
    asterisk/trunk/lib/python/asterisk/version.py
    asterisk/trunk/lib/python/asterisk/voicemail.py
    asterisk/trunk/logger.conf
    asterisk/trunk/runtests.py
    asterisk/trunk/test-config.yaml
    asterisk/trunk/tests/apps/bridge/bridge_baseline/test-config.yaml
    asterisk/trunk/tests/apps/bridge/bridge_transfer_callee/run-test
    asterisk/trunk/tests/apps/chanspy/chanspy_w_mixmonitor/run-test
    asterisk/trunk/tests/apps/confbridge/confbridge_nominal/run-test
    asterisk/trunk/tests/apps/confbridge/confbridge_recording/run-test
    asterisk/trunk/tests/apps/control_playback/nominal/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_answer/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_busy/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_congestion/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_dtmf_hangup_cancel/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_hangup/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_all_busy/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_all_cancel/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_all_congestion/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_all_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_all_unavail/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_answer_cancel/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_single_busy/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_single_congestion/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_single_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_parallel/dial_parallel_single_unavail/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_timeout/test-config.yaml
    asterisk/trunk/tests/apps/dial/dial_unavail/test-config.yaml
    asterisk/trunk/tests/apps/directed_pickup/run-test
    asterisk/trunk/tests/apps/directory/directory_attendant_exit/run-test
    asterisk/trunk/tests/apps/directory/directory_context_operator_exit/run-test
    asterisk/trunk/tests/apps/directory/directory_operator_exit/run-test
    asterisk/trunk/tests/apps/incomplete/sip_incomplete/run-test
    asterisk/trunk/tests/apps/mixmonitor/testaudio2.raw
    asterisk/trunk/tests/apps/mixmonitor_audiohook_inherit/run-test
    asterisk/trunk/tests/apps/mixmonitor_func/test-config.yaml
    asterisk/trunk/tests/apps/page/page_baseline/run-test
    asterisk/trunk/tests/apps/playback/nominal/test-config.yaml
    asterisk/trunk/tests/apps/queues/position_priority_maxlen/run-test
    asterisk/trunk/tests/apps/queues/queue_all_paused_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/queues/queue_baseline/run-test
    asterisk/trunk/tests/apps/queues/queue_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/queues/queue_one_paused_no_answer/test-config.yaml
    asterisk/trunk/tests/apps/queues/queue_penalty_outside_range/test-config.yaml
    asterisk/trunk/tests/apps/queues/queue_transfer_callee/run-test
    asterisk/trunk/tests/apps/queues/reload_queue_members/run-test
    asterisk/trunk/tests/apps/queues/set_penalty/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_extensions/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_nominal/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_callback/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_delete/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_dialout/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_envelope/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward_hangup/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_forward_with_prepend/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_new_user/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_new_user_hangup/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_nominal/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_change_password/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_busy/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_name/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_temp/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_options_record_unavail/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_reply/run-test
    asterisk/trunk/tests/apps/voicemail/check_voicemail_while_leaving_msg/run-test
    asterisk/trunk/tests/apps/voicemail/func_vmcount/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_external_notification/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test
    asterisk/trunk/tests/apps/voicemail/play_message/run-test
    asterisk/trunk/tests/asyncagi/asyncagi_break/test-config.yaml
    asterisk/trunk/tests/bridge/atxfer_nominal/test-config.yaml
    asterisk/trunk/tests/bridge/atxfer_setup/test-config.yaml
    asterisk/trunk/tests/bridge/atxfer_threeway_nominal/test-config.yaml
    asterisk/trunk/tests/bridge/automixmon/test-config.yaml
    asterisk/trunk/tests/bridge/automixmon_bridgefeatures/test-config.yaml
    asterisk/trunk/tests/bridge/automon/test-config.yaml
    asterisk/trunk/tests/bridge/automon_bridgefeatures/test-config.yaml
    asterisk/trunk/tests/bridge/blindxfer_nominal/test-config.yaml
    asterisk/trunk/tests/bridge/blindxfer_setup/test-config.yaml
    asterisk/trunk/tests/bridge/blonde_nominal/test-config.yaml
    asterisk/trunk/tests/bridge/bridge_action/bridge_action.py
    asterisk/trunk/tests/bridge/bridge_action/test-config.yaml
    asterisk/trunk/tests/bridge/connected_line_update/test-config.yaml
    asterisk/trunk/tests/bridge/dial_LS_options/test-config.yaml
    asterisk/trunk/tests/bridge/disconnect/test-config.yaml
    asterisk/trunk/tests/bridge/parkcall/test-config.yaml
    asterisk/trunk/tests/bridge/parkcall_blindxfer/test-config.yaml
    asterisk/trunk/tests/bridge/parkcall_bridgefeatures/test-config.yaml
    asterisk/trunk/tests/bridge/parkcall_timeout/comebacktoorigin_no/test-config.yaml
    asterisk/trunk/tests/bridge/parkcall_timeout/comebacktoorigin_yes/test-config.yaml
    asterisk/trunk/tests/bridge/simple_bridge/test-config.yaml
    asterisk/trunk/tests/bridge/transfer_capabilities/test-config.yaml
    asterisk/trunk/tests/bridge/transfer_capabilities_bridgefeatures/test-config.yaml
    asterisk/trunk/tests/bridge/transfer_failure/test-config.yaml
    asterisk/trunk/tests/callparking/run-test
    asterisk/trunk/tests/callparking_retrieval/run-test
    asterisk/trunk/tests/cause_answered_elsewhere/run-test
    asterisk/trunk/tests/cdr/batch_cdrs/test-config.yaml
    asterisk/trunk/tests/cdr/cdr-tests.py
    asterisk/trunk/tests/cdr/cdr_manipulation/cdr_fork_end_time/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_manipulation/console_fork_after_busy_forward/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_manipulation/console_fork_before_dial/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_manipulation/nocdr/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_originate_sip_congestion_log/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_properties/cdr_accountcode/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_properties/cdr_userfield/test-config.yaml
    asterisk/trunk/tests/cdr/cdr_unanswered_yes/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/channels/SIP/SDP_attribute_passthrough/run-test
    asterisk/trunk/tests/channels/SIP/generic_ccss/run-test
    asterisk/trunk/tests/channels/SIP/handle_response_address_incomplete/run-test
    asterisk/trunk/tests/channels/SIP/hangupcause/run-test
    asterisk/trunk/tests/channels/SIP/info_dtmf/run-test
    asterisk/trunk/tests/channels/SIP/message_send_ami/run-test
    asterisk/trunk/tests/channels/SIP/nat_supertest/run-test
    asterisk/trunk/tests/channels/SIP/noload_res_srtp/run-test
    asterisk/trunk/tests/channels/SIP/noload_res_srtp_attempt_srtp/run-test
    asterisk/trunk/tests/channels/SIP/path/test-config.yaml
    asterisk/trunk/tests/channels/SIP/pcap_demo/run-test
    asterisk/trunk/tests/channels/SIP/realtime_nosipregs/run-test
    asterisk/trunk/tests/channels/SIP/realtime_sipregs/run-test
    asterisk/trunk/tests/channels/SIP/secure_bridge_media/run-test
    asterisk/trunk/tests/channels/SIP/session_timers/basic_uac_refresh/test-config.yaml
    asterisk/trunk/tests/channels/SIP/session_timers/basic_uac_teardown/test-config.yaml
    asterisk/trunk/tests/channels/SIP/session_timers/uac_multiple_422_accept/test-config.yaml
    asterisk/trunk/tests/channels/SIP/session_timers/uac_multiple_422_originate/test-config.yaml
    asterisk/trunk/tests/channels/SIP/session_timers/uac_se_below_minse/test-config.yaml
    asterisk/trunk/tests/channels/SIP/sip2cause/run-test
    asterisk/trunk/tests/channels/SIP/sip_attended_transfer/run-test
    asterisk/trunk/tests/channels/SIP/sip_attended_transfer_tcp/run-test
    asterisk/trunk/tests/channels/SIP/sip_blind_transfer/callee_refer_only/run-test
    asterisk/trunk/tests/channels/SIP/sip_blind_transfer/callee_with_reinvite/run-test
    asterisk/trunk/tests/channels/SIP/sip_blind_transfer/caller_refer_only/run-test
    asterisk/trunk/tests/channels/SIP/sip_blind_transfer/caller_with_reinvite/run-test
    asterisk/trunk/tests/channels/SIP/sip_cause/run-test
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/multiple_state_change/run-test
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/nominal_state_change/run-test
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/non_digium_state_change/run-test
    asterisk/trunk/tests/channels/SIP/sip_custom_presence/resubscribe/run-test
    asterisk/trunk/tests/channels/SIP/sip_hold/run-test
    asterisk/trunk/tests/channels/SIP/sip_hold_direct_media/run-test
    asterisk/trunk/tests/channels/SIP/sip_one_legged_transfer/run-test
    asterisk/trunk/tests/channels/SIP/sip_register_domain_acl/run-test
    asterisk/trunk/tests/channels/SIP/sip_srtp/run-test
    asterisk/trunk/tests/channels/SIP/sip_tls_call/run-test
    asterisk/trunk/tests/channels/SIP/sip_tls_register/run-test
    asterisk/trunk/tests/channels/SIP/use_contact_from_200/run-test
    asterisk/trunk/tests/channels/iax2/acl_call/run-test
    asterisk/trunk/tests/channels/iax2/basic-call/test-config.yaml
    asterisk/trunk/tests/channels/iax2/hangupcause/run-test
    asterisk/trunk/tests/channels/local/local_app/test-config.yaml
    asterisk/trunk/tests/channels/local/local_call/test-config.yaml
    asterisk/trunk/tests/channels/local/local_holding_bridge/test-config.yaml
    asterisk/trunk/tests/channels/local/local_optimize_away/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/ami/show_endpoint/AMISendTest.py
    asterisk/trunk/tests/channels/pjsip/ami/show_endpoint/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/ami/show_endpoints/AMISendTest.py
    asterisk/trunk/tests/channels/pjsip/ami/show_endpoints/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/ami/show_registrations_inbound/AMISendTest.py
    asterisk/trunk/tests/channels/pjsip/ami/show_registrations_inbound/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/ami/show_registrations_outbound/AMISendTest.py
    asterisk/trunk/tests/channels/pjsip/ami/show_registrations_outbound/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/ami/show_subscriptions/AMISendTest.py
    asterisk/trunk/tests/channels/pjsip/ami/show_subscriptions/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/nominal/auth/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/nominal/echo/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/nominal/playback/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/off-nominal/bob_does_not_answer/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/off-nominal/bob_does_not_exist/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/off-nominal/bob_incompatible_codecs/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/outgoing/off-nominal/bob_is_busy/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/two_parties/nominal/alice_initiated/alice_hangs_up/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/basic_calls/two_parties/nominal/alice_initiated/bob_hangs_up/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/dialplan_functions/pjsip_endpoint/test-config.yaml
    asterisk/trunk/tests/channels/pjsip/hold/run-test
    asterisk/trunk/tests/channels/pjsip/message/message_send_ami/run-test
    asterisk/trunk/tests/dynamic-modules/run-test
    asterisk/trunk/tests/fastagi/channel-status/run-test
    asterisk/trunk/tests/fastagi/connect/run-test
    asterisk/trunk/tests/fastagi/control-stream-file/run-test
    asterisk/trunk/tests/fastagi/database/run-test
    asterisk/trunk/tests/fastagi/stream-file/run-test
    asterisk/trunk/tests/fax/pjsip/gateway_native_t38/run-test
    asterisk/trunk/tests/fax/pjsip/gateway_t38_g711/run-test
    asterisk/trunk/tests/fax/sip/gateway_g711_t38/run-test
    asterisk/trunk/tests/fax/sip/gateway_mix1/run-test
    asterisk/trunk/tests/fax/sip/gateway_mix2/run-test
    asterisk/trunk/tests/fax/sip/gateway_mix3/run-test
    asterisk/trunk/tests/fax/sip/gateway_mix4/run-test
    asterisk/trunk/tests/fax/sip/gateway_native_t38/run-test
    asterisk/trunk/tests/fax/sip/gateway_native_t38_ced/run-test
    asterisk/trunk/tests/fax/sip/gateway_no_t38/run-test
    asterisk/trunk/tests/fax/sip/gateway_t38_g711/run-test
    asterisk/trunk/tests/fax/sip/gateway_timeout1/run-test
    asterisk/trunk/tests/fax/sip/gateway_timeout2/run-test
    asterisk/trunk/tests/fax/sip/gateway_timeout3/run-test
    asterisk/trunk/tests/fax/sip/gateway_timeout4/run-test
    asterisk/trunk/tests/fax/sip/gateway_timeout5/run-test
    asterisk/trunk/tests/fax/sip/local_channel_t38_queryoption/run-test
    asterisk/trunk/tests/fax/sip/voxfax_g711/run-test
    asterisk/trunk/tests/feature_call_pickup/run-test
    asterisk/trunk/tests/funcs/func_global/test-config.yaml
    asterisk/trunk/tests/funcs/func_jitterbuffer/run-test
    asterisk/trunk/tests/funcs/func_presencestate/run-test
    asterisk/trunk/tests/funcs/func_srv/run-test
    asterisk/trunk/tests/hangup/handlers/run-test
    asterisk/trunk/tests/hangup/handlers_endbeforehexten/run-test
    asterisk/trunk/tests/manager/acl-login/run-test
    asterisk/trunk/tests/manager/bridge_actions/test-config.yaml
    asterisk/trunk/tests/manager/danger/dangerous/run-test
    asterisk/trunk/tests/manager/danger/safe/run-test
    asterisk/trunk/tests/manager/login/run-test
    asterisk/trunk/tests/masquerade/run-test
    asterisk/trunk/tests/pbx/call-files/run-test
    asterisk/trunk/tests/pbx/callerid_match/run-test
    asterisk/trunk/tests/pbx/dialplan/test-config.yaml
    asterisk/trunk/tests/pbx/dialplan_reload/run-test
    asterisk/trunk/tests/pbx/merge_contexts/run-test
    asterisk/trunk/tests/pbx/pbx_lua_background/run-test
    asterisk/trunk/tests/pbx/pbx_lua_goto/run-test
    asterisk/trunk/tests/predial/run-test
    asterisk/trunk/tests/regressions/M18882/run-test
    asterisk/trunk/tests/rest_api/CORS/run-test
    asterisk/trunk/tests/rest_api/authentication/run-test
    asterisk/trunk/tests/rest_api/content-type/run-test
    asterisk/trunk/tests/rest_api/request-bodies/run-test
    asterisk/trunk/tests/skeleton_test/run-test
    asterisk/trunk/tests/udptl/run-test
    asterisk/trunk/tests/udptl_v6/run-test

Modified: asterisk/trunk/lib/python/asterisk/ami.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/ami.py?view=diff&rev=4556&r1=4555&r2=4556
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ami.py (original)
+++ asterisk/trunk/lib/python/asterisk/ami.py Tue Jan 14 09:43:30 2014
@@ -1,54 +1,70 @@
-from twisted.internet import reactor, protocol
+#!/usr/bin/env python
+# vim: sw=3 et:
+"""
+Copyright (C) 2010, Digium, Inc.
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+from twisted.internet import reactor
 from starpy import manager
 import datetime
-import sys
 import logging
 import re
 import json
 
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
 
 class AMIEventInstance(object):
-    '''
-    Base class for specific instances of AMI event observers
+    """Base class for specific instances of AMI event observers
 
     This handles common elements for both headermatch and callback
     types of AMI event observers, allowing the individual types
     to focus on their specific duties.
-    '''
+    """
+
     def __init__(self, instance_config, test_object):
+        """Constructor
+
+        Keyword Arguments:
+        instance_config The YAML configuration for the object
+        test_object The main test object for the test
+        """
         self.test_object = test_object
-        self.match_conditions = instance_config['conditions']['match']
-        self.nonmatch_conditions = instance_config['conditions'].get('nomatch', {})
+        conditions = instance_config['conditions']
+        self.match_conditions = conditions['match']
+        self.nonmatch_conditions = conditions.get('nomatch', {})
         self.ids = instance_config['id'].split(',') if 'id' in instance_config else ['0']
         self.config = instance_config
         self.passed = True
         self._registered = False
         self._event_observers = []
+        self.count = {}
 
         if 'count' in instance_config:
             count = instance_config['count']
             if isinstance(count, int):
                 # Need exactly this many events
-                self.count_min = count
-                self.count_max = count
+                self.count['min'] = count
+                self.count['max'] = count
             elif count[0] == '<':
                 # Need at most this many events
-                self.count_min = 0
-                self.count_max = int(count[1:])
+                self.count['min'] = 0
+                self.count['max'] = int(count[1:])
             elif count[0] == '>':
                 # Need at least this many events
-                self.count_min = int(count[1:])
-                self.count_max = float("inf")
+                self.count['min'] = int(count[1:])
+                self.count['max'] = float("inf")
             else:
                 # Need exactly this many events
-                self.count_min = int(count)
-                self.count_max = int(count)
+                self.count['min'] = int(count)
+                self.count['max'] = int(count)
         else:
-            self.count_min = 0
-            self.count_max = float("inf")
-
-        self.event_count = 0
+            self.count['min'] = 0
+            self.count['max'] = float("inf")
+
+        self.count['event'] = 0
         if 'type' in instance_config and instance_config['type'] == 'cel':
             # If the type is 'cel' and no condition matches are defined in the
             # test's yaml then create the dict with setting the Event to 'CEL'.
@@ -60,112 +76,124 @@
                 instance_config['conditions']['match']['Event'] = 'CEL'
 
         if 'Event' not in self.match_conditions:
-            logger.error("No event specified to match on. Aborting test")
+            LOGGER.error("No event specified to match on. Aborting test")
             raise Exception
 
         test_object.register_ami_observer(self.ami_connect)
         test_object.register_stop_observer(self.__check_result)
 
     def ami_connect(self, ami):
+        """AMI connect handler"""
         self.register_handler(ami)
 
     def register_handler(self, ami):
-        ''' Register for the AMI events.
+        """Register for the AMI events.
 
         Note:
         In general, most objects won't need this method.  You would only call
         this from a derived object when you create instances of the derived
         object after AMI connect.
-        '''
+        """
         if str(ami.id) in self.ids and not self._registered:
-            logger.debug("Registering event %s" % self.match_conditions['Event'])
-            ami.registerEvent(self.match_conditions['Event'], self.__event_callback)
+            LOGGER.debug("Registering event %s" %
+                         self.match_conditions['Event'])
+            ami.registerEvent(self.match_conditions['Event'],
+                              self.__event_callback)
             self._registered = True
 
     def register_event_observer(self, observer):
-        ''' Register an observer to be called when a matched event is received '''
+        """Register an observer to be called when a matched event is received
+
+        An observer should take in two parameters:
+        ami The AMI manager object
+        event The received event
+        """
         self._event_observers.append(observer)
 
     def dispose(self, ami):
-        ''' Dispose of this object's AMI event registrations '''
+        """Dispose of this object's AMI event registrations"""
         if str(ami.id) not in self.ids:
-            logger.warning("Unable to dispose of AMIEventInstance - unknown AMI object %d" % ami.id)
+            LOGGER.warning("Unable to dispose of AMIEventInstance - " \
+                           "unknown AMI object %d" % ami.id)
             return
-        ami.deregisterEvent(self.match_conditions['Event'], self.__event_callback)
+        ami.deregisterEvent(self.match_conditions['Event'],
+                            self.__event_callback)
 
     def event_callback(self, ami, event):
-        '''
-        Virtual method overridden by specific AMI Event
-        instance types
-        '''
+        """Virtual method overridden by specific AMI Event instance types"""
         pass
 
     def __event_callback(self, ami, event):
-        '''
-        Check event conditions to see if subclasses should
-        be called into
-        '''
-
-        for k,v in self.match_conditions.items():
-            if k.lower() not in event:
-                logger.debug("Condition %s not in event, returning" % (k))
+        """Check event conditions to see if subclasses should be called into"""
+
+        for key, value in self.match_conditions.items():
+            if key.lower() not in event:
+                LOGGER.debug("Condition %s not in event, returning" % (key))
                 return
-            if not re.match(v, event.get(k.lower())):
-                logger.debug("Condition %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
+            if not re.match(value, event.get(key.lower())):
+                LOGGER.debug("Condition %s: %s does not match %s: %s in event" %
+                             (key, value, key, event.get(key.lower())))
                 return
             else:
-                logger.debug("Condition %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-
-        for k,v in self.nonmatch_conditions.items():
-            if k.lower() not in event:
-                logger.debug("Condition %s not in event, returning" % (k))
+                LOGGER.debug("Condition %s: %s matches %s: %s in event" %
+                             (key, value, key, event.get(key.lower())))
+
+        for key, value in self.nonmatch_conditions.items():
+            if key.lower() not in event:
+                LOGGER.debug("Condition %s not in event, returning" % (key))
                 return
-            if re.match(v, event.get(k.lower())):
-                logger.debug("Condition %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
+            if re.match(value, event.get(key.lower())):
+                LOGGER.debug("Condition %s: %s matches %s: %s in event" %
+                             (key, value, key, event.get(key.lower())))
                 return
             else:
-                logger.debug("Condition %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-
-        self.event_count += 1
-
-        #Conditions have matched up as expected
-        #so leave it to the individual types to determine
-        #how to proceed
+                LOGGER.debug("Condition %s: %s does not match %s: %s in event" %
+                             (key, value, key, event.get(key.lower())))
+
+        self.count['event'] += 1
+
+        # Conditions have matched up as expected so leave it to the individual
+        # types to determine how to proceed
         for observer in self._event_observers:
             observer(ami, event)
         return self.event_callback(ami, event)
 
     def check_result(self, callback_param):
-        '''Virtual method to be overridden by subclasses'''
+        """Virtual method to be overridden by subclasses"""
         pass
 
     def __check_result(self, callback_param):
-        '''
-        This will check against event counts and the like and then
-        call into overridden veresions
-        '''
-        if (self.event_count > self.count_max
-                or self.event_count < self.count_min):
-            logger.warning("Event occurred %d times, which is out of the"
-                    " allowable range" % self.event_count)
-            logger.warning("Event description: %s" % (str(self.config)))
+        """Verify results
+
+        This will check against event counts and the like and then call into
+        overridden versions via check_result
+        """
+        if (self.count['event'] > self.count['max']
+                or self.count['event'] < self.count['min']):
+            LOGGER.warning("Event occurred %d times, which is out of the"
+                           " allowable range" % self.count['event'])
+            LOGGER.warning("Event description: %s" % (str(self.config)))
             self.test_object.set_passed(False)
             return callback_param
         return self.check_result(callback_param)
 
+
 class AMIHeaderMatchInstance(AMIEventInstance):
-    '''
-    A subclass of AMIEventInstance that operates by matching headers of
+    """A subclass of AMIEventInstance that operates by matching headers of
     AMI events to expected values. If a header does not match its expected
     value, then the test will fail
-    '''
+    """
+
     def __init__(self, instance_config, test_object):
-        super(AMIHeaderMatchInstance, self).__init__(instance_config, test_object)
-        logger.debug("Initializing an AMIHeaderMatchInstance")
+        """Constructor
+
+        Keyword Arguments:
+        instance_config The YAML configuration for the object
+        test_object The main test object for the test
+        """
+        super(AMIHeaderMatchInstance, self).__init__(instance_config,
+                                                     test_object)
+        LOGGER.debug("Initializing an AMIHeaderMatchInstance")
         if 'requirements' in instance_config:
             self.match_requirements = (
                     instance_config['requirements'].get('match', {}))
@@ -176,50 +204,62 @@
             self.nonmatch_requirements = {}
 
     def event_callback(self, ami, event):
-        for k,v in self.match_requirements.items():
-            if k.lower() not in event:
-                logger.warning("Requirement %s does not exist in event %s" %
-                                (k, event['event']))
-                self.passed = False
-            elif not re.match(v, event.get(k.lower())):
-                logger.warning("Requirement %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-                self.passed = False
-            else:
-                logger.debug("Requirement %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-
-        for k,v in self.nonmatch_requirements.items():
-            if k.lower() not in event:
-                logger.warning("Requirement %s does not exist in event %s" %
-                                (k, event['event']))
-                self.passed = False
-            elif re.match(v, event.get(k.lower(), '')):
-                logger.warning("Requirement %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower(), '')))
-                self.passed = False
-            else:
-                logger.debug("Requirement %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower(), '')))
+        """Callback called when an event is received from AMI"""
+        for key, value in self.match_requirements.items():
+            if key.lower() not in event:
+                LOGGER.warning("Requirement %s does not exist in event %s" %
+                               (key, event['event']))
+                self.passed = False
+            elif not re.match(value, event.get(key.lower())):
+                LOGGER.warning("Requirement %s: %s does not match %s: %s in " \
+                               "event" % (key, value, key,
+                               event.get(key.lower(), '')))
+                self.passed = False
+            else:
+                LOGGER.debug("Requirement %s: %s matches %s: %s in event" %
+                             (key, value, key, event.get(key.lower())))
+
+        for key, value in self.nonmatch_requirements.items():
+            if key.lower() not in event:
+                LOGGER.warning("Requirement %s does not exist in event %s" %
+                                (key, event['event']))
+                self.passed = False
+            elif re.match(value, event.get(key.lower(), '')):
+                LOGGER.warning("Requirement %s: %s matches %s: %s in event" %
+                               (key, value, key, event.get(key.lower(), '')))
+                self.passed = False
+            else:
+                LOGGER.debug("Requirement %s: %s does not match %s: %s " \
+                             "in event" % (key, value, key,
+                              event.get(key.lower(), '')))
 
         return (ami, event)
 
     def check_result(self, callback_param):
+        """Deferred callback called when this object should verify pass/fail"""
         self.test_object.set_passed(self.passed)
         return callback_param
 
+
 class AMIOrderedHeaderMatchInstance(AMIEventInstance):
-    '''
-    A subclass of AMIEventInstance that operates by matching headers of
+    """A subclass of AMIEventInstance that operates by matching headers of
     AMI events to expected values. If a header does not match its expected
     value, then the test will fail. This differs from AMIHeaderMatchInstance
     in that the order of specification is used to define an expected order
     for the events to arrive in which must be matched in order for the test
     to pass.
-    '''
+    """
+
     def __init__(self, instance_config, test_object):
-        super(AMIOrderedHeaderMatchInstance, self).__init__(instance_config, test_object)
-        logger.debug("Initializing an AMIOrderedHeaderMatchInstance")
+        """Constructor
+
+        Keyword Arguments:
+        instance_config The YAML configuration for the object
+        test_object The main test object for the test
+        """
+        super(AMIOrderedHeaderMatchInstance, self).__init__(instance_config,
+                                                            test_object)
+        LOGGER.debug("Initializing an AMIOrderedHeaderMatchInstance")
         self.match_index = 0
         self.match_requirements = []
         self.nonmatch_requirements = []
@@ -230,65 +270,72 @@
                     instance.get('nomatch', {}))
 
     def event_callback(self, ami, event):
+        """Callback called when an event is received from AMI"""
         if self.match_index >= len(self.match_requirements):
-            logger.debug("Event received and not defined: %s" % event)
+            LOGGER.debug("Event received and not defined: %s" % event)
             return
 
-        for k,v in self.match_requirements[self.match_index].items():
-            if k.lower() not in event:
-                logger.warning("Requirement %s does not exist in event %s" %
-                                (k, event['event']))
-                self.passed = False
-            elif not re.match(v, event.get(k.lower())):
-                logger.warning("Requirement %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-                self.passed = False
-            else:
-                logger.debug("Requirement %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower())))
-
-        for k,v in self.nonmatch_requirements[self.match_index].items():
-            if k.lower() not in event:
-                logger.warning("Requirement %s does not exist in event %s" %
-                                (k, event['event']))
-                self.passed = False
-            elif re.match(v, event.get(k.lower(), '')):
-                logger.warning("Requirement %s: %s matches %s: %s in event" %
-                        (k, v, k, event.get(k.lower(), '')))
-                self.passed = False
-            else:
-                logger.debug("Requirement %s: %s does not match %s: %s in event" %
-                        (k, v, k, event.get(k.lower(), '')))
+        for key, value in self.match_requirements[self.match_index].items():
+            if key.lower() not in event:
+                LOGGER.warning("Requirement %s does not exist in event %s" %
+                                (key, event['event']))
+                self.passed = False
+            elif not re.match(value, event.get(key.lower())):

[... 24056 lines stripped ...]



More information about the asterisk-commits mailing list