Coverage for tests/unit/UCDB.py: 94%
61 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 01:09 +0000
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-15 01:09 +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
35from pyEDAA.UCIS.UCDB import Parser
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)
44class ExportAndConvert(TestCase):
45 def test_UCDB2Cobertura(self):
46 ucdbPath = Path("tests/data/ucdb.xml")
47 coberturaPath = Path("tests/data/cobertura.xml")
49 parser = Parser(ucdbPath, False)
50 model = parser.getCoberturaModel()
52 coberturaContent = model.getXml()
54 self.assertIsNotNone(coberturaContent)
56 parser = Parser(ucdbPath, True)
57 model = parser.getCoberturaModel()
59 coberturaContent = model.getXml()
61 self.assertIsNotNone(coberturaContent)
64class CoverageValues(TestCase):
65 def _parseUCDB(self, ucdbPath, mergeInstances):
66 parser = Parser(ucdbPath, mergeInstances)
67 model = parser.getCoberturaModel()
68 model.getXml()
70 return parser, model
72 def test_multipleInstances(self):
73 ucdbPath = Path("tests/data/ucdb000_multiple_instances.xml")
75 (parser, model) = self._parseUCDB(
76 ucdbPath,
77 False,
78 )
80 self.assertEqual(15, parser.statementsCount)
81 self.assertEqual(14, parser.statementsCovered)
82 self.assertEqual(7, model.linesValid)
83 self.assertEqual(6, model.linesCovered)
85 (parser, model) = self._parseUCDB(
86 ucdbPath,
87 True,
88 )
90 self.assertEqual(9, parser.statementsCount)
91 self.assertEqual(8, parser.statementsCovered)
92 self.assertEqual(7, model.linesValid)
93 self.assertEqual(6, model.linesCovered)
95 def test_allExcluded(self):
96 ucdbPath = Path("tests/data/ucdb001_all_excluded.xml")
98 (parser, model) = self._parseUCDB(
99 ucdbPath,
100 False,
101 )
103 self.assertEqual(0, parser.statementsCount)
104 self.assertEqual(0, parser.statementsCovered)
105 self.assertEqual(0, model.linesValid)
106 self.assertEqual(0, model.linesCovered)
108 (parser, model) = self._parseUCDB(
109 ucdbPath,
110 True,
111 )
113 self.assertEqual(0, parser.statementsCount)
114 self.assertEqual(0, parser.statementsCovered)
115 self.assertEqual(0, model.linesValid)
116 self.assertEqual(0, model.linesCovered)
118 def test_partiallyExcluded(self):
119 ucdbPath = Path("tests/data/ucdb002_partially_excluded.xml")
121 (parser, model) = self._parseUCDB(
122 ucdbPath,
123 False,
124 )
126 self.assertEqual(5, parser.statementsCount)
127 self.assertEqual(4, parser.statementsCovered)
128 self.assertEqual(5, model.linesValid)
129 self.assertEqual(4, model.linesCovered)
131 (parser, model) = self._parseUCDB(
132 ucdbPath,
133 True,
134 )
136 self.assertEqual(5, parser.statementsCount)
137 self.assertEqual(4, parser.statementsCovered)
138 self.assertEqual(5, model.linesValid)
139 self.assertEqual(4, model.linesCovered)