#!/usr/bin/env python

"""Tests for availability of pyani dependencies

We only test for dependencies from non-standard libraries.
"""

import subprocess
import sys

import pytest


def test_import_biopython():
    """Test Biopython import."""
    import Bio


def test_import_matplotlib():
    """Test matplotlib import."""
    import matplotlib


def test_import_numpy():
    """Test numpy import."""
    import numpy


def test_import_pandas():
    """Test pandas import."""
    import pandas


def test_import_scipy():
    """Test scipy import."""
    import scipy


def test_run_blast():
    """Test that BLAST+ is runnable."""
    cmd = "blastn -version"
    result = subprocess.run(
        cmd,
        shell=sys.platform != "win32",
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        check=True,
    )
    print(result.stdout)
    assert result.stdout[:6] == b"blastn"


@pytest.mark.skip()
def test_run_blastall():
    """Test that legacy BLAST is runnable."""
    cmd = "blastall"
    # Can't use check=True, as blastall without arguments returns 1!
    result = subprocess.run(
        cmd,
        shell=sys.platform != "win32",
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    print(result.stdout)
    assert result.stdout[1:9] == b"blastall"


def test_run_nucmer():
    """Test that NUCmer is runnable."""
    cmd = "nucmer --version"
    result = subprocess.run(
        cmd,
        shell=sys.platform != "win32",
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        check=True,
    )
    print(result.stderr)  # NUCmer puts output to STDERR!
    assert result.stderr[:6] == b"nucmer"
