a 5êdg ã@sFddlmZddlZddlZddlZddlmZGdd„dejƒZdS)é)ÚchainN)Úassert_python_okc@s”eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#S)$ÚTestTopologicalSortcCsTdd„}t |¡}| t||ƒƒt|ƒ¡t |¡}| t| ¡ƒtt|Žƒ¡dS)Ncss8| ¡| ¡r4| ¡}|D]}| |¡q|VqdS©N)ÚprepareÚ is_activeÚ get_readyÚdone)ÚtsÚnodesÚnode©r ú./usr/local/lib/python3.9/test/test_graphlib.pyÚstatic_order_with_groups s  zATestTopologicalSort._test_graph..static_order_with_groups)ÚgraphlibÚTopologicalSorterÚ assertEqualÚlistÚ static_orderr)ÚselfÚgraphZexpectedrr r r rÚ _test_graph s   zTestTopologicalSort._test_graphc Cs˜t ¡}| ¡D]\}}|j|g|¢RŽqz | ¡WnXtjy}z>|j\}}| d t t |ƒ¡d t t |dƒ¡¡WYd}~n d}~00‚dS)Nú é) rrÚitemsÚaddrZ CycleErrorÚargsZassertInÚjoinÚmapÚstr) rrÚcycler r Ú dependsonÚeÚmsgÚseqr r rÚ _assert_cycles  >z!TestTopologicalSort._assert_cyclec Cs(| dhddhddhddhddhdœgd¢¡| diid g¡| d d „td ƒDƒd d„td ddƒDƒ¡| dhdhdhdhdhdhdhdhdœgd¢¡| ddgdgddgdgdgdgdgdgdggdœ gd¢¡| ddggdggdœgd¢¡| ddggdggdgdggdœgd¢¡dS) Né éééé)ré é r&r'))r(r*r))r&r')rr,r+é©r-cSsi|]}||dh“qSr.r ©Ú.0Úxr r rÚ -óz9TestTopologicalSort.test_simple_cases..r,cSsg|] }|f‘qSr r r/r r rÚ -r3z9TestTopologicalSort.test_simple_cases..éÿÿÿÿéé é éé)rr(r6r*r&r7r8r9))r-r:)r*r9)r6r8)r(r7)rr&rér+) rr-rr(r6r*r;r)r'r+))r+)r6)r(r')r-r*r))r;©r©r)rr-rr())r-r(r<r=)rr-rr(r6r*r;))r-r(r;)rr*)rr6)rÚrange©rr r rÚtest_simple_cases$s> þ$ÿ$þö ó þz%TestTopologicalSort.test_simple_casescCs>| dhdhdhdœddg¡| tƒtƒtƒdœdg¡dS)Nrr6r;)r-r(r*)rr6r;)rÚsetr?r r rÚtest_no_dependenciesLsz(TestTopologicalSort.test_no_dependenciescCsh| dhdhgd¢dœddg¡t ¡}| dd¡| dd¡| dd¡| g| ¡¢ddg¡dS)Nrr6)rr6r6r6r6r6)r-r(r)rr6r-)rrrrrr©rr r r rÚtest_the_node_multiple_timesQs     z0TestTopologicalSort.test_the_node_multiple_timescCs<dd„tdƒDƒ}t d|i¡}| t| ¡ƒgd¢¡dS)Ncss|]}d|dVqdS)rr-Nr r/r r rÚ ]r3z@TestTopologicalSort.test_graph_with_iterables..r*r)r-r(r*r)r+r)r>rrrrr)rr!r r r rÚtest_graph_with_iterables\sz-TestTopologicalSort.test_graph_with_iterablescCsjt ¡}| dd¡| dd¡| dd¡| dd¡t dhd£i¡}| g| ¡¢g| ¡¢¡dS)Nr-rr(r6r*>rr(r6r*)rrrrr)rr Úts2r r rÚ1test_add_dependencies_for_same_node_incrementallyas    zETestTopologicalSort.test_add_dependencies_for_same_node_incrementallycCs| ig¡dSr)rr?r r rÚ test_emptylszTestTopologicalSort.test_emptyc CsÆ| ddhiddg¡| dhdhdœgd¢¡| dhdhdhdœgd¢¡| dhdhdhdhd hd œgd¢¡| dhdhdhd hd hd hd œgd¢¡| dhdhddhd hdœddg¡dS)Nr-r)r-r)r-rr-r()r-rr()r-r(rr-r6r;)r-rr(r*r6r*r))r-rr(r6r;r))r-rr(r6)r%r?r r rÚ test_cycleos &*zTestTopologicalSort.test_cyclecCsªt ¡}| td¡| ¡Wdƒn1s20Y| td¡| d¡Wdƒn1sh0Y| td¡| ¡Wdƒn1sœ0YdS)Nz prepare\(\) must be called firstr()rrÚassertRaisesRegexÚ ValueErrorrr rrCr r rÚtest_calls_before_prepare}s&(z-TestTopologicalSort.test_calls_before_preparecCsHt ¡}| ¡| td¡| ¡Wdƒn1s:0YdS)Nz!cannot prepare\(\) more than once)rrrrKrLrCr r rÚtest_prepare_multiple_times‡sz/TestTopologicalSort.test_prepare_multiple_timescCs¦t ¡}| dddd¡| ddd¡| ¡| ¡| td¡| d¡Wdƒn1sb0Y| td¡| d¡Wdƒn1s˜0YdS)Nr-rr(r6znode 2 was not passed outz#node 24 was not added using add\(\)é)rrrrrrKrLr rCr r rÚtest_invalid_nodes_in_dones(z.TestTopologicalSort.test_invalid_nodes_in_donecCsÖt ¡}| dddd¡| dd¡| ¡| | ¡d¡| | ¡d¡| d¡| | ¡d¡| | ¡d¡| d¡| d¡| | ¡d¡| | ¡d¡| d¡| | ¡d¡| | ¡¡dS) Nr-rr(r6)r(r6r r<r.) rrrrrrr Ú assertFalserrCr r rÚ test_done™s      zTestTopologicalSort.test_donecCsšt ¡}| dd¡| ¡| | ¡¡| | ¡d¡| | ¡¡| d¡| | ¡¡| | ¡d¡| | ¡¡| d¡|  | ¡¡dS)Nr-rr<r.) rrrrZ assertTruerrrr rQrCr r rÚtest_is_active¯s   z"TestTopologicalSort.test_is_activecCsJt ¡}| t|jtƒd¡| t|jdtƒ¡| t|jtƒtƒ¡dS)Nr-)rrZ assertRaisesÚ TypeErrorrÚdictrCr r rÚtest_not_hashable_nodes¾sz+TestTopologicalSort.test_not_hashable_nodescCs´dd„}t ¡}| ddd¡| dd¡| dd¡| d d ¡| dd ¡t ¡}| dd¡| ddd¡| dd ¡| d d ¡| dd¡| t||ƒƒt||ƒƒ¡dS) Ncss2| ¡| ¡r.| ¡}|j|Žt|ƒVqdSr)rrrr rA)r r r r rÚ get_groupsÅs  z^TestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups..get_groupsr(rr-rr6r*r;r))rrrrr)rrWr rGr r rÚ6test_order_of_insertion_does_not_matter_between_groupsÄs        zJTestTopologicalSort.test_order_of_insertion_does_not_matter_between_groupscCs@dd„}|dƒ}|dƒ}| |d¡| |d¡| ||¡dS)NcSs8d}tj ¡}d|d<t|ƒ|d<td|fi|¤Ž}|S)Naxif 1: import graphlib ts = graphlib.TopologicalSorter() ts.add('blech', 'bluch', 'hola') ts.add('abcd', 'blech', 'bluch', 'a', 'b') ts.add('a', 'a string', 'something', 'b') ts.add('bluch', 'hola', 'abcde', 'a', 'b') print(list(ts.static_order())) TZ __cleanenvZPYTHONHASHSEEDz-c)ÚosÚenvironÚcopyrr)ÚseedÚcodeÚenvÚoutr r rÚcheck_order_with_hash_seedÝs   zlTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed..check_order_with_hash_seediÒi·zÚ)ZassertNotEqualr)rr`Zrun1Zrun2r r rÚ4test_static_order_does_not_change_with_the_hash_seedÜs   zHTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seedN)Ú__name__Ú __module__Ú __qualname__rr%r@rBrDrFrHrIrJrMrNrPrRrSrVrXrbr r r rrs" (    r) Ú itertoolsrrrYZunittestZtest.support.script_helperrZTestCaserr r r rÚs