From 7ee5e98662bb5e0c8232864528db1d202c00a892 Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Sun, 15 Dec 2013 17:56:54 +0530 Subject: [PATCH 1/6] Split large function to improve readability and extensibility --- testenv/ChangeLog | 14 ++++++++++++++ testenv/WgetTest.py | 12 ++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/testenv/ChangeLog b/testenv/ChangeLog index 7aa1e81..879685a 100644 --- a/testenv/ChangeLog +++ b/testenv/ChangeLog @@ -1,3 +1,17 @@ +2013-12-15 Darshit Shah + + * WgetTest.py (HTTPTest.HTTP_setup): Rename to Server_setup so it can be + easily reused for other non-HTTP servers. + (HTTPTest.__init__): Call Server_setup instead of HTTP_setup + (HTTPTest.Server_setup): Split into three more functions, that handle + pre-hooks, test execution and post-hooks respectively. + (HTTPTest.pre_hook_call): Set up and execute the pre-test hooks. Code split + from HTTPTest.Server_setup + (HTTPTest.call_test): Execute wget and log exit code. Code split from + HTTPTest.Server_setup + (HTTPTest.post_hook_call): Set up and execute post-test hooks. Code split + from HTTPTest.Server_setup + 2013-12-04 Darshit Shah * Makefile.am [RACE_CHECKING_IS_ENABLED]: Define `RACE_FAIL' and diff --git a/testenv/WgetTest.py b/testenv/WgetTest.py index 9e5d2fe..a856cd8 100644 --- a/testenv/WgetTest.py +++ b/testenv/WgetTest.py @@ -219,7 +219,7 @@ class HTTPTest (CommonMethods): servers=1 ): try: - self.HTTP_setup (name, pre_hook, test_params, post_hook, servers) + self.Server_setup (name, pre_hook, test_params, post_hook, servers) except TestFailed as tf: printer ("RED", "Error: " + tf.error) self.tests_passed = False @@ -232,7 +232,8 @@ class HTTPTest (CommonMethods): printer ("GREEN", "Test Passed") finally: self._exit_test () - def HTTP_setup (self, name, pre_hook, test_params, post_hook, servers): + + def Server_setup (self, name, pre_hook, test_params, post_hook, servers): self.name = name self.servers = servers printer ("BLUE", "Running Test " + self.name) @@ -247,6 +248,11 @@ class HTTPTest (CommonMethods): #self.server = self.init_HTTP_Server () #self.domain = self.get_domain_addr (self.server.server_address) + self.pre_hook_call (pre_hook) + self.call_test (test_params) + self.post_hook_call (post_hook) + + def pre_hook_call (self, pre_hook): for pre_hook_func in pre_hook: try: assert hasattr (self, pre_hook_func) @@ -255,6 +261,7 @@ class HTTPTest (CommonMethods): raise TestFailed ("Pre Test Function " + pre_hook_func + " not defined.") getattr (self, pre_hook_func) (pre_hook[pre_hook_func]) + def call_test (self, test_params): for test_func in test_params: try: assert hasattr (self, test_func) @@ -266,6 +273,7 @@ class HTTPTest (CommonMethods): self.act_retcode = self.exec_wget (self.options, self.urls, self.domain_list) self.stop_HTTP_Server () + def post_hook_call (self, post_hook): for post_hook_func in post_hook: try: assert hasattr (self, post_hook_func) -- 1.8.5.2