-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: add tests for command execution
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |