Skip to content

Commit

Permalink
TST: add tests for command execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Vini2 committed Sep 17, 2024
1 parent bc06779 commit e031c7d
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions tests/test_gbintk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import pathlib
import pytest
import subprocess


__author__ = "Vijini Mallawaarachchi"
__credits__ = ["Vijini Mallawaarachchi"]


DATADIR = pathlib.Path(__file__).parent / "data"


@pytest.fixture(scope="session")
def tmp_dir(tmpdir_factory):
return tmpdir_factory.mktemp("tmp")


@pytest.fixture(autouse=True)
def workingdir(tmp_dir, monkeypatch):
"""set the working directory for all tests"""
monkeypatch.chdir(tmp_dir)


def exec_command(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
"""executes shell command and returns stdout if completes exit code 0
Parameters
----------
cmnd : str
shell command to be executed
stdout, stderr : streams
Default value (PIPE) intercepts process output, setting to None
blocks this."""

proc = subprocess.Popen(cmnd, shell=True, stdout=stdout, stderr=stderr)
out, err = proc.communicate()
if proc.returncode != 0:
raise RuntimeError(f"FAILED: {cmnd}\n{err}")
return out.decode("utf8") if out is not None else None


def test_gbintk():
"""test gbintk"""
cmd = "gbintk"
exec_command(cmd)


def test_gbintk_version():
"""test gbintk version"""
cmd = "gbintk --version"
exec_command(cmd)


def test_gbintk_graphbin():
"""test gbintk graphbin"""
cmd = "gbintk graphbin"
exec_command(cmd)


def test_gbintk_graphbin2():
"""test gbintk graphbin2"""
cmd = "gbintk graphbin2"
exec_command(cmd)


def test_gbintk_metacoag():
"""test gbintk metacoag"""
cmd = "gbintk metacoag"
exec_command(cmd)


def test_gbintk_prepare():
"""test gbintk prepare"""
cmd = "gbintk prepare"
exec_command(cmd)


def test_gbintk_visualise():
"""test gbintk visualise"""
cmd = "gbintk visualise"
exec_command(cmd)


def test_gbintk_evaluate():
"""test gbintk evaluate"""
cmd = "gbintk evaluate"
exec_command(cmd)

0 comments on commit e031c7d

Please sign in to comment.