mercredi 20 juin 2018

pytest tmpdir_factory test glob search

I'm trying to write a test that validates that the correct files are found when I glob over a directory but I dont understand why the glob is coming back empty using the tmpdir_factory, as executing the code on a real dir works as expected. All the module imports are correct and it is calling the function.

Code to be tested:

def get_files(sdir, extension):
    return glob.glob1(sdir, "*" + extension + "*")

pytest code:

flist = [
    "12707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017011",
    "22707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017012",
    "32707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017013",
    "42707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017014",
    "52707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017015",
    "12707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017011.pdpr",
    "22707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017012.pdpr",
    "32707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017013.pdpr",
    "42707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017014.pdpr",
    "52707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017015.pdpr"
]


def test_get_files_afp(tmpdir_factory):
    rlist = [
        "12707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017011",
        "22707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017012",
        "32707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017013",
        "42707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017014",
        "52707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017015"
    ]
    test_dir = tmpdir_factory.mktemp('testdata')
    for f in flist:
        test_dir.join(f)

    lst = get_files(sdir=str(test_dir), extension=".afp")
    assert lst == rlist

fails with:

assert lst == rlist
E       AssertionError: assert [] == ['12707054321.HOM0LRP2.COUNT....JOB46147.pg96.afp.2017015']
E         Right contains more items, first extra item: 
'12707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017011'
E         Full diff:
E         - []
E         + ['12707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017011',
E         +  '22707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017012',
E         +  '32707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017013',
E         +  '42707054321.HOM0LRP2.COUNTS.JOB46147.pg96.afp.2017014',...

Aucun commentaire:

Enregistrer un commentaire