def test_samtools_idxstats_notexec():
    """Error thrown if samtools_idxstats exe not executable"""
    try:
        obj = samtools_idxstats.Samtools_Idxstats("LICENSE")
    except NotExecutableError:
        return True
    else:
        return False
def test_samtools_idxstats_exec():
    """Run samtools_idxstats on test data and compare output
    to precomputed target"""
    obj = samtools_idxstats.Samtools_Idxstats("samtools")
    result = obj.run(BAM_FILE, OUTFILE)
    with open(TARGET, "r") as target_fh:
        with open(result.cov, "r") as test_fh:
            assert_equal(target_fh.read(), test_fh.read())
def test_samtools_idxstats_exec_notexist():
    """Error thrown if samtools_idxstats executable does not exist"""
    try:
        obj = samtools_idxstats.Samtools_Idxstats(os.path.join(
            ".", "samtools"))
    except NotExecutableError:
        return True
    else:
        return False
def test_samtools_idxstats_cmd():
    """samtools_idxstats instantiates, runs and returns
    correct form of cmd-line"""
    # checking and making the output folder is staying in for now
    if not os.path.exists(OUTDIR):
        os.makedirs(OUTDIR)
    obj = samtools_idxstats.Samtools_Idxstats("samtools")
    target = ' '.join([
        "samtools", "idxstats", BAM_FILE, "|", "grep", '-v', "'*'", "|",
        "sort", "--reverse", "-n", "-k3", ">", OUTFILE
    ])
    stats = obj.run(BAM_FILE, OUTFILE)
    assert_equal(stats.command, target)
def test_samtools_idxstats():
    """Samtools_Idxstats instantiates with cmd-line if Samtools_Idxstats
    is in $PATH"""
    samtools_idxstats.Samtools_Idxstats("samtools")