
    (Ti                        d Z ddlZddlZddlZddlmZ ddlZ ee      j                  j                  dz  Z
ej                  j                  de
      Zeej                  J ej                  j                  e      Zej                  j#                  e       dZdZ G d d	      Z G d
 d      Z G d d      Z G d d      Zy)uw  
two_pass_audit.py의 threading regex 수정 검증 테스트.

수정 전: threading backslash-dot w+(?!Lock|RLock|Event|Semaphore)
  -> \w+가 "Event" 소비 후 lookahead가 "(" 위치에서 평가 -> 오탐

수정 후: threading backslash-dot (?!Lock|RLock|Event|Semaphore|Condition|Barrier)\w+
  -> lookahead가 \w+ 앞에서 평가 -> Event 등을 올바르게 제외
    N)Pathtwo_pass_audit.pytwo_pass_audit_modulez,threading\.\w+(?!Lock|RLock|Event|Semaphore)z>threading\.(?!Lock|RLock|Event|Semaphore|Condition|Barrier)\w+c                   "    e Zd ZdZd Zd Zd Zy)TestBuggyPatternFalsePositivesuC   수정 전 패턴이 오탐(false positive)을 일으킴을 확인.c                 F    t        j                  t        d      J d       y)u/   버그 패턴은 threading.Event()를 오탐함e = threading.Event()Nu6   버그 패턴은 threading.Event()를 오탐해야 함researchBUGGY_PATTERNselfs    P/home/jay/workspace/teams/dev1/qc/verifiers.bak/tests/test_two_pass_audit_fix.py test_buggy_pattern_matches_eventz?TestBuggyPatternFalsePositives.test_buggy_pattern_matches_event.   s(     IIm%<=I	DC	DI    c                 <    t        j                  t        d      J y)u3   버그 패턴은 threading.Condition()도 오탐함zc = threading.Condition()Nr
   r   s    r   $test_buggy_pattern_matches_conditionzCTestBuggyPatternFalsePositives.test_buggy_pattern_matches_condition4   s    yy(CDPPPr   c                 <    t        j                  t        d      J y)u2   버그 패턴은 threading.Barrier(5)도 오탐함zb = threading.Barrier(5)Nr
   r   s    r   "test_buggy_pattern_matches_barrierzATestBuggyPatternFalsePositives.test_buggy_pattern_matches_barrier8   s    yy(BCOOOr   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r   +   s    MDQPr   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	 TestFixedPatternNoFalsePositivesuJ   수정 후 패턴은 안전한 threading primitive를 탐지하지 않음.c                 <    t        j                  t        d      J y)u(   threading.Event()는 탐지하지 않음r	   Nr   r   FIXED_PATTERNr   s    r   test_fixed_does_not_match_eventz@TestFixedPatternNoFalsePositives.test_fixed_does_not_match_eventE   s    yy(?@HHHr   c                 <    t        j                  t        d      J y)u'   threading.Lock()은 탐지하지 않음zlock = threading.Lock()Nr   r   s    r   test_fixed_does_not_match_lockz?TestFixedPatternNoFalsePositives.test_fixed_does_not_match_lockI   s    yy(ABJJJr   c                 <    t        j                  t        d      J y)u(   threading.RLock()은 탐지하지 않음zrlock = threading.RLock()Nr   r   s    r   test_fixed_does_not_match_rlockz@TestFixedPatternNoFalsePositives.test_fixed_does_not_match_rlockM   s    yy(CDLLLr   c                 <    t        j                  t        d      J y)u-   threading.Semaphore(5)는 탐지하지 않음zsem = threading.Semaphore(5)Nr   r   s    r   #test_fixed_does_not_match_semaphorezDTestFixedPatternNoFalsePositives.test_fixed_does_not_match_semaphoreQ       yy(FGOOOr   c                 <    t        j                  t        d      J y)u,   threading.Condition()은 탐지하지 않음zcond = threading.Condition()Nr   r   s    r   #test_fixed_does_not_match_conditionzDTestFixedPatternNoFalsePositives.test_fixed_does_not_match_conditionU   r(   r   c                 <    t        j                  t        d      J y)u+   threading.Barrier(3)는 탐지하지 않음zb = threading.Barrier(3)Nr   r   s    r   !test_fixed_does_not_match_barrierzBTestFixedPatternNoFalsePositives.test_fixed_does_not_match_barrierY   s    yy(BCKKKr   N)
r   r   r   r   r!   r#   r%   r'   r*   r,   r   r   r   r   r   B   s)    TIKMPPLr   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)!TestFixedPatternDetectsRiskyUsageu=   수정 후 패턴도 위험한 threading 사용을 탐지함.c                 <    t        j                  t        d      J y)uD   threading.Thread(target=...)는 탐지함 (락 없음 경고 대상)zt = threading.Thread(target=fn)Nr   r   s    r   test_fixed_matches_threadz;TestFixedPatternDetectsRiskyUsage.test_fixed_matches_threadf   s    yy(IJVVVr   c                 <    t        j                  t        d      J y)u#   threading.Timer(1, fn)는 탐지함zt = threading.Timer(1, fn)Nr   r   s    r   test_fixed_matches_timerz:TestFixedPatternDetectsRiskyUsage.test_fixed_matches_timerj       yy(DEQQQr   c                 <    t        j                  t        d      J y)u   threading.local()은 탐지함ztls = threading.local()Nr   r   s    r   test_fixed_matches_localz:TestFixedPatternDetectsRiskyUsage.test_fixed_matches_localn   s    yy(ABNNNr   c                 <    t        j                  t        d      J y)u'   threading.current_thread()는 탐지함zthreading.current_thread()Nr   r   s    r   !test_fixed_matches_current_threadzCTestFixedPatternDetectsRiskyUsage.test_fixed_matches_current_threadr   r3   r   N)r   r   r   r   r0   r2   r5   r7   r   r   r   r.   r.   c   s    GWRORr   r.   c                   .    e Zd ZdZdefdZd Zd Zd Zy)TestSourceContainsFixedPatternuH   two_pass_audit.py 소스 파일에 수정된 패턴이 있음을 확인.returnc                     t        t              j                  j                  dz  }|j                         s
J d|        |j	                  d      S )Nr   u   소스 파일이 없음: zutf-8)encoding)r   __file__parentexists	read_text)r   source_paths     r   _load_sourcez+TestSourceContainsFixedPattern._load_source   sP    8n++225HH!!#N'@%NN#$$g$66r   c                 :    | j                         }d|v sJ d       y)u1   소스에 수정된 lookahead 패턴이 포함됨zthreading\.(?!u6   수정된 패턴 'threading\.(?!' 이 소스에 없음NrB   r   srcs     r   test_fixed_pattern_in_sourcez;TestSourceContainsFixedPattern.test_fixed_pattern_in_source   s$    ! C'b)bb'r   c                 :    | j                         }d|vsJ d       y)u(   소스에 버그 있는 패턴이 없음zthreading\.\w+(?!uD   버그 패턴 'threading\.\w+(?!' 이 소스에 아직 남아 있음NrD   rE   s     r    test_buggy_pattern_not_in_sourcez?TestSourceContainsFixedPattern.test_buggy_pattern_not_in_source   s$    !#3.x0xx.r   c                 <    | j                         }d|v sJ d|v sJ y)u2   Condition과 Barrier가 제외 목록에 포함됨	ConditionBarrierNrD   rE   s     r   ,test_condition_and_barrier_in_exclusion_listzKTestSourceContainsFixedPattern.test_condition_and_barrier_in_exclusion_list   s,    !c!!!Cr   N)	r   r   r   r   strrB   rG   rI   rM   r   r   r   r9   r9   |   s"    R7c 7
cy
 r   r9   )r   importlib.util	importlibr   syspathlibr   pytestr=   r>   _TWO_PASS_PATHutilspec_from_file_location_specloadermodule_from_spec_two_pass_moduleexec_moduler   r    r   r   r.   r9   r   r   r   <module>r\      s     	 
   h&&--0CC../FWU\\5 55>>2259    ) * @ RP P.L LBR R2   r   