B _1@sldZddlmZddlZddlZddlZddlZddlZddlm Z ej ddkrVe Z Gdddej ZdS)z, This script tests ``GitWildMatchPattern``. )unicode_literalsN)GitWildMatchPatternc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zeejd.d/kd0d1d2Zeejd.d3kd4d5d6Zeejd.d/kd0d7d8Z eejd.d3kd4d9d:Z!d;d<Z"d=d>Z#d?S)@GitWildMatchTestzU The ``GitWildMatchTest`` class tests the ``GitWildMatchPattern`` implementation. cCs&td\}}||||dS)z Tests an empty pattern. N)rpattern_to_regex assertIsNone)selfregexincluder D/tmp/pip-unpacked-wheel-sh474h94/pathspec/tests/test_gitwildmatch.py test_00_emptys zGitWildMatchTest.test_00_emptycCs\td\}}||||dtt||}t|dddg}||ddhdS)z Tests an absolute path pattern. This should match: an/absolute/file/path an/absolute/file/path/foo This should NOT match: foo/an/absolute/file/path z/an/absolute/file/pathz^an/absolute/file/path(?:/.*)?$zan/absolute/file/pathzan/absolute/file/path/foozfoo/an/absolute/file/pathN)rr assertTrue assertEqualrecompilesetmatch)r r r patternresultsr r r test_01_absolute!s    z!GitWildMatchTest.test_01_absolutecCs&td\}}||||dS)z~ Tests a single root absolute path pattern. This should NOT match any file (according to git check-ignore (v2.4.1)). /N)rrr)r r r r r r test_01_absolute_root=s z&GitWildMatchTest.test_01_absolute_rootcCsftd\}}||||dtt||}t|dddddg}||dddddhdS)zt Tests a relative path pattern. This should match: spam spam/ foo/spam spam/foo foo/spam/bar Zspamz^(?:.+/)?spam(?:/.*)?$zspam/zfoo/spamzspam/fooz foo/spam/barN)rrrrrrrr)r r r rrr r r test_01_relativeHs    z!GitWildMatchTest.test_01_relativecCs\td\}}||||dtt||}t|dddg}||ddhdS)z Tests a relative nested path pattern. This should match: foo/spam foo/spam/bar This should **not** match (according to git check-ignore (v2.4.1)): bar/foo/spam zfoo/spamz^foo/spam(?:/.*)?$z foo/spam/barz bar/foo/spamN)rrrrrrrr)r r r rrr r r test_01_relative_nestedhs    z(GitWildMatchTest.test_01_relative_nestedcCs&td\}}||||dS)z Tests a comment pattern. z# Cork soakers.N)rrr)r r r r r r test_02_comments z GitWildMatchTest.test_02_commentcCs`td\}}||||||dtt||}t|dg}||tdS)zo Tests an exclude pattern. This should NOT match (according to git check-ignore (v2.4.1)): temp/foo z!tempz^(?:.+/)?temp$ztemp/fooN) rrZassertIsNotNoneZ assertFalserrrrr)r r r rrr r r test_02_ignores   zGitWildMatchTest.test_02_ignorecCsXtd\}}||||dtt||}t|ddg}||dhdS)z Tests a directory name with a double-asterisk child directory. This should match: spam/bar This should **not** match (according to git check-ignore (v2.4.1)): foo/spam/bar zspam/**z ^spam/.*$zspam/barz foo/spam/barN)rrrrrrrr)r r r rrr r r test_03_child_double_asterisks    z.GitWildMatchTest.test_03_child_double_asteriskcCs`td\}}||||dtt||}t|ddddg}||dddhdS)z Tests a path with an inner double-asterisk directory. This should match: left/bar/right left/foo/bar/right left/bar/right/foo This should **not** match (according to git check-ignore (v2.4.1)): foo/left/bar/right z left/**/rightz^left(?:/.+)?/right(?:/.*)?$zleft/bar/rightzleft/foo/bar/rightzleft/bar/right/foozfoo/left/bar/rightN)rrrrrrrr)r r r rrr r r test_03_inner_double_asterisks   z.GitWildMatchTest.test_03_inner_double_asteriskcCs(td\}}||||ddS)z? Tests a double-asterisk pattern which matches everything. z**z^.+$N)rrrr)r r r r r r test_03_only_double_asterisks z-GitWildMatchTest.test_03_only_double_asteriskcCsZtd\}}||||dtt||}t|ddg}||ddhdS)zs Tests a file name with a double-asterisk parent directory. This should match: foo/spam foo/spam/bar z**/spamz^(?:.+/)?spam(?:/.*)?$zfoo/spamz foo/spam/barN)rrrrrrrr)r r r rrr r r test_03_parent_double_asterisks    z/GitWildMatchTest.test_03_parent_double_asteriskcCsftd\}}||||dtt||}t|dddddg}||dddddhdS) z Tests a pattern with an infix wildcard. This should match: foo--bar foo-hello-bar a/foo-hello-bar foo-hello-bar/b a/foo-hello-bar/b z foo-*-barz!^(?:.+/)?foo\-[^/]*\-bar(?:/.*)?$zfoo--barz foo-hello-barza/foo-hello-barzfoo-hello-bar/bza/foo-hello-bar/bN)rrrrrrrr)r r r rrr r r test_04_infix_wildcards    z'GitWildMatchTest.test_04_infix_wildcardcCsftd\}}||||dtt||}t|dddddg}||dddddhdS) z Tests a pattern with a postfix wildcard. This should match: ~temp- ~temp-foo ~temp-foo/bar foo/~temp-bar foo/~temp-bar/baz z~temp-*z^(?:.+/)?\~temp\-[^/]*(?:/.*)?$z~temp-z ~temp-fooz ~temp-foo/barz foo/~temp-barzfoo/~temp-bar/bazN)rrrrrrrr)r r r rrr r r test_04_postfix_wildcards    z)GitWildMatchTest.test_04_postfix_wildcardcCsbtd\}}||||dtt||}t|ddddg}||ddddhdS)zy Tests a pattern with a prefix wildcard. This should match: bar.py bar.py/ foo/bar.py foo/bar.py/baz z*.pyz^(?:.+/)?[^/]*\.py(?:/.*)?$zbar.pyzbar.py/z foo/bar.pyzfoo/bar.py/bazN)rrrrrrrr)r r r rrr r r test_04_prefix_wildcard3s    z(GitWildMatchTest.test_04_prefix_wildcardcCs`td\}}||||dtt||}t|ddddg}||dddhdS)z Tests a directory pattern. This should match: dir/ foo/dir/ foo/dir/bar This should **not** match: dir zdir/z^(?:.+/)?dir/.*$zfoo/dir/z foo/dir/bardirN)rrrrrrrr)r r r rrr r r test_05_directoryPs   z"GitWildMatchTest.test_05_directorycCs|tjdtdS)z+ Tests that the pattern is registered. gitwildmatchN)assertIspathspecutillookup_patternr)r r r r test_06_registeredosz#GitWildMatchTest.test_06_registeredcCs&|ttd|ttjtdS)z] Tests that the pattern is accessible from the root module using the deprecated alias. GitIgnorePatternN)rhasattrr) issubclassr-r)r r r r test_06_access_deprecatedusz*GitWildMatchTest.test_06_access_deprecatedcCs|tjdtjdS)zF Tests that the pattern is registered under the deprecated alias. Z gitignoreN)r(r)r*r+r-)r r r r test_06_registered_deprecated}sz.GitWildMatchTest.test_06_registered_deprecatedcCs6dtttddtjjj}d}| ||dS)z Test encoding bytes. rrs  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~N) joinmapunichrrangeencoder)patternsr'_BYTES_ENCODINGr)r encodedexpectedr r r test_07_encode_bytess"z%GitWildMatchTest.test_07_encode_bytescCs2tttddtjjj}d}|||dS)z Test decoding bytes. rr2u  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿN) bytes bytearrayr6decoder)r8r'r9r)r decodedr;r r r test_07_decode_bytessz%GitWildMatchTest.test_07_decode_bytescCs*td}t|dg}||dhdS)z; Test byte string patterns matching byte string paths. s*.pysa.pyN)rrrr)r rrr r r test_07_match_bytes_and_bytessz.GitWildMatchTest.test_07_match_bytes_and_bytescs\tttdddfddttD}t|}t|g}||hdS)z; Test byte string patterns matching byte string paths. rr2c3s"|]}d||dVqdS)\Nr ).0i)r:r r szJGitWildMatchTest.test_07_match_bytes_and_bytes_complete..N) r=r>r6r3lenrrrr)r escapedrrr )r:r &test_07_match_bytes_and_bytes_completes  z7GitWildMatchTest.test_07_match_bytes_and_bytes_completerrzPython 3 is strictcCs*td}t|dg}||dhdS)z; Test byte string patterns matching byte string paths. s*.pyza.pyN)rrrr)r rrr r r test_07_match_bytes_and_unicodesz0GitWildMatchTest.test_07_match_bytes_and_unicodezPython 2 is lenientc Cs8td}|tx|dgD]}q"WWdQRXdS)z; Test byte string patterns matching byte string paths. s*.pyza.pyN)r assertRaises TypeErrorr)r r_r r r $test_07_match_bytes_and_unicode_fails z5GitWildMatchTest.test_07_match_bytes_and_unicode_failcCs*td}t|dg}||dhdS)z, Test unicode patterns with byte paths. z*.pysa.pyN)rrrr)r rrr r r test_07_match_unicode_and_bytessz0GitWildMatchTest.test_07_match_unicode_and_bytesc Cs8td}|tx|dgD]}q"WWdQRXdS)z, Test unicode patterns with byte paths. z*.pysa.pyN)rrNrOr)r rrPr r r $test_07_match_unicode_and_bytes_fails z5GitWildMatchTest.test_07_match_unicode_and_bytes_failcCs*td}t|dg}||dhdS)z/ Test unicode patterns with unicode paths. z*.pyza.pyN)rrrr)r rrr r r !test_07_match_unicode_and_unicodesz2GitWildMatchTest.test_07_match_unicode_and_unicodecCs"d}d}t|}|||dS)z1 Test escaping a string with meta-characters zfile!with*weird#naming_[1].t?tz$file\!with\*weird\#naming_\[1\].t\?tN)rescaper)r fnamerJresultr r r test_08_escapes zGitWildMatchTest.test_08_escapeN)$__name__ __module__ __qualname____doc__rrrrrrrrrr r!r"r#r$r&r,r0r1r<rArBrKunittestZskipIfsys version_inforLrQrRrSrTrXr r r r rs:         r)r\ __future__rrr^r]Zpathspec.patterns.gitwildmatchr)Z pathspec.utilrr_chrr5ZTestCaserr r r r s