Coverage for collectra/tasks/text.py: 88.89%

18 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 04:26 +0000

1"""Tasks for combining and transforming text artefacts.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any 

6 

7from collectra.tasks.text_output import TextOutputTask 

8from collectra.types.texts import Text 

9 

10__all__ = ["ConcatenateText"] 

11 

12 

13class ConcatenateText(TextOutputTask): 

14 """Join every input Text artefact into one Text artefact.""" 

15 

16 collective: bool = True 

17 

18 def __init__(self, name: str, separator: str = "\n", **kwargs: Any) -> None: 

19 super().__init__(name, separator=separator, **kwargs) 

20 

21 def input_type(self) -> type: 

22 return Text 

23 

24 def output_type(self) -> type: 

25 return Text 

26 

27 def run(self, *texts: Text) -> Text: 

28 for text in texts: 

29 if not isinstance(text, Text): 

30 raise TypeError(f"text must be Text, got {type(text)}") 

31 return self.text_output(self.separator.join(str(text()) for text in texts))