From 6bd567243abe9cb1d09b19926baa502f51ff4535 Mon Sep 17 00:00:00 2001 From: Brett Naul Date: Tue, 12 Mar 2019 09:58:42 -0700 Subject: [PATCH] Add recursive glob test --- dask/bytes/tests/test_local.py | 13 ++++++++++++- dask/utils.py | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dask/bytes/tests/test_local.py b/dask/bytes/tests/test_local.py index c74303552688..6ee1f389cb99 100644 --- a/dask/bytes/tests/test_local.py +++ b/dask/bytes/tests/test_local.py @@ -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: @@ -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) diff --git a/dask/utils.py b/dask/utils.py index 73aff6372e66..6afc7171b9b9 100644 --- a/dask/utils.py +++ b/dask/utils.py @@ -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)