mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
commit
230f77b2bc
3 changed files with 34 additions and 2 deletions
14
news/iglob.rst
Normal file
14
news/iglob.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Made an exceptional case in ``iglobpath()`` more robust when Python globbing
|
||||
fails for due to strange scrandir issue.
|
||||
|
||||
**Security:** None
|
|
@ -27,7 +27,7 @@ from xonsh.tools import (
|
|||
pathsep_to_upper_seq, seq_to_upper_pathsep, expandvars, is_int_as_str, is_slice_as_str,
|
||||
ensure_timestamp, get_portions, is_balanced, subexpr_before_unbalanced,
|
||||
swap_values, get_logical_line, replace_logical_line, check_quotes, deprecated,
|
||||
is_writable_file, balanced_parens)
|
||||
is_writable_file, balanced_parens, iglobpath)
|
||||
from xonsh.environ import Env
|
||||
|
||||
from tools import skip_if_on_windows, skip_if_on_unix
|
||||
|
@ -1360,3 +1360,17 @@ def test_deprecated_past_expiry_raises_assertion_error(expired_version):
|
|||
|
||||
with pytest.raises(AssertionError):
|
||||
my_function()
|
||||
|
||||
|
||||
def test_iglobpath_empty_str(monkeypatch, xonsh_builtins):
|
||||
# makes sure that iglobpath works, even when os.scandir() and os.listdir()
|
||||
# fail to return valid results, like an empty filename
|
||||
def mockscandir(path):
|
||||
yield ''
|
||||
if hasattr(os, 'scandir'):
|
||||
monkeypatch.setattr(os, 'scandir', mockscandir)
|
||||
def mocklistdir(path):
|
||||
return ['']
|
||||
monkeypatch.setattr(os, 'listdir', mocklistdir)
|
||||
paths = list(iglobpath('some/path'))
|
||||
assert len(paths) == 0
|
||||
|
|
|
@ -1888,7 +1888,11 @@ def _iglobpath(s, ignore_case=False, sort_result=None):
|
|||
|
||||
def iglobpath(s, ignore_case=False, sort_result=None):
|
||||
"""Simple wrapper around iglob that also expands home and env vars."""
|
||||
return _iglobpath(s, ignore_case=ignore_case, sort_result=sort_result)[0]
|
||||
try:
|
||||
return _iglobpath(s, ignore_case=ignore_case, sort_result=sort_result)[0]
|
||||
except IndexError:
|
||||
# something went wrong in the actual iglob() call
|
||||
return iter(())
|
||||
|
||||
|
||||
def ensure_timestamp(t, datetime_format=None):
|
||||
|
|
Loading…
Add table
Reference in a new issue