Coverage for  / usr / local / lib / python3.14 / site-packages / twinpad_backend / config_manager / utils.py: 85%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-11 15:40 +0000

1from openpyxl.cell import Cell, MergedCell 

2 

3 

4def read_boolean_cell(cell: Cell | MergedCell, default_value: bool) -> bool: 

5 """ 

6 Reads an excel cell and turns it into a boolean. Correct values are 'Yes', 'No' (any capitalisation) or an empty cell. 

7 

8 :param cell: Excel cell to read. 

9 :type cell: Cell | MergedCell 

10 :param default_value: Value to return if the cell is empty 

11 :type default_value: bool 

12 

13 :raises ValueError: If cell is neither empty nor a variatin of 'Yes' or 'No'. 

14 

15 :returns: True if variation of 'Yes', False if variation of 'No' or :param default_value: otherwise. 

16 :rtype: bool 

17 """ 

18 if cell.value is None: 

19 return default_value 

20 cell_lower = cell.value.lower() 

21 if cell_lower == "yes": 

22 return True 

23 if cell_lower == "no": 

24 return False 

25 raise ValueError(f"Cell value is invalid: {cell_lower}") 

26 

27 

28def is_line_empty(row: tuple[Cell | MergedCell, ...]): 

29 """ 

30 Indicates whether excel line (row or column) is empty or not. 

31 

32 :param row: Excel row/column to check. 

33 :type row: tuple[Cell | MergedCell, ...] 

34 

35 :return: True is the row/column is empty, otherwise, False. 

36 :rtype: bool 

37 """ 

38 row_values = list(cell.value for cell in row if cell.value is not None) 

39 return len(row_values) == 0