
    rhQB                    b   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	r	SSK
r
SSKrSSKrSSKJr  SSKrSSKrSSKJr  SSKJr  \R&                  " S5      rSS jrSS	 jrS
 rSS jr " S S\R2                  R4                  5      r " S S5      r\S:X  a  \R<                  " 5         gg)z$
Things that are common to testing.
    )annotationsN)registerResult)environment)commonztest.commonTestc                   U R                   R                  nUR                  5        H  u  p4SnS H3  nUR                  U5      (       d  UR	                  U5      (       d  M1  SnM5     U(       a  MI  [        U5      (       a  [        U[        R                  5      (       a  Mz  [        US5      (       a  UR                  U:w  a  M   U" 5       n [        R                  " U5         [        R                  " U5        M     g ! [         a     M  f = f! [         a!  nU R                  SU SU 35         S nANSS nAff = f! [         a#  nU R                  SU SU 35         S nAGM?  S nAff = f)NF)_Test	ExceptionT
__module__zCould not copy obj z: zCould not deepcopy obj )	__class__r   items
startswithendswithcallable
isinstancetypesFunctionTypehasattr	TypeErrorcopyr
   faildeepcopy)	testInstanceglobals_	my_modulepartobjmatchskipinstancees	            Q/home/james-whalen/.local/lib/python3.13/site-packages/music21/test/commonTest.pytestCopyAllr#   $   s@   &&11I^^%	.Dt$$d(;(; / }}
30B0B C CsL))S^^y-H	uH	AIIh	EMM(#/ &  		
  	A 3D6A3?@@	A  	E 7vRsCDD	EsB   C?D$D>?
DD
D;D66D;>
E+E&&E+c                   [         R                  R                  X5      nUb  UR                  c  [	        SU< 35      eU [
        R                  ;   a  [
        R                  U    nOD[         R                  R                  U5      nUc  [	        SU< 35      eU[
        R                  U '   UR                  R                  U5        U$ )z
Replacement for deprecated imp.load_source()

Thanks to:
https://github.com/epfl-scitas/spack for pointing out the
important missing "spec.loader.exec_module(module)" line.
zNo such file or directory: )		importlibutilspec_from_file_locationloaderFileNotFoundErrorsysmodulesmodule_from_specexec_module)namepathspecmodules       r"   load_sourcer2   B   s     >>11$=D|t{{*"=dX FGGs{{T"006>#&A$$JKK"DKKF#M    c                      SSK n  SSKJn  SSKJnJn   U" 5         g! [         a  n[        S5      UeSnAff = f! [         a  n[        S5      UeSnAff = f! U a  n[        S5      UeSnAff = f)zF
Test that all optional packages needed for test suites are installed
r   Nz2pip install scipy : needed for running test suites)StringMatcherz?pip install python-Levenshtein : needed for running test suites)LilypondConverterLilyTranslateExceptionz-lilypond must be installed to run test suites)scipyImportErrorLevenshteinr5   music21.lily.translater6   r7   )r8   r!   r5   r6   r7   s        r"   testImportsr<   Y   s    
Wd- QR  WNOUVVW
  d[\bccd " RIJPQQRs<    < A 
949
AAAA1 A,,A1c                    [        S5      R                  R                  5       n[        R                  [        R
                  -  nUUS.nU b  [        R                  " U 40 UD6nU$ [        R                  " S0 UD6nU$ )Nmusic21)globsoptionflags )
__import____dict__r   doctestELLIPSISNORMALIZE_WHITESPACEDocTestSuite)r.   r?   docTestOptionskeywordss1s        r"   defaultDoctestSuiterK   n   s|    y!**//1E&&)E)EEN%H
 !!$3(3 I !!-H-Ir3   c                      \ rS rSrS rSrg)Music21TestRunner   c                V   U R                  5       n[        U5        U R                  Ul        U R                  Ul        [        R
                  " 5          [        U S5      (       a[  U R                  (       aJ  [        R                  " U R                  5        U R                  S;   a  [        R                  " S[        SS9  [        USS5      nUb  U" 5          U" U5        [        USS5      nUb  U" 5         SSS5        UR                  5         S	=n=pg [        [        UR                  UR                  UR                   45      nUu  pVn/ n	UR%                  5       (       d{  U R&                  R)                  S
5        [        UR*                  5      [        UR,                  5      pU
(       a  U	R/                  SU
 35        U(       a  U	R/                  SU 35        O U(       a  U	R/                  SU 35        U(       a  U	R/                  SU 35        U(       a  U	R/                  SU 35        U	(       a2  SR1                  U	5      nU R&                  R3                  SU S35        U$  U$ ! [        USS5      nUb  U" 5         f f = f! , (       d  f       GN= f! ["         a     GN\f = f)z(
Run the given test case or test suite.
warnings)defaultalwaysr1   zPlease use assert\w+ instead.)categorymessagestartTestRunNstopTestRunr   FAILEDz	failures=zerrors=zskipped=zexpected failures=zunexpected successes=z, z ())_makeResultr   failfastbufferrP   catch_warningsr   simplefilterfilterwarningsDeprecationWarninggetattrprintErrorsmaplenexpectedFailuresunexpectedSuccessesskippedAttributeErrorwasSuccessfulstreamwritefailureserrorsappendjoinwriteln)selftestresultrU   rV   expectedFailsre   rf   resultsinfosfailederroredjoineds                r"   runMusic21TestRunner.run   sU    !!#v--$$&tZ((T]]%%dmm4 ==$99++H5G4TV #6>4@L'"V%fmTB*M- '2 	8999+	B# 7 7 & : : & 0 1G ;B7M##%%KKh'!&//2C4FGy12wwi01LL8G9-.LL-m_=>LL01D0EFGYYu%FKK"VHA/  M &fmTB*M ++ '&@  		s7   BJI+ J1J +JJ
J
J('J(rA   N)__name__r   __qualname____firstlineno__ry   __static_attributes__rA   r3   r"   rM   rM      s    Br3   rM   c                  `    \ rS rSrSrSS jrS rS rS rSS.S	 jr	SS
 jr
SS jrSS jrSrg)ModuleGather   a   
Utility class for gathering and importing all modules in the music21
package. Puts them in self.modulePaths.

>>> from music21.test import commonTest
>>> mg = commonTest.ModuleGather(useExtended=True)
>>> #_DOCS_SHOW print(mg.modulePaths[0])
D:\Web\eclipse\music21base\music21\volume.py
Fc                   [        [        R                  " 5       5      U l        Xl        / U l        / SQU l        U R                  / SQ-   U l        / SQU l        / U l	        U R                  / -   U l
        U R                   Vs/ s H"  o3R                  S[        R                  5      PM$     snU l        U R                   Vs/ s H"  o3R                  S[        R                  5      PM$     snU l        U R                   Vs/ s H"  o3R                  S[        R                  5      PM$     snU l	        U R                   Vs/ s H"  o3R                  S[        R                  5      PM$     snU l
        U R                   Vs/ s H"  o3R                  S[        R                  5      PM$     snU l        U(       a  U R                  5         g g s  snf s  snf s  snf s  snf s  snf )N)ztestSingleCoreAll.pyztestExternal.pyztestDefault.pyztestInstallation.pyztestLint.pyztestPerformance.pyztimeGraphs.pyztimeGraphImportStar.pyzmultiprocessTest.pyzsetup.pyzfiguredBass/examples.py)zconfigure.pyztestSerialization.pyzmptCurses.pyzmemoryUsage.pyztest/treeYield.pyztest/toggleDebug.pyzmusicxml/testPrimitive.pyzmusicxml/testFiles.pyz)musedata/testPrimitive/test01/__init__.pyz"musedata/testPrimitive/__init__.pyzmei/test_base.pyzhumdrum/questions.pyzdocumentation/upload.pyzdocumentation/source/conf.pyzdocumentation/extensions.pyzcorpus/testCorpus.pyzaudioSearch/scoreFollower.pyzaudioSearch/repetitionGame.pyzabcFormat/testFiles.py)zmetadata/bundleszmetadata/cachingfeaturesgraphz
graph/plotz
graph/axiszgraph/primitives
freezeThawzfiguredBass/realizerzfeatures/jSymboliczfeatures/nativezfiguredBass/exampleszbraille/testzstream/testszanalysis/windowedzconverter/__init__zmusicxml/test_m21ToXmlzmusicxml/test_xmlToM21zromanText/translatezcorpus/testCorpuszcorpus/corporazaudioSearch/transcriberzaudioSearch/__init__z#alpha/theoryAnalysis/theoryAnalyzer/)strr   getSourceFilePath	dirParentuseExtendedmodulePaths
moduleSkipmoduleSkipExtendedslowModulespathSkippathSkipExtendedreplaceossepwalk)rp   r   autoWalkxs       r"   __init__ModuleGather.__init__   sa   V5578&
" #'// 5
 #
6:  $ 2;???K?a99S"&&1?KCGCZCZ"[CZa99S"&&#9CZ"[9=GA3/GAEAVAV WAVA3!7AV W<@<L<LM<LqIIc2662<LM IIK  L"[G WMs   )G)G )G?)G>)Gc                   U H{  nUR                  S5      (       d  M  [        R                  R                  X$5      n[        R                  R	                  U5      (       a  M`  U R
                  R                  U5        M}     g)zb
append all module paths from _walk() to self.modulePaths.
Utility function called from os.walk()
pyN)r   r   r/   rn   isdirr   rm   )rp   argsdirnamenamesfileNamefps         r"   
_visitFuncModuleGather._visitFunc.  sX    
 H  &&WW\\'4ww}}R(($$++B/	 r3   c                X  ^  U 4S jn[         R                  " T R                  5       H  u  p#nT R                  SX$5        M     [        R
                  " 5       S:  a  T R                  R                  US9  OT R                  R                  5         T R                  R                  5         g)zH
Get all the modules in reverse order, storing them in self.modulePaths
c                   > U [        TR                  5      S-   S n U R                  SS5      n U TR                  ;   U 4$ )zm
for many core systems, like the MacPro, running slowest modules first
helps there be fewer idle cores later
   N.py )rc   r   r   r   )r.   rp   s    r"   manyCoreSortFunc+ModuleGather.walk.<locals>.manyCoreSortFunc=  sF    
 DNN+a/01D<<r*DD,,,d33r3   N   )key)	r   r   r   r   r   cpusr   sortreverse)rp   r   dirPathunused_dirNames	filenamess   `    r"   r   ModuleGather.walk9  s    	4 46774>>3J/GiOOD'5 4K ;;=1!!&6!7!!#
 	  "r3   c                   UR                  [        U R                  5      S5      nUR                  [        R
                  5      (       a  USS nUR                  [        R
                  S5      nUR                  SS5      nU$ )z
Given full file pathlib.Path, find a name for the module with _ as the separator.

>>> from music21.test import commonTest
>>> mg = commonTest.ModuleGather()
>>> #_DOCS_SHOW mg._getName(r'D:\Web\eclipse\music21base\music21\chord.py')
'chord'
r   r   Nr   r   )r   r   r   r   r   r   )rp   r   fns      r"   _getNameModuleGather._getNameT  sd     ZZDNN+R0==  ABBZZ$ZZr"	r3   addM21c               j   UR                  U R                  S5      nUR                  [        R                  5       Vs/ s H  oD(       d  M  UPM     nnUS   S:X  a  UR                  5         SR                  U5      nUR                  SS5      nU(       a  U(       a  SU-   nU$ U(       a  SnU$ s  snf )a  
Given full file path, find a name for the module with . as the separator.

>>> from music21.test import commonTest
>>> mg = commonTest.ModuleGather()
>>> name = '/Users/cuthbert/git/music21base/music21/features/native.py'
>>> #_DOCS_SHOW mg._getNamePeriod(name)
'features.native'
r   z__init__.py.r   zmusic21.r>   )r   r   splitr   r   poprn   )rp   r   r   r   r   partss         r"   _getNamePeriodModuleGather._getNamePeriodd  s     ZZ+HHRVV,2,q,29%IIKXXe_ZZr"bbB 	 B	 3s   
B0B0c                ~    / nU R                    H*  nU R                  X15      nUc  M  UR                  U5        M,     U$ )z
Return a list of module objects that are not in the skip list.

N.B. the list is a list of actual module objects not names,
therefore cannot be pickled.
)r   	getModulerm   )rp   restoreEnvironmentDefaultsr+   r   moduleObjects        r"   loadModuleGather.load|  s@     ""B>>"IL'|, # r3   c                   SnU R                   nU R                  (       a  U R                  nU H  nUR                  U5      (       d  M  Sn  O   U(       a  gU R                  nU R                  (       a  U R
                  nU H  nXq;   d  M
  Sn  O   U(       a  gU R                  USS9n [        R                  " 5          [        X5      n	SSS5        U(       a+  [        W	S	5      (       a  U	R                  R!                  5         W	$ ! , (       d  f       NB= f! [         a=  n
[        R                  SUSUSS[        U
5      R                  5       /5         Sn
A
gSn
A
ff = f)
z+
gets one module object from the file path
FTNr   zfailed import:	
z	EXCEPTION:environLocal)r   r   r   r   r   r   r   rP   r\   r2   r
   r   warnr   stripr   restoreDefaults)rp   r   r   r   msfnSkippsdirSkipr.   modexcps              r"   r   ModuleGather.getModule  s4    __((BF{{6""  ]]&&BG}  ""2e"4	((*!$+ + &sN++  002
 +* 	/tR-s4y/@B C	s6   +D  DD 
DD D 
E #3EE c                <   SnU R                    H  nUR                  U5      (       d  M  Sn  O   U(       a  gU R                   H0  n[        R                  U-   [        R                  -   nXa;   d  M.  Sn  O   U(       a  gU R                  U5      nUR                  S5      n[        n	U H  n
[        X5      (       a8  [        R                  X5      n	[        U	[        R                  5      (       d    gMK  SU
;   a[  U	R                  n[        R                   " SU
-   U5      n[#        XU5        [$        R'                  SU
< SU	< S	U< S
U< 35        Un	M    g   U	nU(       a+  [        US5      (       a  UR$                  R)                  5         [+        SU-   5        U$ )z=
gets one module object from the file path without using Imp
FTr   r   	notInTreerq   zImported thisName=z from currentModule=z, fp=z, packageName=r   z	starting )r   r   r   r   r   r   r   r>   r   object__getattribute__r   r   
ModuleTyper{   r%   import_modulesetattrr   
printDebugr   print)rp   r   r   r   r   r   dirSkipSlash
moduleNamemoduleNamescurrentModulethisNamepackageNamenewModr   s                 r"   getModuleWithoutImp ModuleGather.getModuleWithoutImp  s}    ooF{{6"" & }}G66G+bff4L!	 %
 ((,
 &&s+ $H}// & 7 7 P!-1A1ABB& C8#+44"00xM8''){*?0@2%+X !'" $  %sN++  002kJ&'
r3   )r   r   r   r   r   r   r   r   N)FT)F)r{   r   r|   r}   __doc__r   r   r   r   r   r   r   r   r~   rA   r3   r"   r   r      s7    Yv	0#6  ,1 0(T-r3   r   __main__)r   zunittest.TestCaser   ztyping.Dict[str, typing.Any])r.   r   r/   r   returnztypes.ModuleType)N)r   
__future__r   r   rD   r%   importlib.utilr   r*   typingr   unittestunittest.runnerunittest.signalsr   rP   r>   r   r   Environmentr   r#   r2   r<   rK   runnerTextTestRunnerrM   r   r{   mainTestrA   r3   r"   <module>r      s    #     	 
     +    &&'89E<.R*$C66 CPY Yx z r3   