From a37af77eb2a343f9af72846af573eeec8adf1ab8 Mon Sep 17 00:00:00 2001 From: "Joshua C. Randall" Date: Wed, 29 Nov 2017 16:04:25 +0000 Subject: [PATCH] add test fixture to download example data --- gatkcwlgenerator/tests/test.py | 31 +++++++++++++++++++++++-------- test_requirements.txt | 4 +++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gatkcwlgenerator/tests/test.py b/gatkcwlgenerator/tests/test.py index 97b33a3..46bca99 100644 --- a/gatkcwlgenerator/tests/test.py +++ b/gatkcwlgenerator/tests/test.py @@ -13,6 +13,21 @@ import requests +""" +Download example data to be used in CWL integration tests +""" +@pytest.fixture(scope="module") +def example_data(): + if not os.path.isfile("cwl-example-data/chr22_cwl_test.cram"): + from six.moves.urllib.request import urlopen + import tarfile + print("Downloading and extracting cwl-example-data") + tgz = urlopen("https://cwl-example-data.cog.sanger.ac.uk/chr22_cwl_test.tgz") + tar = tarfile.open(fileobj=tgz, mode="r|gz") + tar.extractall(path="cwl-example-data") + tar.close() + tgz.close() + """ Runs the specified command and reports it as an AssertionError if it fails (can override this with expect_failure) @@ -127,22 +142,22 @@ def test_are_cwl_files_valid(self, version): if exceptions: raise AssertionError("Not all cwl files are valid:\n" + "\n\n".join(exceptions)) - def test_haplotype_caller(self, version): + def test_haplotype_caller(self, version, example_data): run_command("cwl-runner gatk_cmdline_tools/{}/cwl/HaplotypeCaller.cwl examples/HaplotypeCaller_inputs.yml".format(version)) # Test if the haplotype caller accepts all the correct types - def test_boolean_type(self, version): + def test_boolean_type(self, version, example_data): assert "ThreadEfficiencyMonitor" in run_haplotype_caller("monitorThreadEfficiency: True", version).stderr - def test_integers_type(self, version): + def test_integers_type(self, version, example_data): assert "42 data thread" in run_haplotype_caller("num_threads: 42", version, expect_failure=True).stderr - def test_string_type(self, version): + def test_string_type(self, version, example_data): assert "Specified name does not exist in input bam files" in \ run_haplotype_caller("sample_name: invalid_sample_name", version, expect_failure=True).stderr - def test_file_type(self, version): + def test_file_type(self, version, example_data): BQSR_arg = """ BQSR: class: File @@ -151,11 +166,11 @@ def test_file_type(self, version): assert "Bad input: The GATK report has an unknown/unsupported version in the header" in \ run_haplotype_caller(BQSR_arg, version, expect_failure=True).stderr - def test_enum_type(self, version): + def test_enum_type(self, version, example_data): assert "Strictness is LENIENT" in run_haplotype_caller("validation_strictness: LENIENT", version).stderr - def test_list_type(self, version): + def test_list_type(self, version, example_data): run_with_larger_intervals = run_haplotype_caller(extra_info="", version=version, filetext="analysis_type: HaplotypeCaller\n" + default_args + "\nintervals: [chr22:10591400-10591500, chr22:10591500-10591645]") - assert "Processing 246 bp from intervals" in run_with_larger_intervals.stderr \ No newline at end of file + assert "Processing 246 bp from intervals" in run_with_larger_intervals.stderr diff --git a/test_requirements.txt b/test_requirements.txt index 9c4cd94..6781ea0 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,3 +1,5 @@ pytest pytest-xdist -requests_cache \ No newline at end of file +requests_cache +six +cwlref-runner