pytest_ngsfixtures package

Submodules

pytest_ngsfixtures.config module

Configuration settings for pytest-ngsfixtures

pytest_ngsfixtures.os module

pytest_ngsfixtures.os.localpath(src, path=PosixPath('/home/peru/dev/pytest-ngsfixtures/pytest_ngsfixtures/data'))[source]

Generate a py.path.local path given a source and a path

pytest_ngsfixtures.os.safe_copy(p, src, dst=None, ignore_errors=False)[source]

Safely copy fixture file.

Copy file from src to dst in LocalPath p. If src, dst are strings, they will be joined to p, assuming they are relative to p. If src, dst are LocalPath instances, they are left alone since LocalPath objects are always absolute paths.

Parameters:
  • p (LocalPath) – path in which link is setup
  • src (str, LocalPath) – source file that link points to. If string, assume relative to pytest_ngsfixtures data directory
  • dst (str, LocalPath) – link destination name. If string, assume relative to path and concatenate; else leave alone
  • ignore_errors (bool) – ignore errors should target file exist
Returns:

link name

Return type:

dst (LocalPath)

pytest_ngsfixtures.os.safe_mktemp(tmpdir_factory, dirname=None, **kwargs)[source]

Safely make directory

Safely make symlink.

Make symlink from src to dst in LocalPath p. If src, dst are strings, they will be joined to p, assuming they are relative to p. If src, dst are LocalPath instances, they are left alone since LocalPath objects are always absolute paths.

Parameters:
  • p (LocalPath) – path in which link is setup
  • src (str, LocalPath) – source file that link points to. If string, assume relative to pytest_ngsfixtures data directory
  • dst (str, LocalPath) – link destination name. If string, assume relative to path and concatenate; else leave alone
  • ignore_errors (bool) – ignore errors should target file exist
Returns:

link name

Return type:

dst (LocalPath)

pytest_ngsfixtures.plugin module

Plugin configuration module for pytest-ngsfixtures

class pytest_ngsfixtures.plugin.Fixture(name='testdata', request=None, datakey='data', path=None, **kwargs)[source]

Bases: py._path.local.LocalPath

Fixture class to setup fixture represented as a LocalPath object pointing to the root test directory where data are located.

Parameters:
  • name (str) – fixture name (one of testdata, samples, ref)
  • request (_pytest.fixtures.SubRequest) – pytest request object
  • datakey (str) – data key label
  • path (str) – test directory path; overrides call to tmpdir_factory
Keyword Arguments:
 
  • copy (bool) – copy or link data
  • data (dict) – key value mapping of destination and source files
  • dirname (str) – fixture directory; prefixed by testunit if provided
  • ignore_errors (bool) – ignore errors should target file exist
  • numbered (bool) – create numbered test directories
  • testunit (str) – group tests in directory named testunit relative to tmpdir_factory basename
keys()[source]
pytest_ngsfixtures.plugin.pytest_addoption(parser)[source]
pytest_ngsfixtures.plugin.pytest_configure(config)[source]
pytest_ngsfixtures.plugin.ref(request, tmpdir_factory)[source]

Return a temporary directory path object pointing to the location of reference files.

The reference directory path name can be changed with @pytest.mark.ref(dirname=”refdirname”)

Examples

@pytest.mark.ref(dirname="foo", data={'ref.fa': '/path/to/ref.fa'})
def test_ref(ref):
    print(ref)
pytest_ngsfixtures.plugin.samples(request, tmpdir_factory)[source]

Return a temporary directory path object pointing to the root directory where samples are located.

The samples directory path name can be changed with @pytest.mark.samples. In addition, the data layout can be parametrized with @pytest.mark.parametrize.

Examples

@pytest.mark.parametrize("layout", [{'s1.fastq.gz': '/path/to/foo.fastq.gz'},
                                    {'s2.fastq.gz': '/path/to/foo.fastq.gz'}])
@pytest.mark.samples(dirname="foo")
def test_samples(samples, layout):
    print(samples.listdir())
pytest_ngsfixtures.plugin.testdata(request, tmpdir_factory)[source]

Return a temporary directory path object pointing to the root directory where generic test data are located.

Examples

@pytest.mark.testdata(data={'foo.txt': 'bar.txt'})
def test_data(testdata):
    print(testdata.listdir())

pytest_ngsfixtures.shell module

pytest_ngsfixtures.shell.get_conda_root()[source]
class pytest_ngsfixtures.shell.shell[source]

Bases: object

Class wrapper for shell commands.

Wrapper for running shell commands. The wrapper accepts arguments for seamlessly running in docker/singularity containers.

Based on snakemake shell implementation by Johannes Köster.

Parameters:
  • cmd (str) – command string
  • container (Container) – docker/singularity container instance
  • conda_env (str) – conda environment to activate
  • conda_env_list (list) – additional conda environment paths to add to PATH. Note: only the conda environment names need be provided as the conda root is inferred from the current conda environment
  • conda_root (str) – conda root path. Use in case automatically inferring the root fails
  • image (Image) – docker/singularity image to run in
  • iterable (bool) – return output as iterable
  • read (bool) – read and return output
  • async (bool) – run asynchronously
  • path_list (list) – prefix command with additional paths
  • stdout (_io.TextIOWrapper, int) – stdout file object
  • stderr (int) – stderr special value
  • stream (bool) – stream containerized run; alias to iterable
  • detach (bool) – detach containerized run; alias to async
  • process_prefix (str) – temporarily override class process prefix. In containerized settings, using ‘source activate’ together with the automatically generated class process prefix ‘set -euo pipefail’ may fail
Returns:

stdout if read is set, an iterable if iterable is set, a process (either subprocess.Popen or docker.models.containers.Container) if async is set, None otherwise

classmethod executable(cmd)[source]
static iter_stdout(proc, cmd)[source]
classmethod prefix(prefix)[source]
static read_stdout(proc)[source]
static stdout(proc, cmd, ret=None)[source]

pytest_ngsfixtures.utils module

pytest_ngsfixtures.utils.cd(path)[source]

Module contents