Coverage for tests/unit/UCDB.py: 94%

61 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 01:05 +0000

1# ==================================================================================================================== # 

2# _____ ____ _ _ _ _ ____ ___ ____ # 

3# _ __ _ _| ____| _ \ / \ / \ | | | |/ ___|_ _/ ___| # 

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | | | | | | |\___ \ # 

5# | |_) | |_| | |___| |_| / ___ \ / ___ \ | |_| | |___ | | ___) | # 

6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)___/ \____|___|____/ # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2021-2022 Electronic Design Automation Abstraction (EDA²) # 

15# # 

16# Licensed under the Apache License, Version 2.0 (the "License"); # 

17# you may not use this file except in compliance with the License. # 

18# You may obtain a copy of the License at # 

19# # 

20# http://www.apache.org/licenses/LICENSE-2.0 # 

21# # 

22# Unless required by applicable law or agreed to in writing, software # 

23# distributed under the License is distributed on an "AS IS" BASIS, # 

24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

25# See the License for the specific language governing permissions and # 

26# limitations under the License. # 

27# # 

28# SPDX-License-Identifier: Apache-2.0 # 

29# ==================================================================================================================== # 

30# 

31"""Testcase for UCDB file conversions.""" 

32from pathlib import Path 

33from unittest import TestCase 

34 

35from pyEDAA.UCIS.UCDB import Parser 

36 

37 

38if __name__ == "__main__": # pragma: no cover 38 ↛ 39line 38 didn't jump to line 39 because the condition on line 38 was never true

39 print("ERROR: you called a testcase declaration file as an executable module.") 

40 print("Use: 'python -m unitest <testcase module>'") 

41 exit(1) 

42 

43 

44class ExportAndConvert(TestCase): 

45 def test_UCDB2Cobertura(self): 

46 ucdbPath = Path("tests/data/ucdb.xml") 

47 coberturaPath = Path("tests/data/cobertura.xml") 

48 

49 parser = Parser(ucdbPath, False) 

50 model = parser.getCoberturaModel() 

51 

52 coberturaContent = model.getXml() 

53 

54 self.assertIsNotNone(coberturaContent) 

55 

56 parser = Parser(ucdbPath, True) 

57 model = parser.getCoberturaModel() 

58 

59 coberturaContent = model.getXml() 

60 

61 self.assertIsNotNone(coberturaContent) 

62 

63 

64class CoverageValues(TestCase): 

65 def _parseUCDB(self, ucdbPath, mergeInstances): 

66 parser = Parser(ucdbPath, mergeInstances) 

67 model = parser.getCoberturaModel() 

68 model.getXml() 

69 

70 return parser, model 

71 

72 def test_multipleInstances(self): 

73 ucdbPath = Path("tests/data/ucdb000_multiple_instances.xml") 

74 

75 (parser, model) = self._parseUCDB( 

76 ucdbPath, 

77 False, 

78 ) 

79 

80 self.assertEqual(15, parser.statementsCount) 

81 self.assertEqual(14, parser.statementsCovered) 

82 self.assertEqual(7, model.linesValid) 

83 self.assertEqual(6, model.linesCovered) 

84 

85 (parser, model) = self._parseUCDB( 

86 ucdbPath, 

87 True, 

88 ) 

89 

90 self.assertEqual(9, parser.statementsCount) 

91 self.assertEqual(8, parser.statementsCovered) 

92 self.assertEqual(7, model.linesValid) 

93 self.assertEqual(6, model.linesCovered) 

94 

95 def test_allExcluded(self): 

96 ucdbPath = Path("tests/data/ucdb001_all_excluded.xml") 

97 

98 (parser, model) = self._parseUCDB( 

99 ucdbPath, 

100 False, 

101 ) 

102 

103 self.assertEqual(0, parser.statementsCount) 

104 self.assertEqual(0, parser.statementsCovered) 

105 self.assertEqual(0, model.linesValid) 

106 self.assertEqual(0, model.linesCovered) 

107 

108 (parser, model) = self._parseUCDB( 

109 ucdbPath, 

110 True, 

111 ) 

112 

113 self.assertEqual(0, parser.statementsCount) 

114 self.assertEqual(0, parser.statementsCovered) 

115 self.assertEqual(0, model.linesValid) 

116 self.assertEqual(0, model.linesCovered) 

117 

118 def test_partiallyExcluded(self): 

119 ucdbPath = Path("tests/data/ucdb002_partially_excluded.xml") 

120 

121 (parser, model) = self._parseUCDB( 

122 ucdbPath, 

123 False, 

124 ) 

125 

126 self.assertEqual(5, parser.statementsCount) 

127 self.assertEqual(4, parser.statementsCovered) 

128 self.assertEqual(5, model.linesValid) 

129 self.assertEqual(4, model.linesCovered) 

130 

131 (parser, model) = self._parseUCDB( 

132 ucdbPath, 

133 True, 

134 ) 

135 

136 self.assertEqual(5, parser.statementsCount) 

137 self.assertEqual(4, parser.statementsCovered) 

138 self.assertEqual(5, model.linesValid) 

139 self.assertEqual(4, model.linesCovered)