ó
ßüÚ\c           @` sÙ   d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 m Z m Z m Z m Z d  d l m Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d S(   i    (   t   print_functiont   divisiont   absolute_importN(   t   captured_handlert   captured_loggert
   new_configt   new_config_file(   t   initialize_loggingc          C` sÞ   t  j ƒ  }  |  j j } t ƒ  t d ƒ d „  } g  } | j | d |  ƒ ƒ xc t | j ƒ  ƒ D]O \ } } t | t  j	 ƒ s… qa n  | j
 | k sš t ‚ | j | | | ƒ ƒ qa Wx | D] } t d | ƒ q» Wt ƒ  d  S(   Ns7   == Loggers (name, level, effective level, propagate) ==c         S` s.   |  t  j | j ƒ t  j | j ƒ  ƒ | j f S(   N(   t   loggingt   getLevelNamet   levelt   getEffectiveLevelt	   propagate(   t   namet   logger(    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   logger_info   s    s   <root>s   %-40s %-8s %-8s %-5s(   R   t	   getLoggert   managert
   loggerDictt   printt   appendt   sortedt   itemst
   isinstancet   LoggerR   t   AssertionError(   t   roott   loggersR   t   infosR   R   t   info(    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   dump_logger_list   s    
	c          C` s  t  j d ƒ }  t |  j ƒ d k s* t ‚ t |  j d t  j ƒ sI t ‚ t  j d ƒ } | j } | j d ƒ x |  j D] } | j d ƒ qx Wzbt  j d ƒ } t  j d ƒ } t  j d	 ƒ } t	 |  j d ƒ È } t
 | d
 t  j ƒª } t  j | ƒ }	 d }
 |	 j t  j |
 ƒ ƒ | j |	 ƒ t | _ t ƒ  |  j d ƒ |  j d ƒ | j d ƒ | j d ƒ | j d ƒ | j d ƒ | j d ƒ Wd QXWd QX| j ƒ  j ƒ  } | j ƒ  j ƒ  } | d d g k sØt ‚ | d d g k sðt ‚ Wd | j | ƒ Xd S(   s-   
    Test default logging configuration.
    t   distributedi   i    t    t   WARNt   INFOs   distributed.foo.bart   foos   foo.barR
   s)   [%(levelname)s in %(name)s] - %(message)ss   1: debugs   2: infos   3: infos   4: infos   5: errors   6: infos   7: errorNs   distributed - INFO - 2: infos$   distributed.foo.bar - INFO - 3: infos   [ERROR in foo.bar] - 5: error(   R   R   t   lent   handlersR   R   t   StreamHandlerR
   t   setLevelR   R   t   ERRORt   setFormattert	   Formattert
   addHandlert   FalseR   R   t   debugR   t   errort   getvaluet
   splitlines(   t   dR   t   old_root_levelt   handlert   dfbt   ft   fbt   distributed_logt   foreign_logt   ht   fmt(    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_default2   sD    		c           C` s   t  i  ƒ  t ƒ  Wd  QXd  S(   N(   R   R;   (    (    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_empty_simplel   s    c          C` sQ   i i d d 6d d 6d 6}  t  |  ƒ $ d } t j t j d | g ƒ Wd QXd S(	   s:   
    Test simple ("old-style") logging configuration.
    R   s   distributed.fooR.   s   distributed.foo.barR   se  if 1:
            import logging
            import dask

            from distributed.utils_test import captured_handler

            d = logging.getLogger('distributed')
            assert len(d.handlers) == 1
            assert isinstance(d.handlers[0], logging.StreamHandler)
            df = logging.getLogger('distributed.foo')
            dfb = logging.getLogger('distributed.foo.bar')

            with captured_handler(d.handlers[0]) as distributed_log:
                df.info("1: info")
                dfb.warning("2: warning")
                dfb.error("3: error")

            distributed_log = distributed_log.getvalue().splitlines()

            assert distributed_log == [
                "distributed.foo - INFO - 1: info",
                "distributed.foo.bar - ERROR - 3: error",
                ], (dask.config.config, distributed_log)
            s   -cN(   R   t
   subprocesst
   check_callt   syst
   executable(   t   ct   code(    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_simpleq   s    c          C` s½   i i d d 6i i d d 6d 6d 6i i d d 6d	 d
 6d d 6d 6d 6i i d d 6d 6i d d 6d 6d 6i d d 6d g d 6d 6d 6}  t  |  ƒ $ d } t j t j d | g ƒ Wd QXd S(   s<   
    Test extended ("new-style") logging configuration.
    t   1t   versions$   %(levelname)s: %(name)s: %(message)st   formatt   simplet
   formatterss   logging.StreamHandlert   classs   ext://sys.stderrt   streamt	   formattert   consoleR%   R"   R
   s   distributed.fooR(   s   distributed.foo.barR   t   WARNINGR   R   s^  if 1:
            import logging

            from distributed.utils_test import captured_handler

            root = logging.getLogger()
            d = logging.getLogger('distributed')
            df = logging.getLogger('distributed.foo')
            dfb = logging.getLogger('distributed.foo.bar')

            with captured_handler(root.handlers[0]) as root_log:
                df.info("1: info")
                dfb.warning("2: warning")
                dfb.error("3: error")
                d.info("4: info")
                d.warning("5: warning")

            root_log = root_log.getvalue().splitlines()
            print(root_log)

            assert root_log == [
                "INFO: distributed.foo: 1: info",
                "ERROR: distributed.foo.bar: 3: error",
                "WARNING: distributed: 5: warning",
                ]
            s   -cN(   R   R=   R>   R?   R@   (   RA   RB   (    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_extended”   s&    c          C` s?   i i d d 6d 6d d 6}  t  j t ƒ  t |  ƒ Wd QXd S(   sV   
    Ensure that 'logging-file-config' and 'logging' have to be mutual exclusive.
    t   warningt   daskR   s   /path/to/configs   logging-file-configN(   t   pytestt   raisest   RuntimeErrorR   (   t   config(    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_mutual_exclusiveÒ   s    c       	   C` sŠ   d }  t  j d d d t ƒ  } | j |  ƒ Wd QXi | j d 6} t | ƒ $ d } t j t j	 d | g ƒ Wd QXt
 j | j ƒ d S(	   s:   
    Test `logging-file-config` logging configuration
    s‘  
[handlers]
keys=console

[formatters]
keys=simple

[loggers]
keys=root, foo, foo_bar

[handler_console]
class=StreamHandler
level=INFO
formatter=simple
args=(sys.stdout,)

[formatter_simple]
format=%(levelname)s: %(name)s: %(message)s

[logger_root]
level=WARNING
handlers=console

[logger_foo]
level=INFO
handlers=console
qualname=foo

[logger_foo_bar]
level=ERROR
handlers=console
qualname=foo.bar
t   modet   wt   deleteNs   logging-file-configs)  if 1:
            import logging
            from distributed import config
            foo = logging.getLogger('foo')
            bar = logging.getLogger('foo.bar')
            assert logging.INFO == foo.getEffectiveLevel()
            assert logging.ERROR == bar.getEffectiveLevel()
            s   -c(   t   tempfilet   NamedTemporaryFileR,   t   writeR   R   R=   R>   R?   R@   t   ost   remove(   t   logging_config_contentst   logging_configt   dask_configRB   (    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   test_logging_file_configÛ   s    $(   t
   __future__R    R   R   R   R=   R?   RY   R\   RQ   t   distributed.utils_testR   R   R   R   t   distributed.configR   R   R;   R<   RC   RN   RU   Ra   (    (    (    s<   lib/python2.7/site-packages/distributed/tests/test_config.pyt   <module>   s   "		:		#	>		