-
Notifications
You must be signed in to change notification settings - Fork 223
Add tests for nf-core subworkflows create-test-yml
#2219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+116
−14
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e40458
Test subworkflow yml dumper
Aratz 488b25e
Test create_test_file_dict
Aratz c404c87
Test get_md5_sums
Aratz 4db1679
Test scrape_workflow_entry_points
Aratz e7bda6d
Test check_inputs
Aratz 36aab38
Update changelog
Aratz a661087
Fix linting
Aratz 41837df
Switch from `os.path` to `Path`
Aratz ef4738b
Switch from `os.path` to `Path` for modules too
Aratz 8d81588
Lint code (isort, black)
Aratz 20f82c0
Fix changelog
Aratz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,96 @@ | ||
| import os | ||
| from pathlib import Path | ||
| from unittest import mock | ||
|
|
||
Aratz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import pytest | ||
|
|
||
| import nf_core.subworkflows | ||
|
|
||
| from ..utils import with_temporary_folder | ||
Aratz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @with_temporary_folder | ||
| def test_subworkflows_custom_yml_dumper(self, out_dir): | ||
| """Try to create a yml file with the custom yml dumper""" | ||
| yml_output_path = Path(out_dir, "test.yml") | ||
| meta_builder = nf_core.subworkflows.SubworkflowTestYmlBuilder( | ||
| subworkflow="test/tool", | ||
| directory=self.pipeline_dir, | ||
| test_yml_output_path=yml_output_path, | ||
| no_prompts=True, | ||
| ) | ||
| meta_builder.test_yml_output_path = yml_output_path | ||
| meta_builder.tests = [{"testname": "myname"}] | ||
| meta_builder.print_test_yml() | ||
| assert Path(yml_output_path).is_file() | ||
|
|
||
|
|
||
| @with_temporary_folder | ||
| def test_subworkflows_test_file_dict(self, test_file_dir): | ||
| """Create dict of test files and create md5 sums""" | ||
| meta_builder = nf_core.subworkflows.SubworkflowTestYmlBuilder( | ||
| subworkflow="test/tool", | ||
| directory=self.pipeline_dir, | ||
| test_yml_output_path="./", | ||
| no_prompts=True, | ||
| ) | ||
| with open(Path(test_file_dir, "test_file.txt"), "w") as fh: | ||
| fh.write("this line is just for testing") | ||
| test_files = meta_builder.create_test_file_dict(test_file_dir) | ||
| assert len(test_files) == 1 | ||
| assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" | ||
|
|
||
|
|
||
| @with_temporary_folder | ||
| def test_subworkflows_create_test_yml_get_md5(self, test_file_dir): | ||
| """Get md5 sums from a dummy output""" | ||
| meta_builder = nf_core.subworkflows.SubworkflowTestYmlBuilder( | ||
| subworkflow="test/tool", | ||
| directory=self.pipeline_dir, | ||
| test_yml_output_path="./", | ||
| no_prompts=True, | ||
| ) | ||
| with open(Path(test_file_dir, "test_file.txt"), "w") as fh: | ||
| fh.write("this line is just for testing") | ||
| test_files = meta_builder.get_md5_sums( | ||
| command="dummy", | ||
| results_dir=test_file_dir, | ||
| results_dir_repeat=test_file_dir, | ||
| ) | ||
| assert test_files[0]["md5sum"] == "2191e06b28b5ba82378bcc0672d01786" | ||
|
|
||
|
|
||
| def test_subworkflows_create_test_yml_entry_points(self): | ||
| """Test extracting test entry points from a main.nf file""" | ||
| subworkflow = "test_subworkflow" | ||
| meta_builder = nf_core.subworkflows.SubworkflowTestYmlBuilder( | ||
| subworkflow=f"{subworkflow}/test", | ||
| directory=self.pipeline_dir, | ||
| test_yml_output_path="./", | ||
| no_prompts=True, | ||
| ) | ||
| meta_builder.subworkflow_test_main = Path( | ||
| self.nfcore_modules, "tests", "subworkflows", "nf-core", subworkflow, "main.nf" | ||
| ) | ||
| meta_builder.scrape_workflow_entry_points() | ||
| assert meta_builder.entry_points[0] == f"test_{subworkflow}" | ||
|
|
||
|
|
||
| def test_subworkflows_create_test_yml_check_inputs(self): | ||
| """Test the check_inputs() function - raise UserWarning because test.yml exists""" | ||
| cwd = os.getcwd() | ||
| os.chdir(self.nfcore_modules) | ||
| subworkflow = "test_subworkflow" | ||
| meta_builder = nf_core.subworkflows.SubworkflowTestYmlBuilder( | ||
| subworkflow=f"{subworkflow}", | ||
| directory=self.pipeline_dir, | ||
| test_yml_output_path="./", | ||
| no_prompts=True, | ||
| ) | ||
| meta_builder.subworkflow_test_main = Path( | ||
| self.nfcore_modules, "tests", "subworkflows", "nf-core", subworkflow, "main.nf" | ||
| ) | ||
| with pytest.raises(UserWarning) as excinfo: | ||
| meta_builder.check_inputs() | ||
| os.chdir(cwd) | ||
| assert "Test YAML file already exists!" in str(excinfo.value) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.