Move globlist and its test under utils.path · mskobe/ipython@a7c450c · GitHub
Skip to content

Commit a7c450c

Browse files
committed
Move globlist and its test under utils.path
1 parent afb25d0 commit a7c450c

4 files changed

Lines changed: 48 additions & 47 deletions

File tree

IPython/core/magics/execution.py

Lines changed: 1 addition & 15 deletions

IPython/core/tests/test_magic.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def invalidate_caches():
2929
register_line_magic, register_cell_magic,
3030
register_line_cell_magic)
3131
from IPython.core.magics import execution, script
32-
from IPython.core.magics.execution import globlist
3332
from IPython.nbformat.v3.tests.nbexamples import nb0
3433
from IPython.nbformat import current
3534
from IPython.testing import decorators as dec
@@ -87,37 +86,6 @@ def test_magic_parse_long_options():
8786
nt.assert_true(opts['bar'], "bubble")
8887

8988

90-
def test_globlist():
91-
"""Test glob expansion for %run magic."""
92-
filenames_start_with_a = map('a{0}'.format, range(3))
93-
filenames_end_with_b = map('{0}b'.format, range(3))
94-
filenames = filenames_start_with_a + filenames_end_with_b
95-
96-
with TemporaryDirectory() as td:
97-
save = os.getcwdu()
98-
try:
99-
os.chdir(td)
100-
101-
# Create empty files
102-
for fname in filenames:
103-
open(os.path.join(td, fname), 'w').close()
104-
105-
def assert_match(patterns, matches):
106-
# glob returns unordered list. that's why sorted is required.
107-
nt.assert_equals(sorted(globlist(patterns)), sorted(matches))
108-
109-
assert_match(['*'], filenames)
110-
assert_match(['a*'], filenames_start_with_a)
111-
assert_match(['*c'], ['*c'])
112-
assert_match(['*', 'a*', '*b', '*c'],
113-
filenames
114-
+ filenames_start_with_a
115-
+ filenames_end_with_b
116-
+ ['*c'])
117-
finally:
118-
os.chdir(save)
119-
120-
12189
@dec.skip_without('sqlite3')
12290
def doctest_hist_f():
12391
"""Test %hist -f with temporary filename.

IPython/utils/path.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import tempfile
2020
import warnings
2121
from hashlib import md5
22+
from glob import glob
2223

2324
import IPython
2425
from IPython.testing.skipdoctest import skip_doctest
@@ -355,6 +356,19 @@ def expand_path(s):
355356
return s
356357

357358

359+
def globlist(args):
360+
"""
361+
Do glob expansion for each element in `args` and return a flattened list.
362+
363+
Unmatched glob pattern will remain as-is in the returned list.
364+
365+
"""
366+
expanded = []
367+
for a in args:
368+
expanded.extend(glob(a) or [a])
369+
return expanded
370+
371+
358372
def target_outdated(target,deps):
359373
"""Determine whether a target is out of date.
360374

IPython/utils/tests/test_path.py

Lines changed: 33 additions & 0 deletions

0 commit comments

Comments
 (0)