MCPcopy Create free account
hub / github.com/dask/dask / filetexts

Function filetexts

dask/utils.py:464–496  ·  view source on GitHub ↗

Dumps a number of textfiles to disk Parameters ---------- d : dict a mapping from filename to text like {'a.csv': '1,1\n2,2'} Since this is meant for use in tests, this context manager will automatically switch to a temporary current directory, to avoid race conditi

(d, open=open, mode="t", use_tmpdir=True)

Source from the content-addressed store, hash-verified

462
463@contextmanager
464def filetexts(d, open=open, mode="t", use_tmpdir=True):
465 """Dumps a number of textfiles to disk
466
467 Parameters
468 ----------
469 d : dict
470 a mapping from filename to text like {'a.csv': '1,1\n2,2'}
471
472 Since this is meant for use in tests, this context manager will
473 automatically switch to a temporary current directory, to avoid
474 race conditions when running tests in parallel.
475 """
476 with tmp_cwd() if use_tmpdir else nullcontext():
477 for filename, text in d.items():
478 try:
479 os.makedirs(os.path.dirname(filename))
480 except OSError:
481 pass
482 f = open(filename, "w" + mode)
483 try:
484 f.write(text)
485 finally:
486 try:
487 f.close()
488 except AttributeError:
489 pass
490
491 yield list(d)
492
493 for filename in d:
494 if os.path.exists(filename):
495 with suppress(OSError):
496 os.remove(filename)
497
498
499def concrete(seq):

Callers 15

test_read_bytesFunction · 0.90
test_parse_sample_bytesFunction · 0.90
test_with_urlsFunction · 0.90
test_with_pathsFunction · 0.90
test_read_bytes_blockFunction · 0.90

Calls 4

tmp_cwdFunction · 0.85
closeMethod · 0.80
removeMethod · 0.80
itemsMethod · 0.45

Tested by 15

test_read_bytesFunction · 0.72
test_parse_sample_bytesFunction · 0.72
test_with_urlsFunction · 0.72
test_with_pathsFunction · 0.72
test_read_bytes_blockFunction · 0.72