mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1048547 - Improve mozlog.structured argument handling, r=chmanchester
This commit is contained in:
parent
fc606f23b4
commit
b8caeb4153
@ -53,20 +53,27 @@ class log_action(object):
|
||||
values = {}
|
||||
values.update(kwargs)
|
||||
|
||||
j = -1
|
||||
for i, arg in enumerate(args):
|
||||
j += 1
|
||||
# Skip over non-defaulted args supplied as keyword arguments
|
||||
while self.args_no_default[j] in values:
|
||||
j += 1
|
||||
if j == len(self.args_no_default):
|
||||
raise TypeError("Too many arguments")
|
||||
values[self.args_no_default[j]] = arg
|
||||
positional_no_default = [item for item in self.args_no_default if item not in values]
|
||||
|
||||
for k in range(j+1, len(self.args_no_default)):
|
||||
if self.args_no_default[k] not in values:
|
||||
raise TypeError("Missing required argument %s\n%r\n%r\n%r" %
|
||||
(self.args_no_default[k], args, kwargs, values))
|
||||
num_no_default = len(positional_no_default)
|
||||
|
||||
if len(args) < num_no_default:
|
||||
raise TypeError("Too few arguments")
|
||||
|
||||
if len(args) > num_no_default + len(self.args_with_default):
|
||||
raise TypeError("Too many arguments")
|
||||
|
||||
for i, name in enumerate(positional_no_default):
|
||||
values[name] = args[i]
|
||||
|
||||
positional_with_default = [self.args_with_default[i]
|
||||
for i in range(len(args) - num_no_default)]
|
||||
|
||||
|
||||
for i, name in enumerate(positional_with_default):
|
||||
if name in values:
|
||||
raise TypeError("Argument %s specified twice" % name)
|
||||
values[name] = args[i + num_no_default]
|
||||
|
||||
# Fill in missing arguments
|
||||
for name in self.args_with_default:
|
||||
@ -74,9 +81,12 @@ class log_action(object):
|
||||
values[name] = self.args[name].default
|
||||
|
||||
for key, value in values.iteritems():
|
||||
out_value = self.args[key](value)
|
||||
if out_value is not missing:
|
||||
data[key] = out_value
|
||||
if key in self.args:
|
||||
out_value = self.args[key](value)
|
||||
if out_value is not missing:
|
||||
data[key] = out_value
|
||||
else:
|
||||
raise TypeError("Unrecognised argument %s" % key)
|
||||
|
||||
return data
|
||||
|
||||
|
@ -363,6 +363,35 @@ class TestTypeconversions(BaseStructuredTest):
|
||||
self.assertEquals(data[-1], "☺\n")
|
||||
self.logger.suite_end()
|
||||
|
||||
def test_arguments(self):
|
||||
self.logger.info(message="test")
|
||||
self.assert_log_equals({"action": "log",
|
||||
"message": "test",
|
||||
"level": "INFO"})
|
||||
|
||||
self.logger.suite_start([], {})
|
||||
self.assert_log_equals({"action": "suite_start",
|
||||
"tests": [],
|
||||
"run_info": {}})
|
||||
self.logger.test_start(test="test1")
|
||||
self.logger.test_status("subtest1", "FAIL", test="test1", status="PASS")
|
||||
self.assert_log_equals({"action": "test_status",
|
||||
"test": "test1",
|
||||
"subtest": "subtest1",
|
||||
"status": "PASS",
|
||||
"expected": "FAIL"})
|
||||
self.logger.process_output(123, "data", "test")
|
||||
self.assert_log_equals({"action": "process_output",
|
||||
"process": "123",
|
||||
"command": "test",
|
||||
"data": "data"})
|
||||
self.assertRaises(TypeError, self.logger.test_status, subtest="subtest2",
|
||||
status="FAIL", expected="PASS")
|
||||
self.assertRaises(TypeError, self.logger.test_status, "test1", "subtest1",
|
||||
"PASS", "FAIL", "message", "stack", {}, "unexpected")
|
||||
self.assertRaises(TypeError, self.logger.test_status, "test1", test="test2")
|
||||
self.logger.suite_end()
|
||||
|
||||
class TestCommandline(unittest.TestCase):
|
||||
def test_setup_logging(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
|
Loading…
Reference in New Issue
Block a user