Skip to content

Commit 4f1c0e9

Browse files
authored
Fix issue when matching a file in the CWD (#17)
* Fix issue when matching a file in the CWD * Is this causing bad coverage? * Ignore warnings in pytest * Update document typos
1 parent 44ff883 commit 4f1c0e9

File tree

8 files changed

+45
-7
lines changed

8 files changed

+45
-7
lines changed

docs/src/markdown/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.0.3
4+
5+
- **FIX**: In `glob`, properly handle files in the current working directory when give a literal pattern that matches it.
6+
37
## 2.0.2
48

59
- **FIX**: `wcmatch` override events (`on_error` and `on_skip`) should verify the return is **not None** and not **not falsy**.

docs/src/markdown/fnmatch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def translate(patterns, *, flags=0):
133133

134134
#### fnmatch.RAWCHARS, fnmatch.R {: #fnmatchrawchars}
135135

136-
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handled standard string escapes and Unicode including `#!py3 r'\N{CHAR NAME}'`.
136+
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handle standard string escapes and Unicode including `#!py3 r'\N{CHAR NAME}'`.
137137

138138
#### fnmatch.NEGATE, fnmatch.N {: #fnmatchnegate}
139139

docs/src/markdown/glob.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ True
252252

253253
#### glob.RAWCHARS, glob.R {: #globrawchars}
254254

255-
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handled standard string escapes and Unicode including `#!py3 r'\N{CHAR NAME}'`.
255+
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handle standard string escapes and Unicode including `#!py3 r'\N{CHAR NAME}'`.
256256

257257
#### glob.NEGATE, glob.N {: #globnegate}
258258

docs/src/markdown/wcmatch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ On match returns the path of the matched file. You can override `on_match` and
228228

229229
#### wcmatch.RAWCHARS, wcmatch.R {: #wcmatchrawchars}
230230

231-
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handled standard string escapes and Unicode (including `#!py3 r'\N{CHAR NAME}'`).
231+
`RAWCHARS` causes string character syntax to be parsed in raw strings: `#!py3 r'\u0040'` --> `#!py3 r'@'`. This will handle standard string escapes and Unicode (including `#!py3 r'\N{CHAR NAME}'`).
232232

233233
#### wcmatch.EXTMATCH, wcmatch.E {: #wcmatchextmatch}
234234

tests/test_glob.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,35 @@ def test_glob_cases(self, case):
755755
self.eval_glob_cases(case)
756756

757757

758+
class TestCWD(_TestGlob):
759+
"""Test files in the current working directory."""
760+
761+
@classmethod
762+
def setup_fs(cls):
763+
"""Setup filesystem."""
764+
765+
cls.mktemp('a', 'D')
766+
cls.mktemp('aab', 'F')
767+
cls.mktemp('.aa', 'G')
768+
cls.mktemp('.bb', 'H')
769+
cls.mktemp('aaa', 'zzzF')
770+
cls.mktemp('ZZZ')
771+
cls.mktemp('EF')
772+
cls.mktemp('a', 'bcd', 'EF')
773+
cls.mktemp('a', 'bcd', 'efg', 'ha')
774+
cls.can_symlink = can_symlink()
775+
if cls.can_symlink:
776+
os.symlink(cls.norm('broken'), cls.norm('sym1'))
777+
os.symlink('broken', cls.norm('sym2'))
778+
os.symlink(os.path.join('a', 'bcd'), cls.norm('sym3'))
779+
780+
def test_cwd(self):
781+
"""Test glob cases."""
782+
783+
with change_cwd(self.tempdir):
784+
self.assert_equal(glob.glob('EF'), ['EF'])
785+
786+
758787
class TestGlobCornerCase(_TestGlob):
759788
"""
760789
Some tests that need a very specific file set to test against for corner cases.

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ commands=
3030
[flake8]
3131
max-line-length=120
3232
ignore=D202,D203,D401,N802,N801,N803,N806,E741
33+
34+
[pytest]
35+
addopts=-p no:warnings

wcmatch/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Version."""
22

33
# (major, minor, micro, release type, pre-release build, post-release build)
4-
version_info = (2, 0, 2, 'final', 0, 0)
4+
version_info = (2, 0, 3, 'final', 0, 0)
55

66

77
def _version():

wcmatch/glob.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,11 @@ def glob(self):
361361
# on a case sensitive file system may return more than
362362
# one starting location.
363363
results = [curdir] if this.is_drive else self._get_starting_paths(curdir)
364-
if not results: # pragma: no cover
365-
# Nothing to do.
366-
# Do we need this?
364+
if not results:
365+
if not dir_only and os.path.lexists(curdir):
366+
# There is no directory with this name,
367+
# but we have a file and no directory restriction
368+
yield curdir
367369
return
368370

369371
if this.dir_only:

0 commit comments

Comments
 (0)