Coverage for src/chrisjen/reports.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-14 09:29 +0000

1"""Subclasses of Report. 

2 

3Contents: 

4 Summary: a short text summary of a project. 

5 

6""" 

7 

8from __future__ import annotations 

9 

10import dataclasses 

11from typing import TYPE_CHECKING 

12 

13from . import base, utilities 

14 

15if TYPE_CHECKING: 

16 from . import interface 

17 

18 

19@dataclasses.dataclass 

20class Summary(base.Report): 

21 """A short text summary of a project. 

22 

23 Args: 

24 contents: the text of the most recent summary. Defaults to `None`. 

25 

26 """ 

27 

28 def generate(self, project: interface.Project) -> str: 

29 """Generates the summary and stores it in `contents`. 

30 

31 Args: 

32 project: the project to summarize. 

33 

34 Returns: 

35 The text of the summary. 

36 

37 """ 

38 workflow = project.workflow 

39 paths = [ 

40 utilities.label_path(path) 

41 for path in (workflow.walk() if workflow is not None else [])] 

42 lines = [ 

43 f'project: {project.name}', 

44 f'id: {project.id}', 

45 f'paths: {"; ".join(paths) or "none"}', 

46 f'result: {project.result!r}', 

47 ] 

48 text = '\n'.join(lines) 

49 self.contents = text 

50 return text