Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### General

- Fixes bug in `test-datasets list` related to broken rich import ([#4477](https://github.com/nf-core/tools/pull/4477))

### Linting

- Warn if `manifest.diagram` is not set, and fail if it is not a relative path to an existing image file ([#4460](https://github.com/nf-core/tools/pull/4460))
Expand Down
9 changes: 5 additions & 4 deletions nf_core/test_datasets/list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os

import rich
from rich.console import Console
from rich.table import Table

from nf_core.test_datasets.test_datasets_utils import (
IGNORED_FILE_PREFIXES,
Expand All @@ -14,7 +15,7 @@
)
from nf_core.utils import rich_force_colors

stdout = rich.console.Console(force_terminal=rich_force_colors())
stdout = Console(force_terminal=rich_force_colors())
log = logging.getLogger(__name__)


Expand All @@ -26,7 +27,7 @@ def list_dataset_branches() -> None:
"""
remote_branches = get_remote_branch_names()

table = rich.table.Table()
table = Table()
table.add_column("Test-Dataset Branches")
for b in remote_branches:
table.add_row(b)
Expand Down Expand Up @@ -71,7 +72,7 @@ def list_datasets(
stdout.print(os.linesep.join(out))

else:
table = rich.table.Table()
table = Table()
table.add_column("File", overflow="fold")

for el in out:
Expand Down
8 changes: 4 additions & 4 deletions nf_core/test_datasets/search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

import rich.console
import rich.table
from rich.console import Console
from rich.table import Table

from nf_core.test_datasets.test_datasets_utils import (
IGNORED_FILE_PREFIXES,
Expand All @@ -14,7 +14,7 @@
)
from nf_core.utils import rich_force_colors

stdout = rich.console.Console(force_terminal=rich_force_colors())
stdout = Console(force_terminal=rich_force_colors())
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -56,7 +56,7 @@ def search_datasets(
stdout.print(create_pretty_nf_path(selection, branch == MODULES_BRANCH_NAME))
stdout.print(create_download_url(branch, selection))
else:
table = rich.table.Table(show_header=False)
table = Table(show_header=False)
table.add_column("")
table.add_column("", overflow="fold")
table.add_row("File Name:", selection)
Expand Down
4 changes: 4 additions & 0 deletions nf_core/test_datasets/test_datasets_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_remote_branch_names() -> list[str]:
List all branch names on the remote github repository for test-datasets for pipelines or modules.
"""
try:
branches = [] # default to return, if exception is raised
url = GithubApiEndpoints().get_pipelines_list_url()
response = requests.get(url)
resp_json = response.json()
Expand Down Expand Up @@ -189,6 +190,9 @@ def get_or_prompt_branch(maybe_branch: str) -> tuple[str, list[str]]:

else:
all_branches = get_remote_branch_names()
if not all_branches:
log.error("Branch information for test-datasets could not be fetched.")
return ("", [])

# Find pipeline / modules root directory
base_dir: Path = determine_base_dir()
Expand Down
76 changes: 76 additions & 0 deletions tests/test_datasets/test_test_datasets_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import unittest

import responses

from nf_core.test_datasets.list import list_datasets
from nf_core.test_datasets.test_datasets_utils import (
MODULES_BRANCH_NAME,
GithubApiEndpoints,
)


def mock_get_pipelines_request(rsps: responses.RequestsMock) -> None:
"""
Mock request to list pipelines
"""
url = "https://raw.githubusercontent.com/nf-core/website/refs/heads/main/public/pipeline_names.json"
resp_json = {
"pipeline": [
"airrflow",
"ampliseq",
"atacseq",
"bacass",
"bactmap",
]
}

# add dummy json response at given url for get request
rsps.add(method="GET", url=url, json=resp_json, status=200)


def mock_gh_api_request(rsps: responses.RequestsMock, branch=MODULES_BRANCH_NAME) -> None:
"""
Mock request to list files in a github branch
"""
gh_urls = GithubApiEndpoints(gh_orga="nf-core", gh_repo="test-datasets")

# output from requets for modules files
resp_json = {
"sha": "bd061d2421282afa00ae1c83b43151fda0e046b7",
"url": "https://api.github.com/repos/nf-core/test-datasets/git/trees/bd061d2421282afa00ae1c83b43151fda0e046b7",
"tree": [
{
"path": "README.md",
"type": "blob",
"url": "https://api.github.com/repos/nf-core/test-datasets/git/blobs/1ebf7eb543cbb09b875a8a1ef50e107c5cfa8310",
},
{
"path": "assemblies",
"type": "tree",
"url": "https://api.github.com/repos/nf-core/test-datasets/git/trees/fdf5797e56e51b5e0bbd583e8499ef660204a194",
},
{
"path": "assemblies/MEGAHIT-test_minigut.contigs.fa.gz",
"type": "blob",
"url": "https://api.github.com/repos/nf-core/test-datasets/git/blobs/83185a06b64158a5ea144b8a5a4c26499cd3f585",
},
{
"path": "samplesheets/assembly_samplesheet.csv",
"type": "blob",
"url": "https://api.github.com/repos/nf-core/test-datasets/git/blobs/0b86b23c3f901103a1a72ec9953a67623cd90e3e",
},
],
}

# Add dummy json response at gh url with ok status code
rsps.add(method="GET", url=gh_urls.get_remote_tree_url_for_branch(branch), json=resp_json, status=200)


class TestTestDatasetsList(unittest.TestCase):
def test_list_datasets(self):
with responses.RequestsMock() as rsps:
branch = MODULES_BRANCH_NAME
mock_get_pipelines_request(rsps)
mock_gh_api_request(rsps, branch=branch)
res = list_datasets(maybe_branch=branch)
assert res is None
Loading