Coverage for lobster/tools/trlc/instruction.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-09-22 04:43 +0000

1# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report 

2# Copyright (C) 2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 

3# 

4# This program is free software: you can redistribute it and/or modify 

5# it under the terms of the GNU Affero General Public License as 

6# published by the Free Software Foundation, either version 3 of the 

7# License, or (at your option) any later version. 

8# 

9# This program is distributed in the hope that it will be useful, but 

10# WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 

12# Affero General Public License for more details. 

13# 

14# You should have received a copy of the GNU Affero General Public 

15# License along with this program. If not, see 

16# <https://www.gnu.org/licenses/>. 

17 

18from enum import Enum, auto 

19from dataclasses import dataclass 

20 

21 

22class InstructionType(Enum): 

23 CONSTANT_TEXT = auto() 

24 FIELD = auto() 

25 

26 

27@dataclass 

28class Instruction: 

29 """Specification how to convert a TRLC tuple field to string""" 

30 typ: InstructionType 

31 value: str 

32 

33 

34# pylint: disable=invalid-name 

35# The below functions use the CamelCase style instead of snake_case, so that the 

36# look and feel for the developer is that of using a class constructor, because the 

37# functions are essentially just wrappers around the constructor of the Instruction 

38# class. 

39 

40def ConstantInstruction(value: str) -> Instruction: 

41 """Convenience function for constant text.""" 

42 return Instruction(InstructionType.CONSTANT_TEXT, value) 

43 

44 

45def FieldInstruction(value: str) -> Instruction: 

46 """Convenience function for field.""" 

47 return Instruction(InstructionType.FIELD, value)