From adcc793a268ddd909b23a6582d29c2dc243d9116 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Fri, 30 Jan 2015 19:16:13 +0800 Subject: [PATCH] testenv: typo and style fix. * testenv/server/http/http_server.py(BaseTest): Add docstring; use raw string for regex. * testenv/server/http/http_server.py(_Handler): Typo fix. * testenv/conf/server_files.py(ServerFiles): Code style change for readability plus another typo fix. --- testenv/conf/server_files.py | 8 ++++---- testenv/server/http/http_server.py | 4 ++-- testenv/test/base_test.py | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/testenv/conf/server_files.py b/testenv/conf/server_files.py index 1e9d3466..2f9559fe 100644 --- a/testenv/conf/server_files.py +++ b/testenv/conf/server_files.py @@ -3,7 +3,7 @@ from conf import hook """ Pre-Test Hook: ServerFiles This hook is used to define a set of files on the server's virtual filesystem. server_files is expected to be dictionary that maps filenames to their -contents. In the future, this can be used to add additional metadat to the +contents. In the future, this can be used to add additional metadata to the files using the WgetFile class too. This hook also does some additional processing on the contents of the file. Any @@ -19,8 +19,8 @@ class ServerFiles: def __call__(self, test_obj): for server, files in zip(test_obj.servers, self.server_files): - rules = {f.name: test_obj.get_server_rules(f) + files_content = {f.name: test_obj._replace_substring(f.content) for f in files} - files = {f.name: test_obj._replace_substring(f.content) + files_rules = {f.name: test_obj.get_server_rules(f) for f in files} - server.server_conf(files, rules) + server.server_conf(files_content, files_rules) diff --git a/testenv/server/http/http_server.py b/testenv/server/http/http_server.py index 9128b3eb..9630efad 100644 --- a/testenv/server/http/http_server.py +++ b/testenv/server/http/http_server.py @@ -368,7 +368,7 @@ class _Handler (BaseHTTPRequestHandler): assert hasattr (self, rule_name) getattr (self, rule_name) (self.rules [rule_name]) except AssertionError as ae: - msg = "Method " + rule_name + " not defined" + msg = "Rule " + rule_name + " not defined" self.send_error (500, msg) return (None, None) except ServerError as se: @@ -399,7 +399,7 @@ class _Handler (BaseHTTPRequestHandler): content_length)) content_length -= self.range_begin cont_type = self.guess_type (path) - self.send_header ("Content-type", cont_type) + self.send_header ("Content-Type", cont_type) self.send_header ("Content-Length", content_length) self.finish_headers () return (content, self.range_begin) diff --git a/testenv/test/base_test.py b/testenv/test/base_test.py index 0d98078a..34f0b144 100644 --- a/testenv/test/base_test.py +++ b/testenv/test/base_test.py @@ -175,7 +175,10 @@ class BaseTest: self.hook_call(self.post_configs, 'Post Test Function') def _replace_substring (self, string): - pattern = re.compile ('\{\{\w+\}\}') + """ + Replace first occurrence of "{{name}}" in @string with "getattr(self, name)". + """ + pattern = re.compile (r'\{\{\w+\}\}') match_obj = pattern.search (string) if match_obj is not None: rep = match_obj.group()