import os
import pytest
import tempfile
import shutil
from snakemake.shell import shell

@pytest.fixture(scope='session')
def sample1_se_fq(tmpdir_factory):
    fn = 'samples/sample1/sample1_R1.fastq.gz'
    d = str(tmpdir_factory.mktemp('sample1_se_fq'))
    url = 'https://github.com/lcdb/lcdb-test-data/blob/master/data/{}?raw=true'.format(fn)
    basename = os.path.basename(fn)
    shell('wget -q -O- {url} > {d}/{basename}')
    return os.path.join(d, basename)


@pytest.fixture(scope='session')
def sample1_pe_fq(tmpdir_factory):
    pair = []
    d = str(tmpdir_factory.mktemp('sample1_pe_fq'))
    for fn in [
        'samples/sample1/sample1_R1.fastq.gz',
        'samples/sample1/sample1_R2.fastq.gz'
    ]:
        url = 'https://github.com/lcdb/lcdb-test-data/blob/master/data/{}?raw=true'.format(fn)
        basename = os.path.basename(fn)
        shell('wget -q -O- {url} > {d}/{basename}')
        pair.append(os.path.join(d, basename))
    return pair


@pytest.fixture(scope='session')
def dm6_fa(tmpdir_factory):
    fn = 'seq/2L.fa'
    d = str(tmpdir_factory.mktemp('dm6_fa'))
    url = 'https://github.com/lcdb/lcdb-test-data/blob/master/data/{}?raw=true'.format(fn)
    basename = os.path.basename(fn)
    shell('wget -q -O- {url} > {d}/{basename}')
    return os.path.join(d, basename)


@@ -80,16 +80,55 @@
 rt shell
+%0Afrom lcdblib.snakemake import aligners
 %0A%0A@pytes
@@ -1324,28 +1324,471 @@
  os.path.join(d, basename)%0A%0A
+%0A@pytest.fixture(scope='session')%0Adef hisat2_indexes(tmpdir_factory):%0A    d = str(tmpdir_factory.mktemp('hisat2_indexes'))%0A    fns = %5B%5D%0A    for fn in aligners.hisat2_index_from_prefix('seq/2L'):%0A        url = 'https://github.com/lcdb/lcdb-test-data/blob/master/data/%7B%7D?raw=true'.format(fn)%0A        basename = os.path.basename(fn)%0A        shell('wget -q -O- %7Burl%7D %3E %7Bd%7D/%7Bbasename%7D')%0A        fns.append(os.path.join(d, basename))%0A    return fns%0A

add fixture for getting hisat2 indexes