зеркало из https://github.com/mozilla/gecko-dev.git
bug 985612 - fix mozlog.structured.commandline.setup_logging to handle argparse Namespace objects. r=jgraham
This commit is contained in:
Родитель
c4e9fee5e4
Коммит
b5c05a42f1
|
@ -63,6 +63,8 @@ def setup_logging(suite, args, defaults):
|
|||
prefix = "log_"
|
||||
found = False
|
||||
found_stdout_logger = False
|
||||
if not hasattr(args, 'iteritems'):
|
||||
args = vars(args)
|
||||
for name, values in args.iteritems():
|
||||
if name.startswith(prefix) and values is not None:
|
||||
for value in values:
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
import argparse
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
import StringIO
|
||||
import json
|
||||
|
||||
from mozlog.structured import structuredlog, reader
|
||||
from mozlog.structured import (
|
||||
commandline,
|
||||
reader,
|
||||
structuredlog,
|
||||
)
|
||||
|
||||
|
||||
class TestHandler(object):
|
||||
|
@ -182,6 +187,14 @@ class TestStructuredLog(BaseStructuredTest):
|
|||
"level": "INFO",
|
||||
"message": "line 4"})
|
||||
|
||||
class TestCommandline(unittest.TestCase):
|
||||
def test_setup_logging(self):
|
||||
parser = argparse.ArgumentParser()
|
||||
commandline.add_logging_group(parser)
|
||||
args = parser.parse_args(["--log-raw=/tmp/foo"])
|
||||
logger = commandline.setup_logging("test", args, {})
|
||||
self.assertEqual(len(logger.handlers), 1)
|
||||
|
||||
class TestReader(unittest.TestCase):
|
||||
def to_file_like(self, obj):
|
||||
data_str = "\n".join(json.dumps(item) for item in obj)
|
||||
|
|
Загрузка…
Ссылка в новой задаче