forked from LBRYCommunity/lbry-sdk
Add test
This commit is contained in:
parent
63447d1ec3
commit
19e8b6e11f
2 changed files with 31 additions and 3 deletions
|
@ -221,7 +221,7 @@ def ensure_directory_exists(path: str):
|
|||
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def run_daemon(args: list, conf: Config):
|
||||
def setup_logging(args: argparse.Namespace, conf: Config, loop: asyncio.AbstractEventLoop):
|
||||
default_formatter = logging.Formatter("%(asctime)s %(levelname)-8s %(name)s:%(lineno)d: %(message)s")
|
||||
file_handler = logging.handlers.RotatingFileHandler(
|
||||
conf.log_file_path, maxBytes=2097152, backupCount=5
|
||||
|
@ -240,8 +240,6 @@ def run_daemon(args: list, conf: Config):
|
|||
logging.getLogger('aioupnp').setLevel(logging.WARNING)
|
||||
logging.getLogger('aiohttp').setLevel(logging.CRITICAL)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
log.setLevel(logging.INFO)
|
||||
if args.verbose is not None:
|
||||
loop.set_debug(True)
|
||||
|
@ -256,6 +254,10 @@ def run_daemon(args: list, conf: Config):
|
|||
loggly_handler.setLevel(logging.ERROR)
|
||||
log.addHandler(loggly_handler)
|
||||
|
||||
|
||||
def run_daemon(args: argparse.Namespace, conf: Config):
|
||||
loop = asyncio.get_event_loop()
|
||||
setup_logging(args, conf, loop)
|
||||
daemon = Daemon(conf)
|
||||
|
||||
def __exit():
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import contextlib
|
||||
import asyncio
|
||||
import logging
|
||||
from io import StringIO
|
||||
from torba.testcase import AsyncioTestCase
|
||||
|
||||
|
@ -37,3 +39,27 @@ class CLIIntegrationTest(AsyncioTestCase):
|
|||
cli.main(["--api", "localhost:5299", "status"])
|
||||
actual_output = actual_output.getvalue()
|
||||
self.assertIn("connection_status", actual_output)
|
||||
|
||||
def test_setup_logging(self):
|
||||
def setup(argv):
|
||||
parser = cli.get_argument_parser()
|
||||
args, command_args = parser.parse_known_args(argv)
|
||||
loop = asyncio.get_event_loop()
|
||||
conf = Config.create_from_arguments(args)
|
||||
cli.setup_logging(args, conf, loop)
|
||||
|
||||
setup(["start"])
|
||||
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.INFO))
|
||||
self.assertFalse(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
|
||||
|
||||
setup(["start", "--verbose"])
|
||||
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
|
||||
self.assertTrue(logging.getLogger("lbry").isEnabledFor(logging.INFO))
|
||||
self.assertFalse(logging.getLogger("torba").isEnabledFor(logging.DEBUG))
|
||||
|
||||
setup(["start", "--verbose", "lbry.extras", "lbry.wallet", "torba.client"])
|
||||
self.assertTrue(logging.getLogger("lbry.extras").isEnabledFor(logging.DEBUG))
|
||||
self.assertTrue(logging.getLogger("lbry.wallet").isEnabledFor(logging.DEBUG))
|
||||
self.assertTrue(logging.getLogger("torba.client").isEnabledFor(logging.DEBUG))
|
||||
self.assertFalse(logging.getLogger("lbry").isEnabledFor(logging.DEBUG))
|
||||
self.assertFalse(logging.getLogger("torba").isEnabledFor(logging.DEBUG))
|
||||
|
|
Loading…
Reference in a new issue