ó
¬>ìXâ5  c           @   s>  d  d l  Z d  d l j j Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l m
 Z
 d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d  „  Z& d! „  Z' d" „  Z( d# „  Z) d$ „  Z* d% „  Z+ d& „  Z, d' „  Z- d( „  Z. d) „  Z/ d* „  Z0 d+ „  Z1 d, „  Z2 d- „  Z3 d. „  Z4 d/ „  Z5 d0 „  Z6 e j7 j8 Z8 d1 „  Z9 d2 „  Z: d3 „  Z; d4 „  Z< d5 „  Z= d6 „  Z> d7 „  Z? d8 „  Z@ d S(9   iÿÿÿÿN(   t
   rules_yacc(   t   parse_rules(   t	   scan_itemc         C   s  |  | ƒ } t  | ƒ g  f } | | k } | st j d | f d | | f ƒ i t j | ƒ d 6d t j ƒ  k s‚ t j | ƒ r‘ t j | ƒ n d d 6d t j ƒ  k s¹ t j |  ƒ rÈ t j |  ƒ n d d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d  } } } d  S(   Ns   !=s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} != %(py6)st   py3t   datat   py1t	   matchfunct   py0t   py6t    s   assert %(py8)st   py8(   s   !=(   s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} != %(py6)ss   assert %(py8)s(
   t   lent
   @pytest_art   _call_reprcomparet	   _safereprt   @py_builtinst   localst   _should_repr_global_namet   AssertionErrort   _format_explanationt   None(   R   R   t   @py_assert2t   @py_assert5t   @py_assert4t   @py_format7t   @py_format9(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt	   not_match   s        ³   c         C   s  |  | ƒ } t  | ƒ g  f } | | k } | st j d | f d | | f ƒ i t j | ƒ d 6d t j ƒ  k s‚ t j | ƒ r‘ t j | ƒ n d d 6d t j ƒ  k s¹ t j |  ƒ rÈ t j |  ƒ n d d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d  } } } d  S(   Ns   ==s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sR   R   R   R   R   R   R	   s   assert %(py8)sR
   (   s   ==(   s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)ss   assert %(py8)s(
   R   R   R   R   R   R   R   R   R   R   (   R   R   R   R   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt
   does_match   s        ³   c          C   se  i d t  j d d ƒ 6}  t  j } d } d } | | | ƒ } | |  k } | sKt j d | f d | |  f ƒ i t j | ƒ d 6d t j ƒ  k s¡ t j t  ƒ r° t j t  ƒ n d d 6t j | ƒ d	 6t j | ƒ d
 6t j | ƒ d 6d t j ƒ  k st j |  ƒ rt j |  ƒ n d d 6} d i | d 6} t t j	 | ƒ ƒ ‚ n  d } } } } } d S(   s%   Can a ScanItem be used as a hashable?t   bart   fooi    t   insX   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.ScanItem
}(%(py4)s, %(py6)s)
} in %(py10)st   py2R   R   R   t   py4R
   t   dctt   py10R	   s   assert %(py12)st   py12N(   R   (   sX   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.ScanItem
}(%(py4)s, %(py6)s)
} in %(py10)ss   assert %(py12)s(   R   t   ScanItemR   R   R   R   R   R   R   R   R   (   R!   t   @py_assert1t   @py_assert3R   t   @py_assert7t   @py_assert9t   @py_format11t   @py_format13(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_scanitem_hashable'   s    	      Ó   c           C   s3   t  j t ƒ  t j d d ƒ j d ƒ Wd  QXd  S(   NR   i    R   (   t   pytestt   raisest   NotImplementedErrorR   R$   t   matches(    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_scanitem_match-   s    c    	      C   s…  i d t  j d d d ƒ 6}  t  j } d } d } d } | | | | ƒ } | |  k } | sgt j d | f d | |  f ƒ i t j | ƒ d 6d t j ƒ  k s­ t j t  ƒ r¼ t j t  ƒ n d d	 6t j | ƒ d
 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6d t j ƒ  k s$t j |  ƒ r3t j |  ƒ n d d 6} d i | d 6} t t j	 | ƒ ƒ ‚ n  d } } } } } } d S(   s%   Can a ScanItem be used as a hashable?t   bazR   i    R   R   si   %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.ValuedScanItem
}(%(py4)s, %(py6)s, %(py8)s)
} in %(py12)sR   R   R   R   R    R
   R"   R!   R#   R	   s   assert %(py14)st   py14N(   R   (   si   %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.ValuedScanItem
}(%(py4)s, %(py6)s, %(py8)s)
} in %(py12)ss   assert %(py14)s(   R   t   ValuedScanItemR   R   R   R   R   R   R   R   R   (	   R!   R%   R&   R   R'   R(   t   @py_assert11R*   t   @py_format15(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_valuedscanitem_hashable3   s    	       ã   c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s$   Does the match match a valid string?i    s   Some-99 StringN(   R   t   UserStrScanItemR   R/   (   t   itemR   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_userstrscanitem_matches:   s    c    
      C   sx  t  j d ƒ }  d } |  j } d } | | } | | ƒ } t | ƒ g  f } | | k } | sZt j d | f d | | f ƒ i d t j ƒ  k s  t j | ƒ r¯ t j	 | ƒ n d d 6t j	 | ƒ d 6d	 t j ƒ  k sç t j |  ƒ rö t j	 |  ƒ n d	 d
 6t j	 | ƒ d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6}	 t
 t j |	 ƒ ƒ ‚ n  d } } } } } } d S(   s)   Does the match stop after a valid string?i    s   Some-99 Strings    - more Texts   ==sZ   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.matches
}((%(py3)s + %(py5)s))
} == %(py11)sR   R   R   R8   R   t   py5R
   t   py11R	   s   assert %(py13)st   py13N(   s   ==(   sZ   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.matches
}((%(py3)s + %(py5)s))
} == %(py11)ss   assert %(py13)s(   R   R7   R/   R   R   R   R   R   R   R   R   R   R   (
   R8   R   R%   R   t   @py_assert6R'   t   @py_assert10R(   t   @py_format12t   @py_format14(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_userstrscanitem_stopsA   s    	  
     Ó   c          C   sè  t  j }  d } d } d } |  | | | ƒ } t  j } d } d } | | | ƒ } | | k }	 |	 rºt j d f |	 f d f | | f ƒ i t j |  ƒ d 6d t j ƒ  k p¹ t j t  ƒ rË t j t  ƒ n d d 6t j | ƒ d	 6t j | ƒ d
 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6d t j ƒ  k pPt j t  ƒ rbt j t  ƒ n d d 6t j | ƒ d 6t j | ƒ d 6}
 d d i |
 d 6} t	 t j
 | ƒ ƒ ‚ n  t }  } } } } }	 } } } } d S(   sW   A SpecialUserStrScanItem compares different from a UserStrScanItem
    of the same typei   s	   <element>s    value s   !=sÃ   %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.SpecialUserStrScanItem
}(%(py4)s, %(py6)s, %(py8)s)
} != %(py20)s
{%(py20)s = %(py14)s
{%(py14)s = %(py12)s.UserStrScanItem
}(%(py16)s, %(py18)s)
}R   R   R   R   R    R
   R2   t   py16R"   R#   t   py20t   py18R	   s   assert %(py22)st   py22N(   R   t   SpecialUserStrScanItemR7   R   R   R   R   R   R   R   R   R   (   R%   R&   R   R'   R(   t   @py_assert13t   @py_assert15t   @py_assert17t   @py_assert19R4   t   @py_format21t   @py_format23(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt&   test_specialuserstrscanitem_notspecialI   s     	     	      ÿ *   c          C   s  t  j }  d } d } d } |  | | | ƒ } t  j } d } d } d } | | | | ƒ }	 | |	 k }
 |
 rÓt j d f |
 f d f | |	 f ƒ i t j |  ƒ d 6d t j ƒ  k pÂ t j t  ƒ rÔ t j t  ƒ n d d	 6t j | ƒ d
 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6d t j ƒ  k pYt j t  ƒ rkt j t  ƒ n d d 6t j | ƒ d 6t j | ƒ d 6t j |	 ƒ d 6} d d i | d 6} t t j	 | ƒ ƒ ‚ n  t
 }  } } } } }
 } } } } }	 d S(   sR   2 objects compare different when the strings following the <user_item>
    differsi   s	   <element>s    value0 s    value1 s   !=sÔ   %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.SpecialUserStrScanItem
}(%(py4)s, %(py6)s, %(py8)s)
} != %(py22)s
{%(py22)s = %(py14)s
{%(py14)s = %(py12)s.SpecialUserStrScanItem
}(%(py16)s, %(py18)s, %(py20)s)
}R   R   R   R   R    R
   R2   RB   R"   R#   RC   RD   RE   R	   s   assert %(py24)st   py24N(   R   RF   R   R   R   R   R   R   R   R   R   (   R%   R&   R   R'   R(   RG   RH   RI   RJ   t   @py_assert21R4   RL   t   @py_format25(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt%   test_specialuserstrscanitem_differentP   s"    	     	       ÿ :   c          C   s  t  j }  d } d } d } |  | | | ƒ } t  j } d } d } d } | | | | ƒ }	 | |	 k }
 |
 rÓt j d f |
 f d f | |	 f ƒ i t j |  ƒ d 6d t j ƒ  k pÂ t j t  ƒ rÔ t j t  ƒ n d d 6t j | ƒ d	 6t j | ƒ d
 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6d t j ƒ  k pYt j t  ƒ rkt j t  ƒ n d d 6t j | ƒ d 6t j | ƒ d 6t j |	 ƒ d 6} d d i | d 6} t t j	 | ƒ ƒ ‚ n  t
 }  } } } } }
 } } } } }	 d S(   sS   2 objects compare equal when the strings followig the <user_item>
    do not differi   s	   <element>s    value s   ==sÔ   %(py10)s
{%(py10)s = %(py2)s
{%(py2)s = %(py0)s.SpecialUserStrScanItem
}(%(py4)s, %(py6)s, %(py8)s)
} == %(py22)s
{%(py22)s = %(py14)s
{%(py14)s = %(py12)s.SpecialUserStrScanItem
}(%(py16)s, %(py18)s, %(py20)s)
}R   R   R   R   R    R
   R2   RB   R"   R#   RC   RD   RE   R	   s   assert %(py24)sRN   N(   R   RF   R   R   R   R   R   R   R   R   R   (   R%   R&   R   R'   R(   RG   RH   RI   RJ   RO   R4   RL   RP   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_specialuserstrscanitem_sameW   s"    	     	       ÿ :   c    
      C   s~  t  j d d d ƒ }  d } |  j } d } | | } | | ƒ } t | ƒ g  f } | | k } | s`t j d | f d | | f ƒ i d t j ƒ  k s¦ t j | ƒ rµ t j	 | ƒ n d d	 6t j	 | ƒ d
 6d t j ƒ  k sí t j |  ƒ rü t j	 |  ƒ n d d 6t j	 | ƒ d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6}	 t
 t j |	 ƒ ƒ ‚ n  d } } } } } } d S(   s>   Comparison works when there's a trailing string where expectedi   s	   <element>s    value s   Some Element or Anothers    value and mores   ==sZ   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.matches
}((%(py3)s + %(py5)s))
} == %(py11)sR   R   R   R8   R   R:   R
   R;   R	   s   assert %(py13)sR<   N(   s   ==(   sZ   %(py8)s
{%(py8)s = %(py2)s
{%(py2)s = %(py0)s.matches
}((%(py3)s + %(py5)s))
} == %(py11)ss   assert %(py13)s(   R   RF   R/   R   R   R   R   R   R   R   R   R   R   (
   R8   R   R%   R   R=   R'   R>   R(   R?   R@   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt)   test_specialuserstrscanitem_trail_succeed^   s    	  
     Ó   c          C   s/   t  j d d d ƒ }  d } t |  j | ƒ d S(   s0   Comparison works when there's no trailing stringi   s	   <element>s    value s   Some Element or AnotherN(   R   RF   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt+   test_specialuserstrscanitem_notrail_succeede   s    c          C   sê  t  j d d d ƒ }  d } |  j | d ƒ } t | ƒ g  f } | | k } | sç t j d | f d | | f ƒ i t j | ƒ d 6d	 t j ƒ  k s¤ t j	 | ƒ r³ t j | ƒ n d	 d
 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } | d } d } t | ƒ }	 | |	 k } | sÔt j d | f d | |	 f ƒ i d t j ƒ  k sat j	 t ƒ rpt j t ƒ n d d 6t j | ƒ d 6t j |	 ƒ d 6t j | ƒ d 6}
 d i |
 d 6} t
 t j | ƒ ƒ ‚ n  d } } } }	 d S(   sB   Comparison fails when there's a trailing string where not expectedi   s	   <element>s    value s   Some random value or Anothers    value and mores   !=s   %(py0)s != %(py3)sR   t   resultR   R	   s   assert %(py5)sR:   i    s   Some randoms   ==s0   %(py1)s == %(py7)s
{%(py7)s = %(py3)s(%(py5)s)
}R   R   t   py7s   assert %(py9)st   py9N(   s   !=(   s   %(py0)s != %(py3)ss   assert %(py5)s(   s   ==(   s0   %(py1)s == %(py7)s
{%(py7)s = %(py3)s(%(py5)s)
}s   assert %(py9)s(   R   RF   R/   R   R   R   R   R   R   R   R   R   R   (   R8   R   RU   R   R%   t   @py_format4t   @py_format6t   @py_assert0R   R=   t   @py_format8t   @py_format10(    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt&   test_specialuserstrscanitem_trail_faill   s&       l   

     Œ   c          C   sH  t  j d d d ƒ }  t  j d d d ƒ } t |  ƒ } t |  ƒ } | | k } | r©t j d f | f d f | | f ƒ i t j | ƒ d 6d t j ƒ  k pª t j |  ƒ r¼ t j |  ƒ n d d	 6d
 t j ƒ  k pá t j t ƒ ró t j t ƒ n d
 d 6d t j ƒ  k pt j |  ƒ r*t j |  ƒ n d d 6d
 t j ƒ  k pOt j t ƒ rat j t ƒ n d
 d 6t j | ƒ d 6} d d i | d 6} t	 t j
 | ƒ ƒ ‚ n  t } } } t |  ƒ } t | ƒ } | | k } | r6t j d f | f d f | | f ƒ i t j | ƒ d 6d t j ƒ  k p7t j |  ƒ rIt j |  ƒ n d d	 6d
 t j ƒ  k pnt j t ƒ r€t j t ƒ n d
 d 6d t j ƒ  k p¥t j | ƒ r·t j | ƒ n d d 6d
 t j ƒ  k pÜt j t ƒ rît j t ƒ n d
 d 6t j | ƒ d 6} d d i | d 6} t	 t j
 | ƒ ƒ ‚ n  t } } } d S(   s1   The hash function works with special user stringsi   s	   <element>s    value0 s    value1 s   ==sN   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py8)s
{%(py8)s = %(py5)s(%(py6)s)
}R   t   item0R   t   hashR   R   R:   R
   R	   s   assert %(py10)sR"   s   !=sN   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} != %(py8)s
{%(py8)s = %(py5)s(%(py6)s)
}t   item1N(   R   RF   R_   R   R   R   R   R   R   R   R   R   (   R^   R`   R   R'   R   R   R)   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_specialuserstrscanitem_hashu   s(        ÿ (       ÿ (   c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s   A hash scan item matches digitsi    t   2340N(   R   t   HashScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_hashscanitem_matches~   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s2   A hash scan item matches digits with leading zerosi    t   02340N(   R   Rc   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt"   test_hashscanitem_matches_leading0…   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s2   A hash scan item does not match digits and lettersi    t   02a340N(   R   Rc   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_hashscanitem_failsŒ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s*   An entity matches a reasonable entity namei    s   Some EntityN(   R   t   EntityScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_entity_scan_item”   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s%   A date scan item matches a valid datei    s
   2017-01-01N(   R   t   DateScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt$   test_date_scan_item_matches_gooddateœ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s(   A date scan item matches an invalid datei    s
   0000-00-00N(   R   Rk   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt#   test_date_scan_item_matches_baddate£   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s,   A date scan item does not match a short datei    s   2017-1-1N(   R   Rk   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt"   test_date_scan_item_mismatch_shortª   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s4   A date scan item does not match non-date-like stringi    s   2017-sandwitch-1N(   R   Rk   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt$   test_date_scan_item_mismatch_letters±   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s$   A year scan item matches a good yeari    t   2017N(   R   t   YearScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_year_scan_item_match_good¹   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s#   A year scan item matches a bad yeari    t   0017N(   R   Rq   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_year_scan_item_match_badÀ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s+   A year scan item does not match alpha charsi    t   20a17N(   R   Rq   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt"   test_year_scan_item_mismatch_alphsÇ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s   A hash scan item matches digitsi    Rb   N(   R   t   Last4DigitsScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_last4digitsscanitem_matchesÏ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s2   A hash scan item matches digits with leading zerosi    t   0234N(   R   Rw   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt)   test_last4digitsscanitem_matches_leading0Ö   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s2   A hash scan item does not match digits and lettersi    t   2a340N(   R   Rw   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_last4digitsscanitem_failsÝ   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s   A version number matchesi    s    v10N(   R   t   VersionScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_versionscanitem_matcheså   s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s    A version with a leading 0 failsi    s    v01N(   R   R}   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt#   test_versionscanitem_fails_leading0ì   s    c          C   s,   t  j d d ƒ }  d } t |  j | ƒ d S(   s2   A parenthetical with no optional user text matchesi    s    (some parenthetical)N(   R   t   ParenScanItemR   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_parenscanitem_matches_plainô   s    c    	      C   sd  t  j d d ƒ }  d } d | d } |  j } | | ƒ } t | ƒ | g f } | | k } | sNt j d | f d | | f ƒ i d t j ƒ  k s¤ t j | ƒ r³ t j	 | ƒ n d d	 6t j	 | ƒ d
 6d t j ƒ  k së t j |  ƒ rú t j	 |  ƒ n d d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } } } d S(   si   A parenthetical with valid optional user text matches and returns
    the expected content to be reportedi    s    (some parenthetical)s   some parenthetical; Extra Stuffs    (t   )s   ==sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)sR   R   R   R8   R   R
   R:   R	   s   assert %(py10)sR"   N(   s   ==(   sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)ss   assert %(py10)s(   R   R€   R/   R   R   R   R   R   R   R   R   R   R   (	   R8   t   contentR   R%   R   R'   R=   R   R)   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_parenscanitem_matches_extraû   s    	     Ã   c          C   s,   t  j d d ƒ }  d } t |  j | ƒ d S(   s5   A parenthetical with different content fails to matchi    s    (some parenthetical)s    (some other parenthetical)N(   R   R€   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt!   test_parenscanitem_nomatch_differ  s    c          C   s,   t  j d d ƒ }  d } t |  j | ƒ d S(   s>   A parenthetical with invalid optional user text does not matchi    s    (some parenthetical)s    (some parenthetical; ===)N(   R   R€   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt    test_parenscanitem_nomatch_extra  s    c          C   s,   t  j d d ƒ }  d } t |  j | ƒ d S(   s.   A parenthetical does not match non-parenthesisi    s    (some parenthetical)s    some parentheticalN(   R   R€   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt#   test_parenscanitem_nomatch_notparen  s    c    	      C   sa  t  j d ƒ }  d } d | d } |  j } | | ƒ } t | ƒ | g f } | | k } | sKt j d | f d | | f ƒ i d t j ƒ  k s¡ t j | ƒ r° t j	 | ƒ n d d 6t j	 | ƒ d	 6d
 t j ƒ  k sè t j |  ƒ r÷ t j	 |  ƒ n d
 d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6} t
 t j | ƒ ƒ ‚ n  d } } } } d S(   s:   A repeated parens scan item matches a single parentheticali    s   some text and mores    (R‚   s   ==sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)sR   R   R   R8   R   R
   R:   R	   s   assert %(py10)sR"   N(   s   ==(   sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)ss   assert %(py10)s(   R   t   RepeatedParensScanItemR/   R   R   R   R   R   R   R   R   R   R   (	   R8   Rƒ   R   R%   R   R'   R=   R   R)   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt$   test_repeatedparensscanitem_matches1  s    	     Ã   c    
      C   sr  t  j d ƒ }  d } d } d | d | d } |  j } | | ƒ } t | ƒ | | g f } | | k } | s\t j d | f d | | f ƒ i d	 t j ƒ  k s² t j | ƒ rÁ t j	 | ƒ n d	 d
 6t j	 | ƒ d 6d t j ƒ  k sù t j |  ƒ rt j	 |  ƒ n d d 6t j	 | ƒ d 6t j	 | ƒ d 6} d i | d 6}	 t
 t j |	 ƒ ƒ ‚ n  d } } } } d S(   s6   A repeated parens scan item matches two parentheticalsi    s   some text and mores   another parentheticals    (s   ) (R‚   s   ==sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)sR   R   R   R8   R   R
   R:   R	   s   assert %(py10)sR"   N(   s   ==(   sM   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.matches
}(%(py3)s)
} == %(py8)ss   assert %(py10)s(   R   Rˆ   R/   R   R   R   R   R   R   R   R   R   R   (
   R8   t   content1t   content2R   R%   R   R'   R=   R   R)   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt$   test_repeatedparensscanitem_matches2"  s    	     Ã   c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s3   A repeated parens scan item fails on trailing charsi    s    (some text; and more) N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt*   test_repeatedparensscanitem_fails_trailing+  s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   sB   A repeated parens scan item fails when parenthetical is not closedi    s    (some text; and more N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt+   test_repeatedparensscanitem_fails_notclosed2  s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s9   A repeated parens scan item fails without a leading spacei    s   (some text; and more)N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt0   test_repeatedparensscanitem_fails_noleadingspace9  s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s?   A repeated parens scan item fails when space follows open pareni    s   ( some text; and more)N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt+   test_repeatedparensscanitem_fails_openspace@  s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s>   A repeated parens scan item fails when space leads close pareni    s   (some text; and more )N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt,   test_repeatedparensscanitem_fails_closespaceG  s    c          C   s)   t  j d ƒ }  d } t |  j | ƒ d S(   s,   A repeated parens scan item fails when emptyi    s   ()N(   R   Rˆ   R   R/   (   R8   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt+   test_repeatedparensscanitem_fails_nocontentN  s    c          C   s9   t  j d g  ƒ }  t j t ƒ  |  j d ƒ Wd QXd S(   s5   Trying to match an optional scan item raises an errori    t   anythingN(   R   t   OptionalScanItemR,   R-   R.   R/   (   R8   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt$   test_optionalscanitem_does_not_matchV  s    c    	      C   sW  d }  d } d |  d | d } t  j } | | ƒ } |  | g } | | k } | sAt j d | f d | | f ƒ i d t j ƒ  k s— t j | ƒ r¦ t j | ƒ n d d	 6t j | ƒ d
 6d t j ƒ  k sÞ t j t  ƒ rí t j t  ƒ n d d 6t j | ƒ d 6t j | ƒ d 6} d i | d 6} t t j	 | ƒ ƒ ‚ n  d } } } } d S(   s   Returns what's expecteds   some text and mores   another parentheticals    (s   ) (R‚   s   ==s\   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.repeated_paren_content
}(%(py3)s)
} == %(py8)sR   R   R   R   R   R
   R:   R	   s   assert %(py10)sR"   N(   s   ==(   s\   %(py5)s
{%(py5)s = %(py2)s
{%(py2)s = %(py0)s.repeated_paren_content
}(%(py3)s)
} == %(py8)ss   assert %(py10)s(   R   t   repeated_paren_contentR   R   R   R   R   R   R   R   R   (	   RŠ   R‹   R   R%   R   R'   R=   R   R)   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_repeated_paren_contenth  s    	     Ã   c          C   sí   t  j d g d ƒ }  |  j } d } | | k } | sÛ t j d | f d | | f ƒ i t j | ƒ d 6d t j ƒ  k sˆ t j |  ƒ r— t j |  ƒ n d d	 6t j | ƒ d
 6} d i | d 6} t	 t j
 | ƒ ƒ ‚ n  d } } } d S(   sp   Test that a scan item list of one item produces a
    specialuserstrscanitem with an empty string for a next_strt   user_strs
   <anything>i    R	   s   ==s0   %(py2)s
{%(py2)s = %(py0)s.next_str
} == %(py5)sR   R8   R   R:   s   assert %(py7)sRV   N(   s   user_strs
   <anything>(   s   ==(   s0   %(py2)s
{%(py2)s = %(py0)s.next_str
} == %(py5)ss   assert %(py7)s(   R   t   scan_to_specialuserstrscanitemt   next_strR   R   R   R   R   R   R   R   R   (   R8   R%   R   R&   RY   R[   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt#   test_scan_to_specialuserstrscanitemq  s    	    |   c          C   sÙ  t  j d g d ƒ }  t |  ƒ } d } | | k } | st j d | f d | | f ƒ i t j | ƒ d 6d t j ƒ  k s‹ t j |  ƒ rš t j |  ƒ n d d	 6d
 t j ƒ  k sÂ t j t ƒ rÑ t j t ƒ n d
 d 6t j | ƒ d 6} d i | d 6} t	 t j
 | ƒ ƒ ‚ n  d } } } |  d } | j } d } | | k } | sót j d | f d | | f ƒ i t j | ƒ d 6d t j ƒ  k s t j | ƒ r¯t j | ƒ n d d 6t j | ƒ d 6}	 d i |	 d 6}
 t	 t j
 |
 ƒ ƒ ‚ n  d } } } | j } d } | | k } | sÇt j d  | f d! | | f ƒ i t j | ƒ d 6d t j ƒ  k stt j | ƒ rƒt j | ƒ n d d 6t j | ƒ d 6}	 d" i |	 d 6}
 t	 t j
 |
 ƒ ƒ ‚ n  d } } } d S(#   s1   Does an entity tuple produce an entity scan item?t   entitys   Some Entityi   i   s   ==s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)sR   t   itemsR   R   R   R   R	   s   assert %(py8)sR
   i    s,   %(py2)s
{%(py2)s = %(py0)s.type
} == %(py5)sR   R8   R:   s   assert %(py7)sRV   s+   %(py2)s
{%(py2)s = %(py0)s.pos
} == %(py5)sN(   s   entitys   Some Entity(   s   ==(   s0   %(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py2)s
{%(py2)s = %(py0)s.type
} == %(py5)ss   assert %(py7)s(   s   ==(   s+   %(py2)s
{%(py2)s = %(py0)s.pos
} == %(py5)ss   assert %(py7)s(   R   t   tuple_to_itemsR   R   R   R   R   R   R   R   R   R   t   typet   pos(   R   R   R   R   R   R   R8   R%   R&   RY   R[   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_tuple_to_items_entity~  s4        ³   
	    |   	    |   c           C   s-   t  j t ƒ  t j d g d ƒ Wd QXd S(   s2   Do we get an exception when supplying a bad tuple?t   unknowntypet	   somevaluei   N(   R¢   R£   (   R,   R-   t
   ValueErrorR   Rž   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_tuple_to_items_badtuple‡  s    c          C   sã   t  j j d ƒ }  t j |  d ƒ } | d } | j } d } | | k } | sÍ t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d	 6} d i | d 6} t	 t j
 | ƒ ƒ ‚ n  d } } } } d S(   sN   A speicaluserstrscanitem gets the correct next_str when given
    parsed inputs   <element one> by <element two>i
   i    s    by s   ==s0   %(py3)s
{%(py3)s = %(py1)s.next_str
} == %(py6)sR   R   R   R	   s   assert %(py8)sR
   N(   s   ==(   s0   %(py3)s
{%(py3)s = %(py1)s.next_str
} == %(py6)ss   assert %(py8)s(   R   t   parsert   parseR   Rž   Rš   R   R   R   R   R   R   (   t   scanR   RZ   R   R   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_tuple_to_items_parsed  s    
 	    U   c          C   sJ  t  j t d ƒ ƒ }  |  d } | j } d } | | k } | s¾ t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d
 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j
 } d } | | k } | syt j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d
 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j } d } | | k } | s4t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d
 6} t t j | ƒ ƒ ‚ n  d } } } } d S(   s3   Do we get valid position information in scan items?s   two words <address>i    s   ==s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)sR   R   R   R	   s   assert %(py8)sR
   i
   t   addresss,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)sN(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   R   t   to_scan_itemsR§   R    R   R   R   R   R   R   RŸ   (   R   RZ   R   R   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_to_scan_item_pos_simple–  s8    
 	    U   
 	    U   
 	    U   c          C   s  t  j t d ƒ ƒ }  |  d } | j } d } | | k } | s¾ t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j
 } d } | | k } | syt j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } } d S(   s3   Do we get valid position information in scan items?s"   two words <address> - <yyyy-mm-dd>i   t   dates   ==s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)sR   R   R   R	   s   assert %(py8)sR
   i   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)sN(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   R   R«   R§   RŸ   R   R   R   R   R   R   R    (   R   RZ   R   R   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_to_scan_item_pos_complexŸ  s(    
 	    U   
 	    U   c          C   s‘  t  j t d ƒ ƒ }  |  d } | j } d } | | k } | s¾ t j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j
 } d } | | k } | syt j d | f d | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j } d } | | k } | s;t j d | f d  | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d! i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j
 } d } | | k } | sýt j d" | f d# | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d$ i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j } d } | | k } | s¿t j d% | f d& | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d' i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j
 } d } | | k } | st j d( | f d) | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d* i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j } d } | | k } | s<t j d+ | f d, | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d- i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d } | j
 } d } | | k } | s÷t j d. | f d/ | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d0 i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j } d } | | k } | s¹t j d1 | f d2 | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d3 i | d 6} t t j | ƒ ƒ ‚ n  d } } } } |  d j d } | j
 } d } | | k } | s{t j d4 | f d5 | | f ƒ i t j | ƒ d 6t j | ƒ d 6t j | ƒ d 6} d6 i | d 6} t t j | ƒ ƒ ‚ n  d } } } } d S(7   s?   Is position information valid with optional pattern components?s8   two words <address>[ - <yyyy-mm-dd>][ - <last 4 digits>]i   t   optionals   ==s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)sR   R   R   R	   s   assert %(py8)sR
   i   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)si    t   stringi   i   R­   i   i   i$   t   last_4_digitsi(   N(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   s   ==(   s,   %(py3)s
{%(py3)s = %(py1)s.type
} == %(py6)ss   assert %(py8)s(   s   ==(   s+   %(py3)s
{%(py3)s = %(py1)s.pos
} == %(py6)ss   assert %(py8)s(   R   R«   R§   RŸ   R   R   R   R   R   R   R    t   value(   R   RZ   R   R   R   R   R   (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   test_to_scan_item_optional_pos¨  s¸    
 	    U   
 	    U    	    U    	    U    	    U    	    U   
 	    U   
 	    U    	    U    	    U   (A   t   __builtin__R   t   _pytest.assertion.rewritet	   assertiont   rewriteR   R,   t   enforcerR    R   R   R   R   R+   R0   R6   R9   RA   RM   RQ   RR   RS   RT   R]   Ra   Rd   Rf   Rh   Rj   Rl   Rm   Rn   Ro   Rr   Rt   Rv   Rx   Rz   R|   R~   R   R   R„   R…   R†   R‡   R‰   RŒ   R   RŽ   R   R   R‘   R’   R•   R¦   R§   R—   R›   R¡   R¥   R©   R¬   R®   R³   (    (    (    sT   /home/kop/biz/barnett/enforcer_project/BRIEF-Script/Enforcer/tests/test_scan_item.pyt   <module>   st     																																																													