Skip to content

Commit

Permalink
Merge pull request #180 from vreuter/automicro
Browse files Browse the repository at this point in the history
Initial case and framework for smoketesting the CLI with microtest
  • Loading branch information
vreuter authored May 2, 2019
2 parents f9b6e9b + 53ebbc0 commit d235b87
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ install:
- pip install .
- pip install -r requirements/requirements-dev.txt
- pip install -r requirements/requirements-test.txt
script: pytest
script: pytest --cov=looper
branches:
only:
- dev
Expand Down
2 changes: 2 additions & 0 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
coveralls==1.1
pytest-cov==2.4.0
pytest-remotedata
ubiquerg>=0.0.3dev
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
PROJECT_CONFIG_DATA = {"metadata": {SAMPLE_ANNOTATIONS_KEY: "annotations.csv"}}



def update_project_conf_data(extension):
""" Updated Project configuration data mapping based on file extension """
updated = copy.deepcopy(PROJECT_CONFIG_DATA)
Expand All @@ -196,15 +195,13 @@ def update_project_conf_data(extension):
return updated



def pytest_addoption(parser):
""" Facilitate command-line test behavior adjustment. """
parser.addoption("--logging-level",
default="WARN",
help="Project root logger level to use for tests")



def pytest_generate_tests(metafunc):
""" Centralize dynamic test case parameterization. """
if "empty_collection" in metafunc.fixturenames:
Expand Down
70 changes: 70 additions & 0 deletions tests/test_with_microtest_as_smoketest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
""" Use microtest for smoketesting the looper CLI. """

import os
import subprocess
import pytest
from ubiquerg import build_cli_extra

__author__ = "Vince Reuter"
__email__ = "[email protected]"


REPO_NAME = "microtest"
REPO_URL = "https://github.com/databio/{}".format(REPO_NAME)
SAMPLE_SELECTOR_OPTION = "--selector-attribute"
INCLUSION_OPTION = "--selector-include"


@pytest.mark.remote_data
@pytest.fixture
def data_root(tmpdir):
""" Clone data repo and return path to it. """
tmp = tmpdir.strpath
cmd = "git clone {}".format(REPO_URL)
try:
subprocess.check_call(cmd, cwd=tmp, shell=True)
except subprocess.CalledProcessError:
raise Exception("Failed to pull data ()".format(cmd))
root = os.path.join(tmp, REPO_NAME)
assert os.path.isdir(root)
return root


@pytest.fixture
def data_conf_file(data_root):
""" Clone data repo and return path to project config file. """
f = os.path.join(data_root, "config", "microtest_config.yaml")
assert os.path.isfile(f), "Contents: {}".format(os.listdir(data_root))
return f


@pytest.fixture(scope="function")
def temp_chdir_home(tmpdir):
""" Temporarily (for a test case) change home and working directories. """
key = "HOME"
prev_home = os.environ[key]
prev_work = os.environ["PWD"]
curr_home = tmpdir.strpath
os.environ[key] = curr_home
os.chdir(curr_home)
yield
os.environ[key] = prev_home
os.chdir(prev_work)
assert os.getcwd() == prev_work
assert os.getenv(key) == prev_home
assert os.environ[key] == prev_home


@pytest.mark.remote_data
@pytest.mark.usefixtures("temp_chdir_home")
@pytest.mark.parametrize("cli_extra",
[build_cli_extra(**kvs) for kvs in
[{SAMPLE_SELECTOR_OPTION: "protocol", INCLUSION_OPTION: "ATAC-seq"}]])
def test_cli_microtest_smoke(cli_extra, data_conf_file):
""" Using microtest as project, test CLI for failure on specific cases. """
cmd = "looper run -d {} {}".format(data_conf_file, cli_extra)
try:
subprocess.check_call(cmd, shell=True)
except Exception as e:
print("Exception: {}".format(e))
pytest.fail("Failed command: {}".format(cmd))

0 comments on commit d235b87

Please sign in to comment.