Skip to content

Commit

Permalink
run ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblair committed May 17, 2024
1 parent 58d954b commit 36c0319
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
12 changes: 7 additions & 5 deletions nireports/assembler/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def index(self, config):
)
reportlets.append(rlet)
except ReportletException as e:
exceptions.append(e)
exceptions.append(e)
list_combos = subrep_cfg.get("nested", False)
else:
# Do not use dictionary for queries, as we need to preserve ordering
Expand Down Expand Up @@ -411,10 +411,12 @@ def index(self, config):

# Filter out empty reportlets
reportlets = [r for r in reportlets if not r.is_empty()]

# When support python < 3.11 dropped we can use ExceptionGroups
if exceptions:
raise NiReportsException(('There were errors generating report {self}', *exceptions))
raise NiReportsException(
("There were errors generating report {self}", *exceptions)
)

if reportlets:
sub_report = SubReport(
Expand Down Expand Up @@ -457,9 +459,9 @@ def process_plugins(self, config, metadata=None):
)
],
)

def __str__(self):
return f'<Report {self.title}>'
return f"<Report {self.title}>"

Check warning on line 464 in nireports/assembler/report.py

View check run for this annotation

Codecov / codecov/patch

nireports/assembler/report.py#L464

Added line #L464 was not covered by tests

def generate_report(self):
"""Once the Report has been indexed, the final HTML can be generated"""
Expand Down
1 change: 0 additions & 1 deletion nireports/assembler/reportlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat
if config.get("required", False) and self.is_empty():
raise RequiredReportletException(config)


def is_empty(self):
"""Determine whether the reportlet has no components."""
return len(self.components) == 0
15 changes: 7 additions & 8 deletions nireports/assembler/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from nireports.assembler import data
from nireports.assembler.report import Report
from nireports.exceptions import NiReportsException, RequiredReportletException
from nireports.exceptions import NiReportsException, RequiredReportletException

summary_meta = {
"Summary": {
Expand Down Expand Up @@ -139,21 +139,20 @@ def test_report2(bids_sessions):
subject="01",
)

def test_missing_reportlet(
test_report1,
bids_sessions
):

def test_missing_reportlet(test_report1, bids_sessions):
out_dir = tempfile.mkdtemp()
report = test_report1
settings = yaml.safe_load(data.load.readable("default.yml").read_text())
settings["root"] = str(Path(bids_sessions) / "nireports")
settings["out_dir"] = str(Path(out_dir) / "nireports")
settings["run_uuid"] = "fakeuuid"
settings['sections'][0]['reportlets'][0]['required'] = True
settings['sections'][0]['reportlets'][0]['bids'] = {'datatype': 'fake'}
with pytest.raises(NiReportsException, match='No content found'):
settings["sections"][0]["reportlets"][0]["required"] = True
settings["sections"][0]["reportlets"][0]["bids"] = {"datatype": "fake"}
with pytest.raises(NiReportsException, match="No content found"):
report.index(settings)


@pytest.mark.parametrize(
"orderings,expected_entities,expected_value_combos",
[
Expand Down
6 changes: 5 additions & 1 deletion nireports/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class NiReportsException(Exception):
pass


class ReportletException(NiReportsException):
pass


class RequiredReportletException(ReportletException):
def __init__(self, config):
self.args = (f'No content found while generated reportlet listed as required with the following config: {config}',)
self.args = (
f"No content found while generated reportlet listed as required with the following config: {config}",
)

0 comments on commit 36c0319

Please sign in to comment.