Coverage for harbor_cli/output/table/anysequence.py: 86%

22 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-09 12:09 +0100

1from __future__ import annotations 

2 

3from typing import Any 

4from typing import Sequence 

5 

6from harborapi.models.base import BaseModel 

7from rich.table import Table 

8 

9from ._utils import get_table 

10 

11 

12class AnySequence(BaseModel): 

13 """Pydantic model that can contain a sequence of any type. 

14 

15 Used to render arbitrary sequences of objects as a table where 

16 each row consists of 1 column showing 1 value.""" 

17 

18 title: str = "Values" 

19 values: Sequence[Any] = [] 

20 

21 

22def anysequence_table(s: Sequence[AnySequence]) -> Table: 

23 """Renders an AnySequence as a table.""" 

24 # No title here I think...? 

25 table = get_table() 

26 try: 

27 title = s[0].title 

28 except IndexError: 

29 title = "Values" 

30 table.add_column(title) 

31 for idx, seq in enumerate(s): 

32 for item in seq.values: 32 ↛ 33line 32 didn't jump to line 33, because the loop on line 32 never started

33 table.add_row( 

34 item, 

35 ) 

36 if idx < len(s) - 1: # add a section between each sequence 

37 table.add_section() # type: ignore # it definitely has this method?! 

38 return table