Exemple #1
0
def _mergefiles2stream(*infiles, **kwargs):

    """
    Merge sort a bunch of tempfiles into a sorted stream of objects.  Tempfiles
    are not deleted.

    Parameters
    ----------
    infiles : str
        Input paths to merge sort.
    reader : tinysort.io.BaseSerializer
        Instance of the serializer for reading the `paths`.
    kwargs : **kwargs, optional
        Keyword arguments for `heapq.merge()`.

    Yields
    ------
    object
    """

    if 'reader' not in kwargs:
        raise TypeError("reader parameter is required.")
    else:
        reader = kwargs.pop('reader')

    with tools.batch_open(*infiles, opener=reader.open) as handles:
        for item in heapq_merge(*handles, **kwargs):
            yield item
Exemple #2
0
def test_batch_open(tmpdir):

    base = tmpdir.mkdir('test_delete_files')
    paths = [str(base.join(str(i))) for i in range(5)]

    for p in paths:
        assert not os.path.exists(p)

    with tools.batch_open(*paths, mode='w') as handles:
        if six.PY2:
            t = file
        else:
            t = io.IOBase
        for h in handles:
            assert isinstance(h, t)