
    3jk-                        d Z ddl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 dgZddej                  ej                  z  fdZddZ ej"                  d	      Zddd
ZdddZd Zedk(  r e        yy)z
The testRunner module contains the all important "mainTest" function that runs tests
in a given module.  Except for the one instance of "defaultImports", everything here
can run on any system, not just music21.
    )annotationsN)parenthesesMatchParenthesesMatchmusic21Fc           	        t        j                         }|s+t        t        d         j                  j                         }n|i }|D ]~  }t        j                  |      st        |dd      }|)|D ]Q  }||   }	|j                  |	|||d      }
|
j                  s*t        j                  |
|      }| j                  |       S  y)a~  
    takes a suite, such as a doctest.DocTestSuite and the list of variables
    in a module and adds from those classes that have a _DOC_ATTR dictionary
    (which documents the properties in the class) any doctests to the suite.

    >>> import doctest
    >>> s1 = doctest.DocTestSuite(chord)
    >>> s1TestsBefore = len(s1._tests)
    >>> before = set(s1._tests)
    >>> allLocals = [getattr(chord, x) for x in dir(chord)]
    >>> test.testRunner.addDocAttrTestsToSuite(s1, allLocals)
    >>> s1TestsAfter = len(s1._tests)
    >>> s1TestsAfter - s1TestsBefore
    4
    >>> lastTest = s1._tests[-1]
    >>> lastTest
    client ()
    r   N	_DOC_ATTR)optionflags)doctestDocTestParser
__import__defaultImports__dict__copyinspectisclassgetattrget_doctestexamplesDocTestCaseaddTest)suitemoduleVariableListsouterFilenameglobsr	   dtplvkdocattrdockeydocumentationdtdtcs               D/DATA/.local/lib/python3.12/site-packages/music21/test/testRunner.pyaddDocAttrTestsToSuiter#   "   s    4 


!C>!,-66;;=	"$#{D1?F#FOMv}aPB;;%%b2=(C MM#  #    c                x   t        j                         dk(  }t        j                  d   dk\  }| D ]  }t	        |d      s|j
                  }|j                  D ]^  }t        |j                  d      |_        |rt        |j                  d      |_        |s>|j                  j                  dd      |_        `  y	)
z
    Fix doctests so that addresses are sanitized, WindowsPath is okay on windows
    and OrderedDicts pass on Python 3.12.

    In the past this fixed other differences among Python versions.
    In the future, it will again!
    Windows      _dt_testz0x......	PosixPathWindowsPathN)platformsystemsysversion_infohasattrr)   r   stripAddresseswantfix312OrderedDictreplace)doctestSuitewindowsisPython312r!   r    examples         r"   fixDoctestsr:   V   s     OO%2G""1%+KsJ'\\{{G)',,@GL0uE&||33KO # r$   z0x[0-9A-Fa-f]+c                .    t         j                  ||       S )a7  
    Function that changes all memory addresses (pointers) in the given
    textString with (replacement).  This is useful for testing
    that a function gives an expected result even if the result
    contains references to memory locations.  So for instance:

    >>> stripA = test.testRunner.stripAddresses
    >>> stripA('{0.0} <music21.clef.TrebleClef object at 0x02A87AD0>')
    '{0.0} <music21.clef.TrebleClef object at ADDRESS>'

    while this is left alone:

    >>> stripA('{0.0} <music21.humdrum.spineParser.MiscTandem *>I>')
    '{0.0} <music21.humdrum.spineParser.MiscTandem *>I>'

    For doctests, can strip to '...' to make it work fine with doctest.ELLIPSIS

    >>> stripA('{0.0} <music21.base.Music21Object object at 0x102a0ff10>', '0x...')
    '{0.0} <music21.base.Music21Object object at 0x...>'
    )ADDRESSsub)
textStringreplacements     r"   r2   r2   q   s    * ;;{J//r$   c           	     N   d| vr| S 	 t        | dd      }g }d}|D ]R  }|j                  | ||j                  t        d      z
          |j                  d|z   dz          |j                  dz   }T |j                  | |d        d	j                  |      S # t        $ r |cY S w xY w)
a  
    Function that fixes the OrderedDicts to work on Python 3.12 and above.
    (eventually when 3.12 is the norm, this should be replaced to neuter
    the doctests for 3.11 instead.  Or just wait until 3.12 is the minimum version?)

    >>> fix312 = test.testRunner.fix312OrderedDict
    >>> fix312('OrderedDict([(0, 1), (1, 2), (2, 3)])')
    'OrderedDict({...})'

    while this is left alone:

    >>> fix312('{0: 1, 1: 2, 2: 3}', 'nope!')
    '{0: 1, 1: 2, 2: 3}'
    zOrderedDict([(z)]))opencloser   zOrderedDict({z})   N )r   appendstartlenendjoin
ValueError)r>   r?   matchesoutlastms         r"   r4   r4      s     z)":4DERAJJz$qww5E1F'FGHJJ4t;<5519D  	

:de$%wws| s   BB B$#B$c                 \
   d}t        |j                  dd            }|r3t        j                  t        j                  z  t        j
                  z  }n!t        j                  t        j                  z  }d}d| v s?dt        j                  v s-dt        j                  v st        |j                  dd            rd}nd}|rt        j                         }nd| v s-dt        j                  v st        |j                  dd            rnt        D ]%  }t        |      j                  j                         }' d| v s-dt        j                  v st        |j                  dd            r3|j                  t        j                          d	   d
   j"                         	 t        j$                  d||      }d	}
d| v s-dt        j                  v st        |j                  dd            rd}
d}dt        j                  v sHdt        j                  v s6t        |j                  dd            st        |j                  dd            rd}d}d}t+        t        j                        dk(  r8t        j                  d	   j-                         }|dvrt        j                  d	   }t        |j                  dd            r|j                  dd      }dt        j                  v sd| v st        |j                  dd            rg } | D ]L  }t/        |t0              r|r2t        j2                  j5                  |      D ]  }t)        d|         | |       }t7        |      D ]o  }|j-                         |j-                         k(  sI|j-                         d|j-                         z   k(  s%|j-                         d|j-                         z   k(  sm|} n t9        ||      r3t)        d|        |j;                           t=        ||              d} nBt)        d| d       t        j2                  j?                  |      }|jA                  |       O |sit        j                          }t+        |      d	kD  r|d	   }n|d
   }|d
   }|d	   }tC        |jD                  jG                               }tI        |||||       |r8tK        |       t        jL                         }|
|_'        |jQ                  |      }yy# t&        $ r-}	t)        d|	        t        j                         }Y d}	~	td}	~	ww xY w)at  
    Takes as its arguments modules (or a string 'noDocTest' or 'verbose')
    and runs all of these modules through a unittest suite

    Unless 'noDocTest' is passed as a module, a docTest
    is also performed on `__main__`, hence the name "mainTest".

    If 'moduleRelative' (a string) is passed as a module, then
    global variables are preserved.

    Run example (put at end of your modules):

    ::

        import unittest
        class Test(unittest.TestCase):
            def testHello(self):
                hello = 'Hello'
                self.assertEqual('Hello', hello)

        import music21
        if __name__ == '__main__':
            music21.mainTest(Test)

    This module tries to fix up some differences between python2 and python3 so
    that the same doctests can work.  These differences can now be removed, but
    I cannot remember what they are!
    TfailFastN	noDocTest	nodoctestFmoduleRelativeimportPlusRelativer'   r   __main__)r   r	   zEProblem in docstrings [usually a missing r value before the quotes]: verbose   listdisplay)rX   rY   rV   rR   runTestonlyDocTestzUnit Test Method: testxtestzRunning Named Test Method: z"Could not find named test method: z, running all tests))boolgetr
   ELLIPSISNORMALIZE_WHITESPACEREPORT_ONLY_FIRST_FAILUREr/   argvunittest	TestSuiter   r   r   r   updater   stack	f_globalsDocTestSuiterJ   printrG   lower
isinstancestrdefaultTestLoadergetTestCaseNamesdirr1   setUpr   loadTestsFromTestCaseaddTestsrX   f_localsvaluesr#   r:   TextTestRunner	verbosityrun)testClasseskeywordsrunAllTestsrP   r	   r   skipDoctests1diverw   displayNamesrunThisTestargttNametObjnames2stacksouterFrameTuple
outerFramer   localVariablesrunnerunused_testResults                             r"   mainTestr      s   < K HLLT23H**+//0 	 **+ 	
 E{"chh&chh&HLLe45 ! +#sxx/%5u=>$"2//446 %$3+sxx7HLL)=uEF W]]_Q/2<<=	&%%'B I[ CHH$HLLE23	L#((CHH$HLLE23HLL/0K
388}hhqk!AA((1+KHLLE*+ll9e4 	!+HLL67!S!%77HHKE.ug67 L&sID

(9(9(;;"jjlv8I8I8K/KL"jjlw9J9J9L/LM&* & 4-7}EFJJL.GD+.0"'K>{mK^_` ++AA!DBKKO3 8 v;?$QiO$QiO$Q'
'*j1188:;r>=%UB((*$"JJrN O  	&YZ\Y]^_##%B	&s   S5 5	T+>"T&&T+rU   )r6   zdoctest._DocTestSuitereturnNone)r<   )r   rm   )r*   )__doc__
__future__r   r
   r   r-   rer/   rd   music21.common.stringToolsr   r   r   r`   ra   r#   r:   compiler<   r2   r4   r   __name__ r$   r"   <module>r      s   
 #    	 
  I *.!&&//!(!=!= >1hP0 "**%
&00D^+B zJ r$   