mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
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.
This commit is contained in:
parent
d94d9cd98b
commit
adcc793a26
@ -3,7 +3,7 @@ from conf import hook
|
|||||||
""" Pre-Test Hook: ServerFiles
|
""" Pre-Test Hook: ServerFiles
|
||||||
This hook is used to define a set of files on the server's virtual filesystem.
|
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
|
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.
|
files using the WgetFile class too.
|
||||||
|
|
||||||
This hook also does some additional processing on the contents of the file. Any
|
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):
|
def __call__(self, test_obj):
|
||||||
for server, files in zip(test_obj.servers, self.server_files):
|
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}
|
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}
|
for f in files}
|
||||||
server.server_conf(files, rules)
|
server.server_conf(files_content, files_rules)
|
||||||
|
@ -368,7 +368,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
assert hasattr (self, rule_name)
|
assert hasattr (self, rule_name)
|
||||||
getattr (self, rule_name) (self.rules [rule_name])
|
getattr (self, rule_name) (self.rules [rule_name])
|
||||||
except AssertionError as ae:
|
except AssertionError as ae:
|
||||||
msg = "Method " + rule_name + " not defined"
|
msg = "Rule " + rule_name + " not defined"
|
||||||
self.send_error (500, msg)
|
self.send_error (500, msg)
|
||||||
return (None, None)
|
return (None, None)
|
||||||
except ServerError as se:
|
except ServerError as se:
|
||||||
@ -399,7 +399,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
content_length))
|
content_length))
|
||||||
content_length -= self.range_begin
|
content_length -= self.range_begin
|
||||||
cont_type = self.guess_type (path)
|
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.send_header ("Content-Length", content_length)
|
||||||
self.finish_headers ()
|
self.finish_headers ()
|
||||||
return (content, self.range_begin)
|
return (content, self.range_begin)
|
||||||
|
@ -175,7 +175,10 @@ class BaseTest:
|
|||||||
self.hook_call(self.post_configs, 'Post Test Function')
|
self.hook_call(self.post_configs, 'Post Test Function')
|
||||||
|
|
||||||
def _replace_substring (self, string):
|
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)
|
match_obj = pattern.search (string)
|
||||||
if match_obj is not None:
|
if match_obj is not None:
|
||||||
rep = match_obj.group()
|
rep = match_obj.group()
|
||||||
|
Loading…
Reference in New Issue
Block a user