l

Nc               @   s   d  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 d d l	 m
 Z
 d g Z d   Z Gd   d e j  Z Gd	   d
 e j  Z Gd   d e  Z Gd   d e  Z Gd   d e  Z d S(   u  
This module scans all ``*.rst`` files below ``docs/`` for example code. Example
code is discoved by checking for lines containing the ``.. literalinclude:: ``
directives.

An example consists of two consecutive literalinclude directives. The first
must include a ``*.py`` file and the second a ``*.out`` file. The ``*.py`` file
consists of the example code which is executed in a separate process. The
output of this process is compared to the contents of the ``*.out`` file.

i    N(   u   TerminalRepr(   u
   _diff_textu   SimRTManual.rstc             C   sJ   |  j  d k r d Sx' t D] } t |   j |  r d Sq Wt |  |  S(   uR   Checks if the file is a rst file and creates an :class:`ExampleFile`
    instance.u   .rstN(   u   extu	   blacklistu   stru   endswithu   ExampleFile(   u   pathu   parentu   item(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   pytest_collect_file   s    c             B   s   |  Ee  Z d  Z d   Z d S(   u.   Collects all examples contained in a rst-file.c             c   s  g  } |  j  j   } } xs t |  D]e \ } } d | k rC q% n  | j d  d j   } t j j |  j  j |  } | j	 | | f  q% WWd  QXx t
 t |  d  D]h } | | \ } }	 | | d \ }
 } |	 j d  s q n  | j d  s q n  t |
 |	 | |   Vq Wd  S(   Nu   literalincludeu   ::i   u   .pyu   .outi(   u   fspathu   openu	   enumerateu   splitu   stripu   osu   pathu   joinu   dirnameu   appendu   rangeu   lenu   endswithu   ExampleItem(   u   selfu   literalincludesu   datau   linenou   lineu   filenameu   filepathu   idxu   example_linenou   exampleu   output_linenou   output(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   collect)   s     N(   u   __name__u
   __module__u   __doc__u   collect(   u
   __locals__(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   ExampleFile&   s   
u   ExampleFilec             B   s8   |  Ee  Z d  Z d   Z d   Z d   Z d   Z d S(   u(   Executes an example found in a rst-file.c             C   sw   t  j j |  | |  | |  _ | |  _ | |  _ t j j |  j	 j
 |  j  |  _ t j j |  j	 j
 |  j  |  _ d  S(   N(   u   pytestu   Itemu   __init__u   linenou   exampleu   outputu   osu   pathu   joinu   fspathu   dirnameu   examplefileu
   outputfile(   u   selfu   linenou   exampleu   outputu   parent(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   __init__B   s    			!c             C   s  t  |  j   } | j   } Wd  QXd | k rk t j d  t t j d   d k rk t j d  qk n  t  |  j	   } | j   } Wd  QXt
 t d  s t j d  n  t j d |  j g d t j } t | t  r | j d	  } n  | | k rt | |   n  d  S(
   Nu   expovariatei    g?u   Old exovariate implementation.u   check_outputu(   subprocess has no check_output() method.u   pythonu   stderru   utf8(   u   openu   examplefileu   readu   randomu   seedu   intu   expovariateu   pytestu   skipu
   outputfileu   hasattru
   subprocessu   check_outputu   STDOUTu
   isinstanceu   bytesu   decodeu
   ValueError(   u   selfu   fu   srcu   expectedu   output(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   runtestJ   s     c             C   s   | j  t f  rR | j j \ } } t | |  } t |  j j |  j |  j	 |  S| j  t
 f  r | j j t j k r t j j |  |  St |  j j |  j |  j |  S| j  t j f  r t |  j j |  j |  j |  St j j |  |  Sd  S(   N(   u   errisinstanceu
   ValueErroru   valueu   argsu
   _diff_textu   ReprFailExampleu   fspathu   basenameu   linenou
   outputfileu   IOErroru   errnou   ENOENTu   pytestu   Itemu   repr_failureu   ReprFileNotFoundExampleu   examplefileu
   subprocessu   CalledProcessErroru   ReprErrorExample(   u   selfu   exc_infou   expectedu   outputu   message(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   repr_failuree   s    c             C   s#   |  j  d d t j j |  j  f S(   u%   Returns a description of the example.u   [example %s]N(   u   fspathu   Noneu   osu   pathu   relpathu   examplefile(   u   self(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu
   reportinfo   s    N(   u   __name__u
   __module__u   __doc__u   __init__u   runtestu   repr_failureu
   reportinfo(   u
   __locals__(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   ExampleItem?   s
   
			u   ExampleItemc             B   s\   |  Ee  Z d  Z i e d d
  d 6e d d
  d 6e d d
  d 6Z d   Z d   Z d	 S(   uC   Reports output mismatches in a nice and informative representation.u   greenu   +u   redu   -u   boldu   ?c             C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   u   filenameu   linenou
   outputfileu   message(   u   selfu   filenameu   linenou
   outputfileu   message(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   __init__   s    			c             C   sp   x: |  j  D]/ } t j j | d i   } | j | |  q
 W| j d |  j |  j t j j	 |  j
  f  d  S(   Ni    u    %s:%d (in %s): Unexpected output(   u   messageu   ReprFailExampleu   Markupu   getu   lineu   filenameu   linenou   osu   pathu   relpathu
   outputfile(   u   selfu   twu   lineu   markup(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu
   toterminal   s
    NT(   u   __name__u
   __module__u   __doc__u   dictu   Trueu   Markupu   __init__u
   toterminal(   u
   __locals__(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   ReprFailExample   s   
	u   ReprFailExamplec             B   s&   |  Ee  Z d  Z d   Z d   Z d S(   u0   Reports failures in the execution of an example.c             C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   u   filenameu   linenou   examplefileu   exc_info(   u   selfu   filenameu   linenou   examplefileu   exc_info(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   __init__   s    			c             C   s   | j  d d d | j d  | j  |  j j j d d d d | j  d |  j |  j t j	 j
 |  j  |  j j j f  d  S(   Nu"   Execution failed! Captured output:u   boldu   -u   redu'   %s:%d (%s) Example failed (exitcode=%d)T(   u   lineu   Trueu   sepu   exc_infou   valueu   outputu   filenameu   linenou   osu   pathu   relpathu   examplefileu
   returncode(   u   selfu   tw(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu
   toterminal   s    "N(   u   __name__u
   __module__u   __doc__u   __init__u
   toterminal(   u
   __locals__(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   ReprErrorExample   s   
	u   ReprErrorExamplec             B   s&   |  Ee  Z d  Z d   Z d   Z d S(   uB   Reports concise error information in the case of a file not found.c             C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   u   filenameu   linenou   examplefileu   exc_info(   u   selfu   filenameu   linenou   examplefileu   exc_info(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   __init__   s    			c             C   sR   | j  |  j j d d d d | j  d |  j |  j t j j |  j	  f  d  S(   Nu   redu   boldu   %s:%d (%s) Example failedT(
   u   lineu   exc_infou   valueu   Trueu   filenameu   linenou   osu   pathu   relpathu   examplefile(   u   selfu   tw(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu
   toterminal   s    N(   u   __name__u
   __module__u   __doc__u   __init__u
   toterminal(   u
   __locals__(    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   ReprFileNotFoundExample   s   
	u   ReprFileNotFoundExample(   u   __doc__u   os.pathu   osu
   subprocessu   errnou   randomu   pytestu   py._code.codeu   TerminalRepru   _pytest.assertion.utilu
   _diff_textu	   blacklistu   pytest_collect_fileu   Fileu   ExampleFileu   Itemu   ExampleItemu   ReprFailExampleu   ReprErrorExampleu   ReprFileNotFoundExample(    (    (    u)   /Users/stefan/Code/simpy/docs/conftest.pyu   <module>   s   		F