From ee3dbe113a2d5b8cddc8720527bc970f08fe8184 Mon Sep 17 00:00:00 2001 From: Yash Patel <86321070+yashpatel6@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:11:26 -0800 Subject: [PATCH] Refactor interface (#88) * Update setup.cfg for new structure * Update name * Update tests for new structure * Setup pipeval main module * Update validate module * Update validate module with new structure * Update checksum module * Remove old structure * Update Dockerfile * Update command name * Update CHANGELOG * Update commands in README * Remove version from subcommands --- CHANGELOG.md | 12 +++ README.md | 10 +-- docker/Dockerfile | 7 +- generate_checksum/__main__.py | 25 ------ pipeval/__init__.py | 3 + pipeval/__main__.py | 32 +++++++ .../generate_checksum}/__init__.py | 2 - pipeval/generate_checksum/__main__.py | 18 ++++ .../generate_checksum}/checksum.py | 0 {validate => pipeval/validate}/__init__.py | 2 - {validate => pipeval/validate}/__main__.py | 26 +++--- {validate => pipeval/validate}/files.py | 0 {validate => pipeval/validate}/validate.py | 14 +-- .../validate}/validate_types.py | 0 .../validate}/validators/__init__.py | 0 .../validate}/validators/bam.py | 2 +- .../validate}/validators/cram.py | 2 +- .../validate}/validators/sam.py | 2 +- .../validate}/validators/vcf.py | 0 setup.cfg | 7 +- test/unit/test_generate_checksum.py | 54 ++++++------ test/unit/test_validate.py | 88 +++++++++---------- 22 files changed, 166 insertions(+), 140 deletions(-) delete mode 100644 generate_checksum/__main__.py create mode 100644 pipeval/__init__.py create mode 100644 pipeval/__main__.py rename {generate_checksum => pipeval/generate_checksum}/__init__.py (54%) create mode 100644 pipeval/generate_checksum/__main__.py rename {generate_checksum => pipeval/generate_checksum}/checksum.py (100%) rename {validate => pipeval/validate}/__init__.py (54%) rename {validate => pipeval/validate}/__main__.py (64%) rename {validate => pipeval/validate}/files.py (100%) rename {validate => pipeval/validate}/validate.py (91%) rename {validate => pipeval/validate}/validate_types.py (100%) rename {validate => pipeval/validate}/validators/__init__.py (100%) rename {validate => pipeval/validate}/validators/bam.py (95%) rename {validate => pipeval/validate}/validators/cram.py (96%) rename {validate => pipeval/validate}/validators/sam.py (93%) rename {validate => pipeval/validate}/validators/vcf.py (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a3bcc..ae9a78c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm --- +## [5.0.0-rc.1] - 2023-11-22 +### Changed +- Restructured CLI to have common main command `pipeval` + +--- + +## [4.0.0] - 2023-11-22 +### Added +- Parallelize validation + +--- + ## [4.0.0-rc.2] - 2023-04-24 ### Changed - Resolve potential symlinks before validation diff --git a/README.md b/README.md index 198944c..d0c0f1b 100644 --- a/README.md +++ b/README.md @@ -70,16 +70,15 @@ pip install . ``` ## Usage -### `validate` +### `pipeval validate` ``` -usage: validate [-h] [-v] [-r CRAM_REFERENCE] path [path ...] +usage: pipeval validate [-h] [-v] [-r CRAM_REFERENCE] path [path ...] positional arguments: path one or more paths of files to validate options: -h, --help show this help message and exit - -v, --version show program's version number and exit -r CRAM_REFERENCE, --cram-reference CRAM_REFERENCE Path to reference file for CRAM -p PROCESSES, --processes PROCESSES @@ -111,9 +110,9 @@ Input: path/to/input is valid Error: path/to/input ``` -### `generate-checksum` +### `pipeval generate-checksum` ``` -usage: generate-checksum [-h] [-t {md5,sha512}] [-v] path [path ...] +usage: pipeval generate-checksum [-h] [-t {md5,sha512}] [-v] path [path ...] positional arguments: path one or more paths of files to validate @@ -122,7 +121,6 @@ options: -h, --help show this help message and exit -t {md5,sha512}, --type {md5,sha512} Checksum type - -v, --version show program's version number and exit ``` ## Development diff --git a/docker/Dockerfile b/docker/Dockerfile index a4958dc..0bd7e55 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -32,8 +32,7 @@ RUN mkdir -p /tool/validate/ COPY setup.py /tool COPY setup.cfg /tool COPY pyproject.toml /tool -COPY /generate_checksum /tool/generate_checksum -COPY /validate/ /tool/validate/ +COPY /pipeval /tool/pipeval WORKDIR /tool RUN pip install build && \ pip install . @@ -48,5 +47,5 @@ RUN groupadd -g 500001 bldocker && \ # Change the default user to bldocker from root USER bldocker -LABEL maintainer="Arpi Beshlikyan " \ - org.opencontainers.image.source=https://github.com/uclahs-cds/public-tool-PipeVal +LABEL maintainer="Yash Patel " \ + org.opencontainers.image.source=https://github.com/uclahs-cds/package-PipeVal diff --git a/generate_checksum/__main__.py b/generate_checksum/__main__.py deleted file mode 100644 index 9194f66..0000000 --- a/generate_checksum/__main__.py +++ /dev/null @@ -1,25 +0,0 @@ -''' Console script main entrance ''' -import argparse -from generate_checksum import __version__ -from generate_checksum.checksum import generate_checksum - -def _parse_args(): - """ Parse arguments """ - parser = argparse.ArgumentParser() - parser.add_argument('path', help='one or more paths of files to validate', type=str, nargs='+') - parser.add_argument('-t', '--type', help='Checksum type', - choices=['md5', 'sha512'], - default='sha512') - parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version__}') - - parser.set_defaults(func=generate_checksum) - - return parser.parse_args() - -def main(): - ''' Main entrance ''' - args = _parse_args() - args.func(args) - -if __name__=='__main__': - main() diff --git a/pipeval/__init__.py b/pipeval/__init__.py new file mode 100644 index 0000000..e93fd0d --- /dev/null +++ b/pipeval/__init__.py @@ -0,0 +1,3 @@ +'''Inits pipeval module''' + +__version__ = '5.0.0-rc.1' diff --git a/pipeval/__main__.py b/pipeval/__main__.py new file mode 100644 index 0000000..9ad293f --- /dev/null +++ b/pipeval/__main__.py @@ -0,0 +1,32 @@ +''' Console script main entrance ''' +import argparse +from pipeval import __version__ + +from pipeval.validate.__main__ import add_subparser_validate +from pipeval.generate_checksum.__main__ import add_subparser_generate_checksum + +def _parse_args(): + """ Parse arguments """ + parser = argparse.ArgumentParser( + prog = 'pipeval' + ) + + parser.add_argument( + '-v', '--version', + action='version', + version=f'%(prog)s {__version__}' + ) + + subparsers = parser.add_subparsers(dest = 'command') + add_subparser_validate(subparsers) + add_subparser_generate_checksum(subparsers) + + return parser.parse_args() + +def main(): + ''' Main entrance ''' + args = _parse_args() + args.func(args) + +if __name__=='__main__': + main() diff --git a/generate_checksum/__init__.py b/pipeval/generate_checksum/__init__.py similarity index 54% rename from generate_checksum/__init__.py rename to pipeval/generate_checksum/__init__.py index 9e8585d..77b5852 100644 --- a/generate_checksum/__init__.py +++ b/pipeval/generate_checksum/__init__.py @@ -1,3 +1 @@ '''Inits checksum module''' - -__version__ = '3.0.0' diff --git a/pipeval/generate_checksum/__main__.py b/pipeval/generate_checksum/__main__.py new file mode 100644 index 0000000..ac1113a --- /dev/null +++ b/pipeval/generate_checksum/__main__.py @@ -0,0 +1,18 @@ +''' Console script main entrance ''' +import argparse +from pipeval.generate_checksum.checksum import generate_checksum + +def add_subparser_generate_checksum(subparsers:argparse._SubParsersAction): + """ Parse arguments """ + parser = subparsers.add_parser( + name = 'generate-checksum', + help = 'Generate checksums for one or more file(s)', + description = 'Generate checksums for one or more file(s)', + formatter_class = argparse.ArgumentDefaultsHelpFormatter + ) + parser.add_argument('path', help='one or more paths of files to validate', type=str, nargs='+') + parser.add_argument('-t', '--type', help='Checksum type', + choices=['md5', 'sha512'], + default='sha512') + + parser.set_defaults(func=generate_checksum) diff --git a/generate_checksum/checksum.py b/pipeval/generate_checksum/checksum.py similarity index 100% rename from generate_checksum/checksum.py rename to pipeval/generate_checksum/checksum.py diff --git a/validate/__init__.py b/pipeval/validate/__init__.py similarity index 54% rename from validate/__init__.py rename to pipeval/validate/__init__.py index a7f1cbc..be93e35 100644 --- a/validate/__init__.py +++ b/pipeval/validate/__init__.py @@ -1,3 +1 @@ '''Inits validate module''' - -__version__ = '4.0.0' diff --git a/validate/__main__.py b/pipeval/validate/__main__.py similarity index 64% rename from validate/__main__.py rename to pipeval/validate/__main__.py index 37a1013..50288c6 100644 --- a/validate/__main__.py +++ b/pipeval/validate/__main__.py @@ -1,7 +1,6 @@ ''' Console script main entrance ''' import argparse -from validate import __version__ -from validate.validate import run_validate +from pipeval.validate.validate import run_validate def positive_integer(arg): """ Type and value check for positive integers """ @@ -15,24 +14,19 @@ def positive_integer(arg): return i -def _parse_args(): +def add_subparser_validate(subparsers:argparse._SubParsersAction): """ Parse arguments """ - parser = argparse.ArgumentParser() - parser.add_argument('path', help='one or more paths of files to validate', type=str, nargs='+') - parser.add_argument('-v', '--version', action='version', version=f'%(prog)s {__version__}') + parser = subparsers.add_parser( + name = 'validate', + help = 'Validate one or more file(s)', + description = 'Validate one or more file(s)', + formatter_class = argparse.ArgumentDefaultsHelpFormatter + ) + + parser.add_argument('path', help='One or more paths of files to validate', type=str, nargs='+') parser.add_argument('-r', '--cram-reference', default=None, \ help='Path to reference file for CRAM') parser.add_argument('-p', '--processes', type=positive_integer, default=1, \ help='Number of processes to run in parallel when validating multiple files') parser.set_defaults(func=run_validate) - - return parser.parse_args() - -def main(): - ''' Main entrance ''' - args = _parse_args() - args.func(args) - -if __name__=='__main__': - main() diff --git a/validate/files.py b/pipeval/validate/files.py similarity index 100% rename from validate/files.py rename to pipeval/validate/files.py diff --git a/validate/validate.py b/pipeval/validate/validate.py similarity index 91% rename from validate/validate.py rename to pipeval/validate/validate.py index b2af3e9..7697393 100644 --- a/validate/validate.py +++ b/pipeval/validate/validate.py @@ -6,16 +6,16 @@ import multiprocessing from itertools import repeat -from validate.validators.bam import _check_bam -from validate.validators.sam import _check_sam -from validate.validators.cram import _check_cram -from validate.validators.vcf import _check_vcf -from validate.files import ( +from pipeval.validate.validators.bam import _check_bam +from pipeval.validate.validators.sam import _check_sam +from pipeval.validate.validators.cram import _check_cram +from pipeval.validate.validators.vcf import _check_vcf +from pipeval.validate.files import ( _check_compressed, _path_exists ) -from validate.validate_types import ValidateArgs -from generate_checksum.checksum import _validate_checksums +from pipeval.validate.validate_types import ValidateArgs +from pipeval.generate_checksum.checksum import _validate_checksums # Currently supported data types FILE_TYPES_DICT = { diff --git a/validate/validate_types.py b/pipeval/validate/validate_types.py similarity index 100% rename from validate/validate_types.py rename to pipeval/validate/validate_types.py diff --git a/validate/validators/__init__.py b/pipeval/validate/validators/__init__.py similarity index 100% rename from validate/validators/__init__.py rename to pipeval/validate/validators/__init__.py diff --git a/validate/validators/bam.py b/pipeval/validate/validators/bam.py similarity index 95% rename from validate/validators/bam.py rename to pipeval/validate/validators/bam.py index c6d7665..52749aa 100644 --- a/validate/validators/bam.py +++ b/pipeval/validate/validators/bam.py @@ -4,7 +4,7 @@ import pysam -from validate.validate_types import ValidateArgs +from pipeval.validate.validate_types import ValidateArgs def _validate_bam_file(path:Path): '''Validates bam file''' diff --git a/validate/validators/cram.py b/pipeval/validate/validators/cram.py similarity index 96% rename from validate/validators/cram.py rename to pipeval/validate/validators/cram.py index 9bcd18a..0c30cd5 100644 --- a/validate/validators/cram.py +++ b/pipeval/validate/validators/cram.py @@ -4,7 +4,7 @@ import pysam -from validate.validate_types import ValidateArgs +from pipeval.validate.validate_types import ValidateArgs def _validate_cram_file(path:Path, reference:str=None): '''Validates cram file''' diff --git a/validate/validators/sam.py b/pipeval/validate/validators/sam.py similarity index 93% rename from validate/validators/sam.py rename to pipeval/validate/validators/sam.py index d2b123a..71b362b 100644 --- a/validate/validators/sam.py +++ b/pipeval/validate/validators/sam.py @@ -4,7 +4,7 @@ import pysam -from validate.validate_types import ValidateArgs +from pipeval.validate.validate_types import ValidateArgs def _validate_sam_file(path:Path): '''Validates sam file''' diff --git a/validate/validators/vcf.py b/pipeval/validate/validators/vcf.py similarity index 100% rename from validate/validators/vcf.py rename to pipeval/validate/validators/vcf.py diff --git a/setup.cfg b/setup.cfg index 298bf3f..aa7cb7b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] -name = validate -version = attr: validate.__version__ +name = pipeval +version = attr: pipeval.__version__ author = 'Yash Patel' author_email = 'YashPatel@mednet.ucla.edu' description = 'Python CLI tool to validate different file types and their contents in Nextflow scripts/pipelines' @@ -31,5 +31,4 @@ where = . [options.entry_points] console_scripts = - validate = validate.__main__:main - generate-checksum = generate_checksum.__main__:main + pipeval = pipeval.__main__:main diff --git a/test/unit/test_generate_checksum.py b/test/unit/test_generate_checksum.py index e360602..bba086e 100644 --- a/test/unit/test_generate_checksum.py +++ b/test/unit/test_generate_checksum.py @@ -5,7 +5,7 @@ import mock import pytest -from generate_checksum.checksum import ( +from pipeval.generate_checksum.checksum import ( _validate_checksums, _compare_hash, _write_checksum_file, @@ -15,7 +15,7 @@ ChecksumArgs ) -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__validate_checksums__validate_checksums_passes_with_no_checksum_file(mock_path): mock_path.suffix.return_value = '' mock_path.with_suffix.return_value = mock_path @@ -23,8 +23,8 @@ def test__validate_checksums__validate_checksums_passes_with_no_checksum_file(mo _validate_checksums(mock_path) -@mock.patch('generate_checksum.checksum._compare_hash') -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum._compare_hash') +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__validate_checksums__validate_checksum_passes(mock_path, mock_compare_hash): mock_path.suffix.return_value = '' mock_path.with_suffix.return_value = mock_path @@ -34,8 +34,8 @@ def test__validate_checksums__validate_checksum_passes(mock_path, mock_compare_h _validate_checksums(mock_path) -@mock.patch('generate_checksum.checksum._compare_hash') -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum._compare_hash') +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__validate_checksums__error_raised_when_comparison_fails(mock_path, mock_compare_hash): mock_path.suffix.return_value = '' mock_path.with_suffix.return_value = mock_path @@ -53,9 +53,9 @@ def test__validate_checksums__error_raised_when_comparison_fails(mock_path, mock ('sha512') ] ) -@mock.patch('generate_checksum.checksum._generate_sha512') -@mock.patch('generate_checksum.checksum._generate_md5') -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum._generate_sha512') +@mock.patch('pipeval.generate_checksum.checksum._generate_md5') +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__compare_hash__compares_correct_checksums( mock_path, mock_generate_md5, @@ -76,9 +76,9 @@ def test__compare_hash__compares_correct_checksums( ('sha512') ] ) -@mock.patch('generate_checksum.checksum._generate_sha512') -@mock.patch('generate_checksum.checksum._generate_md5') -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum._generate_sha512') +@mock.patch('pipeval.generate_checksum.checksum._generate_md5') +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__compare_hash__compares_incorrect_checksums( mock_path, mock_generate_md5, @@ -92,7 +92,7 @@ def test__compare_hash__compares_incorrect_checksums( assert not _compare_hash(hash_type, mock_path, mock_path) -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__compare_hash__fails_on_invalid_checksum_type(mock_path): mock_path.read_text.return_value = 'checksum fname' hash_type = 'invalid_hash_type' @@ -100,8 +100,8 @@ def test__compare_hash__fails_on_invalid_checksum_type(mock_path): with pytest.raises(IOError): _compare_hash(hash_type, mock_path, mock_path) -@mock.patch('generate_checksum.checksum.open', new_callable=mock_open) -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.open', new_callable=mock_open) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__write_checksum_file__writes_proper_checksum(mock_path, mock_write_open): file_path = 'filepath' computed_hash = 'hash' @@ -116,9 +116,9 @@ def test__write_checksum_file__writes_proper_checksum(mock_path, mock_write_open handle.write.assert_called_once_with(f'{computed_hash} {file_path}\n') # pylint: disable=W0613 -@mock.patch('generate_checksum.checksum.open', new_callable=mock_open) -@mock.patch('generate_checksum.checksum.Path', autospec=True) -@mock.patch('generate_checksum.checksum.iter') +@mock.patch('pipeval.generate_checksum.checksum.open', new_callable=mock_open) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.iter') def test__generate_md5__return_correct_checksum(mock_iter, mock_path, mock_read_open): md5_checksum = hashlib.md5() md5_checksum.update(b'') @@ -127,9 +127,9 @@ def test__generate_md5__return_correct_checksum(mock_iter, mock_path, mock_read_ assert _generate_md5(mock_path) == md5_checksum.hexdigest() # pylint: disable=W0613 -@mock.patch('generate_checksum.checksum.open', new_callable=mock_open) -@mock.patch('generate_checksum.checksum.Path', autospec=True) -@mock.patch('generate_checksum.checksum.iter') +@mock.patch('pipeval.generate_checksum.checksum.open', new_callable=mock_open) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.iter') def test__generate_sha512__return_correct_checksum(mock_iter, mock_path, mock_read_open): sha512_checksum = hashlib.sha512() sha512_checksum.update(b'') @@ -144,11 +144,11 @@ def test__generate_sha512__return_correct_checksum(mock_iter, mock_path, mock_re (ChecksumArgs(path=[], type='sha512')) ] ) -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__generate_checksum__passes_generation_with_no_files(mock_path, test_args): generate_checksum(test_args) -@mock.patch('generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) def test__generate_checksum__fails_with_invalid_type(mock_path): test_args = ChecksumArgs(path=['some/path'], type='bad_type') expected_code = 1 @@ -164,10 +164,10 @@ def test__generate_checksum__fails_with_invalid_type(mock_path): (ChecksumArgs(path=['some/path'], type='sha512')) ] ) -@mock.patch('generate_checksum.checksum.Path', autospec=True) -@mock.patch('generate_checksum.checksum._generate_md5') -@mock.patch('generate_checksum.checksum._generate_sha512') -@mock.patch('generate_checksum.checksum._write_checksum_file') +@mock.patch('pipeval.generate_checksum.checksum.Path', autospec=True) +@mock.patch('pipeval.generate_checksum.checksum._generate_md5') +@mock.patch('pipeval.generate_checksum.checksum._generate_sha512') +@mock.patch('pipeval.generate_checksum.checksum._write_checksum_file') def test__generate_checksum__fails_with_failed_write( mock_write_checksum_file, mock_generate_sha512, diff --git a/test/unit/test_validate.py b/test/unit/test_validate.py index 88449de..e74f1b4 100644 --- a/test/unit/test_validate.py +++ b/test/unit/test_validate.py @@ -7,33 +7,33 @@ import mock import pytest -from validate.files import ( +from pipeval.validate.files import ( _check_compressed, _path_exists ) -from validate.validators.bam import ( +from pipeval.validate.validators.bam import ( _validate_bam_file, _check_bam_index ) -from validate.validators.vcf import ( +from pipeval.validate.validators.vcf import ( _validate_vcf_file ) -from validate.validators.sam import ( +from pipeval.validate.validators.sam import ( _validate_sam_file ) -from validate.validators.cram import ( +from pipeval.validate.validators.cram import ( _validate_cram_file, _check_cram_index ) -from validate.validate import ( +from pipeval.validate.validate import ( _detect_file_type_and_extension, _check_extension, run_validate, _validate_file, _validation_worker ) -from validate.__main__ import positive_integer -from validate.validate_types import ValidateArgs +from pipeval.validate.__main__ import positive_integer +from pipeval.validate.validate_types import ValidateArgs def test__positive_integer__returns_correct_integer(): expected_number = 2 @@ -83,21 +83,21 @@ def test__check_extension__correct_file_type(test_extension, expected_type): assert file_type == expected_type -@mock.patch('validate.files.Path', autospec=True) +@mock.patch('pipeval.validate.files.Path', autospec=True) def test__path_exists__returns_true_for_existing_path(mock_path): mock_path.exists.return_value = True _path_exists(mock_path) -@mock.patch('validate.files.Path', autospec=True) +@mock.patch('pipeval.validate.files.Path', autospec=True) def test__path_exists__errors_for_non_existing_path(mock_path): mock_path.exists.return_value = False with pytest.raises(IOError): _path_exists(mock_path) -@mock.patch('validate.files.magic.from_file') -@mock.patch('validate.files.Path', autospec=True) +@mock.patch('pipeval.validate.files.magic.from_file') +@mock.patch('pipeval.validate.files.Path', autospec=True) def test__check_compressed__raises_warning_for_uncompressed_path(mock_path, mock_magic): mock_magic.return_value = 'text/plain' @@ -111,8 +111,8 @@ def test__check_compressed__raises_warning_for_uncompressed_path(mock_path, mock ('application/x-bzip2') ] ) -@mock.patch('validate.files.magic.from_file') -@mock.patch('validate.files.Path', autospec=True) +@mock.patch('pipeval.validate.files.magic.from_file') +@mock.patch('pipeval.validate.files.Path', autospec=True) def test__check_compressed__passes_compression_check(mock_path, mock_magic, compression_mime): mock_magic.return_value = compression_mime @@ -120,7 +120,7 @@ def test__check_compressed__passes_compression_check(mock_path, mock_magic, comp warnings.filterwarnings("error") _check_compressed(mock_path) -@mock.patch('validate.validators.bam.pysam') +@mock.patch('pipeval.validate.validators.bam.pysam') def test__validate_bam_file__empty_bam_file(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.head.return_value = iter([]) @@ -131,14 +131,14 @@ def test__validate_bam_file__empty_bam_file(mock_pysam): with pytest.raises(ValueError): _validate_bam_file(test_path) -@mock.patch('validate.validators.bam.Path', autospec=True) +@mock.patch('pipeval.validate.validators.bam.Path', autospec=True) def test__validate_bam_file__quickcheck_fails(mock_path): mock_path.exists.return_value = False with pytest.raises(ValueError): _validate_bam_file(mock_path) -@mock.patch('validate.validators.bam.pysam', autospec=True) +@mock.patch('pipeval.validate.validators.bam.pysam', autospec=True) def test__check_bam_index__no_index_file_error(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.check_index.side_effect = ValueError('no') @@ -147,7 +147,7 @@ def test__check_bam_index__no_index_file_error(mock_pysam): with pytest.raises(FileNotFoundError): _check_bam_index('/some/file') -@mock.patch('validate.validators.bam.pysam', autospec=True) +@mock.patch('pipeval.validate.validators.bam.pysam', autospec=True) def test__check_bam_index__index_check_pass(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.check_index.return_value = True @@ -155,7 +155,7 @@ def test__check_bam_index__index_check_pass(mock_pysam): _check_bam_index('/some/file') -@mock.patch('validate.validators.bam.pysam') +@mock.patch('pipeval.validate.validators.bam.pysam') def test__validate_sam_file__empty_sam_file(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.head.return_value = iter([]) @@ -166,7 +166,7 @@ def test__validate_sam_file__empty_sam_file(mock_pysam): with pytest.raises(ValueError): _validate_sam_file(test_path) -@mock.patch('validate.validators.sam.Path', autospec=True) +@mock.patch('pipeval.validate.validators.sam.Path', autospec=True) def test__validate_sam_file__quickcheck_fails(mock_path): mock_path.exists.return_value = False @@ -180,7 +180,7 @@ def test__validate_sam_file__quickcheck_fails(mock_path): ('ref') ] ) -@mock.patch('validate.validators.cram.pysam') +@mock.patch('pipeval.validate.validators.cram.pysam') def test__validate_cram_file__empty_cram_file(mock_pysam, test_reference): mock_alignment_file = Mock() mock_alignment_file.head.return_value = iter([]) @@ -191,14 +191,14 @@ def test__validate_cram_file__empty_cram_file(mock_pysam, test_reference): with pytest.raises(ValueError): _validate_cram_file(test_path, test_reference) -@mock.patch('validate.validators.cram.Path', autospec=True) +@mock.patch('pipeval.validate.validators.cram.Path', autospec=True) def test__validate_cram_file__quickcheck_fails(mock_path): mock_path.exists.return_value = False with pytest.raises(ValueError): _validate_cram_file(mock_path) -@mock.patch('validate.validators.cram.pysam', autospec=True) +@mock.patch('pipeval.validate.validators.cram.pysam', autospec=True) def test__check_cram_index__no_index_file_error(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.check_index.side_effect = ValueError('no') @@ -207,7 +207,7 @@ def test__check_cram_index__no_index_file_error(mock_pysam): with pytest.raises(FileNotFoundError): _check_cram_index('/some/file') -@mock.patch('validate.validators.cram.pysam', autospec=True) +@mock.patch('pipeval.validate.validators.cram.pysam', autospec=True) def test__check_cram_index__index_check_pass(mock_pysam): mock_alignment_file = Mock() mock_alignment_file.check_index.return_value = True @@ -215,14 +215,14 @@ def test__check_cram_index__index_check_pass(mock_pysam): _check_cram_index('/some/file') -@mock.patch('validate.validators.vcf.subprocess.call') +@mock.patch('pipeval.validate.validators.vcf.subprocess.call') def test__validate_vcf_file__fails_vcf_validation(mock_call): mock_call.return_value = 1 with pytest.raises(ValueError): _validate_vcf_file('some/file') -@mock.patch('validate.validators.vcf.subprocess.call') +@mock.patch('pipeval.validate.validators.vcf.subprocess.call') def test__validate_vcf_file__passes_vcf_validation(mock_call): mock_call.return_value = 0 @@ -241,10 +241,10 @@ def test__run_validate__passes_validation_no_files(): (OSError) ] ) -@mock.patch('validate.validate._detect_file_type_and_extension') -@mock.patch('validate.validate._validate_file') -@mock.patch('validate.validate._print_error') -@mock.patch('validate.validate.Path.resolve') +@mock.patch('pipeval.validate.validate._detect_file_type_and_extension') +@mock.patch('pipeval.validate.validate._validate_file') +@mock.patch('pipeval.validate.validate._print_error') +@mock.patch('pipeval.validate.validate.Path.resolve') def test___validation_worker__fails_with_failing_checks( mock_path_resolve, mock_print_error, @@ -260,8 +260,8 @@ def test___validation_worker__fails_with_failing_checks( assert not _validation_worker(test_path, test_args) -@mock.patch('validate.validate.Path.resolve', autospec=True) -@mock.patch('validate.validate.multiprocessing.Pool') +@mock.patch('pipeval.validate.validate.Path.resolve', autospec=True) +@mock.patch('pipeval.validate.validate.multiprocessing.Pool') def test__run_validate__passes_on_all_valid_files( mock_pool, mock_path_resolve @@ -274,8 +274,8 @@ def test__run_validate__passes_on_all_valid_files( run_validate(test_args) -@mock.patch('validate.validate.Path.resolve', autospec=True) -@mock.patch('validate.validate.multiprocessing.Pool') +@mock.patch('pipeval.validate.validate.Path.resolve', autospec=True) +@mock.patch('pipeval.validate.validate.multiprocessing.Pool') def test__run_validate__fails_with_failing_file( mock_pool, mock_path_resolve): @@ -290,7 +290,7 @@ def test__run_validate__fails_with_failing_file( run_validate(test_args) assert pytest_exit.value.code == expected_code -@mock.patch('validate.validate._path_exists') +@mock.patch('pipeval.validate.validate._path_exists') def test__validate_file__errors_with_invalid_extension(mock_path_exists): mock_path_exists.return_value = True @@ -305,10 +305,10 @@ def test__validate_file__errors_with_invalid_extension(mock_path_exists): ('file-bed') ] ) -@mock.patch('validate.validate._path_exists') -@mock.patch('validate.validate._check_compressed') -@mock.patch('validate.validate._validate_checksums') -@mock.patch('validate.validate.CHECK_FUNCTION_SWITCH') +@mock.patch('pipeval.validate.validate._path_exists') +@mock.patch('pipeval.validate.validate._check_compressed') +@mock.patch('pipeval.validate.validate._validate_checksums') +@mock.patch('pipeval.validate.validate.CHECK_FUNCTION_SWITCH') def test__validate_file__checks_compression( mock_check_function_switch, mock_validate_checksums, @@ -323,7 +323,7 @@ def test__validate_file__checks_compression( mock_check_compressed.assert_called_once() -@mock.patch('validate.validate.Path.resolve', autospec=True) +@mock.patch('pipeval.validate.validate.Path.resolve', autospec=True) def test__run_validate__fails_on_unresolvable_symlink(mock_path_resolve): expected_error = FileNotFoundError mock_path_resolve.side_effect = expected_error @@ -335,10 +335,10 @@ def test__run_validate__fails_on_unresolvable_symlink(mock_path_resolve): with pytest.raises(expected_error): run_validate(test_args) -@mock.patch('validate.validate.Path.resolve', autospec=True) -@mock.patch('validate.validate._detect_file_type_and_extension') -@mock.patch('validate.validate._validate_file') -@mock.patch('validate.validate._print_success') +@mock.patch('pipeval.validate.validate.Path.resolve', autospec=True) +@mock.patch('pipeval.validate.validate._detect_file_type_and_extension') +@mock.patch('pipeval.validate.validate._validate_file') +@mock.patch('pipeval.validate.validate._print_success') def test___validation_worker__passes_proper_validation( mock_print_success, mock_validate_file,