Skip to content

Commit

Permalink
Add recursive glob test
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaul committed Mar 12, 2019
1 parent 0838a29 commit 6bd5672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dask/bytes/tests/test_local.py
Expand Up @@ -31,7 +31,9 @@
csv_files = {'.test.fakedata.1.csv': (b'a,b\n'
b'1,2\n'),
'.test.fakedata.2.csv': (b'a,b\n'
b'3,4\n')}
b'3,4\n'),
'subdir/.test.fakedata.2.csv': (b'a,b\n'
b'5,6\n')}


try:
Expand Down Expand Up @@ -101,6 +103,15 @@ def test_urlpath_expand_read():
assert len(paths) == 2


@pytest.mark.skipif(sys.version_info < (3, 5),
reason="Recursive glob is new in Python 3.5")
def test_recursive_glob_expand():
"""Make sure * is expanded in file paths when reading."""
with filetexts(csv_files, mode='b'):
_, _, paths = get_fs_token_paths('**/.*.csv')
assert len(paths) == 3


def test_urlpath_expand_write():
"""Make sure * is expanded in file paths when writing."""
_, _, paths = get_fs_token_paths('prefix-*.csv', mode='wb', num=2)
Expand Down
5 changes: 5 additions & 0 deletions dask/utils.py
Expand Up @@ -196,6 +196,11 @@ def filetexts(d, open=open, mode='t', use_tmpdir=True):
"""
with (tmp_cwd() if use_tmpdir else noop_context()):
for filename, text in d.items():
dirname = os.path.dirname(filename)
try:
os.makedirs(dirname)
except OSError:
pass
f = open(filename, 'w' + mode)
try:
f.write(text)
Expand Down

0 comments on commit 6bd5672

Please sign in to comment.