
    rh-                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
Jr  S/rSS\R                  \R                  -  4S jrSS jr\R"                  " S	5      rSSS
 jjrSSS jjrS r\S:X  a  \" 5         gg)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           	        [         R                  " 5       nUSL a+  [        [        S   5      R                  R                  5       nOUc  0 nU H  n[        R                  " U5      (       d  M   [        USS5      nUc  M2  U HS  nXx   n	UR                  XXS5      n
U
R                  (       d  M-  [         R                  " U
US9nU R                  U5        MU     M     g)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 ()
Fr   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               Q/home/james-whalen/.local/lib/python3.13/site-packages/music21/test/testRunner.pyaddDocAttrTestsToSuiter#   #   s    4 


!C~>!,-66;;=	"$$#{D1?F#OMvaPB;;%%b2=(C MM#  #    c                   [         R                  " 5       S:H  n[        R                  S   S:  nU  H  n[	        US5      (       d  M  UR
                  nUR                   Hj  n[        UR                  S5      Ul        U(       a  [        UR                  S5      Ul        U(       d  MI  UR                  R                  SS5      Ul        Ml     M     g	)
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:   W   s     OO%2G""1%+KsJ''\\{{G)',,@GL0uEw&||33KO # r$   z0x[0-9A-Fa-f]+c                ,    [         R                  X5      $ )a  
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   r   s    * ;;{//r$   c           	     N   SU ;  a  U $  [        U SSS9n/ nSnU HR  nUR                  XUR                  [        S5      -
   5        UR                  SU-   S-   5        UR                  S-   nMT     UR                  XS 5        S	R                  U5      $ ! [         a    Us $ f = f)
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.10/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JJzqww5E1F'FGHJJ4t;<5519D  	

:e$%wws| s   B
B B$#B$c                 L   Sn[        UR                  SS5      5      nU(       a3  [        R                  [        R                  -  [        R
                  -  nO![        R                  [        R                  -  nSnSU ;   dH  S[        R                  ;   d4  S[        R                  ;   d   [        UR                  SS5      5      (       a  SnOSnU(       a  [        R                  " 5       nOSU ;   d4  S[        R                  ;   d   [        UR                  SS5      5      (       a  O[         H&  n[        U5      R                  R                  5       nM(     SU ;   d4  S[        R                  ;   d   [        UR                  SS5      5      (       a4  UR                  [        R                   " 5       S	   S
   R"                  5         [        R$                  " SUUS9nS	n
SU ;   d4  S[        R                  ;   d   [        UR                  SS5      5      (       a  Sn
SnS[        R                  ;   dT  S[        R                  ;   d@  [        UR                  SS5      5      (       d   [        UR                  SS5      5      (       a  SnSnSn[+        [        R                  5      S:X  a:  [        R                  S	   R-                  5       nUS;  a  [        R                  S	   n[        UR                  SS5      5      (       a  UR                  SS5      nS[        R                  ;   d&  SU ;   d   [        UR                  SS5      5      (       a  / n U  GHc  n[/        U[0        5      (       a  M  USL a4  [        R2                  R5                  U5       H  n[)        SU 35        M     Ub  U" 5       n[7        U5       Hs  nUR-                  5       UR-                  5       :X  dL  UR-                  5       SUR-                  5       -   :X  d'  UR-                  5       SUR-                  5       -   :X  d  Mq  Un  O   [9        UU5      (       a3  [)        SU 35        UR;                  5         [=        UU5      " 5         Sn  OD[)        SU S35        [        R2                  R?                  U5      nURA                  U5        GMf     U(       dj  [        R                   " 5       n[+        U5      S	:  a  US	   nOUS
   nUS
   nUS	   n[C        URD                  RG                  5       5      n[I        UUUXT5        USL a9  [K        U5        [        RL                  " 5       nU
Ul'        URQ                  U5      ngg! [&         a1  n	[)        SSU	 3-   5        [        R                  " 5       n Sn	A	GNSn	A	ff = f)a%  
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	   z8Problem in docstrings [usually a missing r value before z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5 ! +#sxx/%5u=>>$"2//446 %$3+sxx7HLL)=uEFFW]]_Q/2<<=		&%%'B I[ CHH$HLLE233	L#((CHH$HLLE233HLL/00K
388}hhqk!AA((1+KHLLE*++ll9e4 	!+HLL677!S!!t#%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D+.0"'K>{mK^_` ++AA!DBKKO3 8 v;?$QiO$QiO$Q'
'*j1188:;r>=%UdB((*$"JJrN Q  	&L#B4() *##%B	&s   U( (
V#2&VV#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$   