|
1 | 1 | """Some tests covering the bump_version code.""" |
2 | 2 |
|
3 | 3 | import logging |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import yaml |
6 | 7 |
|
7 | 8 | import nf_core.pipelines.bump_version |
8 | 9 | import nf_core.utils |
| 10 | +from nf_core.pipelines.lint_utils import run_prettier_on_file |
9 | 11 |
|
10 | 12 | from ..test_pipelines import TestPipelines |
11 | 13 |
|
@@ -104,3 +106,43 @@ def test_bump_pipeline_version_in_snapshot_no_version(self): |
104 | 106 | self.caplog.set_level(logging.INFO) |
105 | 107 | nf_core.pipelines.bump_version.bump_pipeline_version(self.pipeline_obj, "1.1.0") |
106 | 108 | assert "Could not find version number in " in self.caplog.text |
| 109 | + |
| 110 | + def test_bump_pipeline_version_nf_core_yml_prettier(self): |
| 111 | + """Test that lists in .nf-core.yml have correct formatting after version bump.""" |
| 112 | + |
| 113 | + nf_core_yml_path = Path(self.pipeline_dir / ".nf-core.yml") |
| 114 | + |
| 115 | + # Add a list to the .nf-core.yml file to test list indentation |
| 116 | + with open(nf_core_yml_path) as fh: |
| 117 | + nf_core_yml = yaml.safe_load(fh) |
| 118 | + |
| 119 | + # Add a lint section with a list |
| 120 | + if "lint" not in nf_core_yml: |
| 121 | + nf_core_yml["lint"] = {} |
| 122 | + nf_core_yml["lint"]["files_exist"] = ["assets/multiqc_config.yml", "conf/base.config"] |
| 123 | + |
| 124 | + with open(nf_core_yml_path, "w") as fh: |
| 125 | + yaml.dump(nf_core_yml, fh, default_flow_style=False) |
| 126 | + |
| 127 | + # Run prettier to ensure the file is properly formatted before the test |
| 128 | + run_prettier_on_file(nf_core_yml_path) |
| 129 | + |
| 130 | + # Bump the version |
| 131 | + nf_core.pipelines.bump_version.bump_pipeline_version(self.pipeline_obj, "1.1.0") |
| 132 | + |
| 133 | + # Read the file before prettier to store it |
| 134 | + with open(nf_core_yml_path) as fh: |
| 135 | + content_before = fh.read() |
| 136 | + |
| 137 | + # Run prettier on the file |
| 138 | + run_prettier_on_file(nf_core_yml_path) |
| 139 | + |
| 140 | + # Read the file after prettier |
| 141 | + with open(nf_core_yml_path) as fh: |
| 142 | + content_after = fh.read() |
| 143 | + |
| 144 | + # If prettier changed the file, the formatting was wrong |
| 145 | + assert content_before == content_after, ( |
| 146 | + "The .nf-core.yml file formatting changed after running prettier. " |
| 147 | + "This means the YAML dumping did not use correct indentation settings." |
| 148 | + ) |
0 commit comments