def test_commandline(capsys, bamFile): getstartends.main([str(bamFile)]) out, err = capsys.readouterr() out2 = subprocess.check_output("getstartends " + str(bamFile), shell=True) out3 = subprocess.check_output("python -m dnapy.getstartends " + str(bamFile), shell=True) for ii, jj, kk in zip(out.split('\n'), out2.decode().split('\n'), out3.decode().split('\n')): print(ii) print(jj) assert ii == jj == kk
def test_main(capsys, tmpdir, bamFile): with pytest.raises(SystemExit): getstartends.main() out, err = capsys.readouterr() assert 'usage' in err with pytest.raises(SystemExit): getstartends.main(['-h']) out, err = capsys.readouterr() assert 'usage' in out getstartends.main(['-v', str(bamFile)]) out, err = capsys.readouterr() assert 'Arguments' in err compare = getstartends.getStartsInFile(str(bamFile)) count = 0 for ii, jj in zip(out.split('\n')[1:], compare): ii = ii.split(',') count += 1 assert ii[0] == jj['ref'] assert int(ii[1]) == jj['start'] assert int(ii[2]) == jj['end'] assert ii[3] == jj['strand'] assert count == 2 compare = getstartends.getStartsInFile(str(bamFile), maxGaps=10) getstartends.main([str(bamFile), '-g 10']) out, err = capsys.readouterr() count = 0 for ii, jj in zip(out.split('\n')[1:], compare): count += 1 ii = ii.split(',') assert ii[0] == jj['ref'] assert int(ii[1]) == jj['start'] assert int(ii[2]) == jj['end'] assert ii[3] == jj['strand'] assert count == 3 getstartends.main([str(bamFile), '-g 10', '-n']) noHead, err = capsys.readouterr() for ii, jj in zip(out.split('\n')[1:], noHead.split('\n')): assert ii == jj getstartends.main([str(bamFile), '-g 10', '-n', '-c']) regCol, err = capsys.readouterr() for ii, jj in zip(out.split('\n')[1:], regCol.split('\n')): if ii: ii = "None," + ii assert ii == jj getstartends.main([str(bamFile), '-g 10', '-n', '-c', '-r', 'ref:1-100']) regCol, err = capsys.readouterr() for ii, jj in zip(out.split('\n')[1:], regCol.split('\n')): if ii: ii = "ref:1-100," + ii assert ii == jj d = tmpdir.mkdir('dir') p = d.join('test.regions') p.write("ref:1-10\nref:1-100") getstartends.main([str(bamFile), '-g 10', '-n', '-c', '-f', str(p)]) fileOut, err = capsys.readouterr() for ii, jj in zip(regCol.split('\n'), fileOut.split('\n')): assert ii == jj