Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
V
vadere
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
110
Issues
110
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vadere
vadere
Commits
c6301548
Commit
c6301548
authored
Jul 16, 2018
by
Benedikt Kleinmeier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed "collect_coverage_data.py" to "collect_line_and_branch_coverage.py" and revised script.
parent
2eca4684
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
54 deletions
+77
-54
Tools/collect_coverage_data.py
Tools/collect_coverage_data.py
+0
-53
Tools/collect_line_and_branch_coverage.py
Tools/collect_line_and_branch_coverage.py
+76
-0
pom.xml
pom.xml
+1
-1
No files found.
Tools/collect_coverage_data.py
deleted
100644 → 0
View file @
2eca4684
# Collect HTML coverage reports (created by Maven's jacoco plugin) and average the result of all moduls.
# Use top-level pom.xml to look into correct subdirectories.
#
# Wach out: call this script from root directory of project. E.g.
#
# python Tools/my_script.py
import
xml.etree.ElementTree
as
ET
import
os
import
re
def
get_modules_from_pom_file
(
filename
=
"pom.xml"
):
xml_name_spaces
=
{
"default"
:
"http://maven.apache.org/POM/4.0.0"
}
xml_tree
=
ET
.
parse
(
filename
)
xml_root
=
xml_tree
.
getroot
()
exclude_list
=
[
"VadereAnnotation"
]
modules
=
xml_root
.
findall
(
"default:modules/default:module"
,
xml_name_spaces
)
module_names
=
[
module
.
text
for
module
in
modules
if
module
.
text
not
in
exclude_list
]
return
module_names
def
read_coverage_data_for_modules
(
module_names
):
module_to_coverage
=
dict
()
default_coverage_file
=
"target/site/coverage-reports/index.html"
for
module
in
module_names
:
coverage_path
=
os
.
path
.
join
(
module
,
default_coverage_file
)
with
open
(
coverage_path
,
"r"
)
as
file
:
coverage_report
=
file
.
read
()
regex_pattern
=
re
.
compile
(
r"Total.*?([0-9]{1,3})%"
)
match
=
regex_pattern
.
search
(
coverage_report
)
if
match
:
module_to_coverage
[
module
]
=
match
.
group
(
1
)
else
:
raise
Exception
(
"Coverage data not found for module: {}"
.
format
(
module
))
return
module_to_coverage
if
__name__
==
"__main__"
:
module_names
=
get_modules_from_pom_file
()
module_to_coverage
=
read_coverage_data_for_modules
(
module_names
)
print
(
module_to_coverage
)
Tools/collect_line_and_branch_coverage.py
0 → 100644
View file @
c6301548
# Extract line and branch coverage (in percentage) from HTML coverage reports
# which are created by Maven's jacoco plugin.
# Use top-level pom.xml to search in correct subdirectories.
#
# Wach out: call this script from root directory of project. E.g.
#
# python Tools/my_script.py
import
xml.etree.ElementTree
as
ET
import
os
import
re
def
get_modules_from_pom_file
(
filename
=
"pom.xml"
):
"""Return a list of submodules which where found in passed "pom.xml"."""
xml_name_spaces
=
{
"default"
:
"http://maven.apache.org/POM/4.0.0"
}
xml_tree
=
ET
.
parse
(
filename
)
xml_root
=
xml_tree
.
getroot
()
exclude_list
=
[
"./VadereAnnotation"
,
"./VadereGui"
]
modules
=
xml_root
.
findall
(
"default:modules/default:module"
,
xml_name_spaces
)
module_names
=
[
module
.
text
for
module
in
modules
if
module
.
text
not
in
exclude_list
]
return
module_names
def
extract_line_and_branch_coverage
(
module_names
):
"""Return a dictionary which maps module name to line and branch coverage tuple."""
module_to_coverage
=
dict
()
default_coverage_file
=
"target/site/coverage-reports/index.html"
for
module
in
module_names
:
coverage_path
=
os
.
path
.
join
(
module
,
default_coverage_file
)
with
open
(
coverage_path
,
"r"
)
as
file
:
coverage_report
=
file
.
read
()
regex_pattern
=
re
.
compile
(
r"Total.*?([0-9]{1,3})%.*?([0-9]{1,3})%"
)
match
=
regex_pattern
.
search
(
coverage_report
)
if
match
:
line_coverage
=
float
(
match
.
group
(
1
))
branch_coverage
=
float
(
match
.
group
(
2
))
module_to_coverage
[
module
]
=
(
line_coverage
,
branch_coverage
)
else
:
raise
Exception
(
"Coverage data not found for module: {}"
.
format
(
module
))
return
module_to_coverage
def
print_averaged_line_coverage
(
coverage_data
):
"""GitLab CI tools read out the stdout output of the build process. Therefore, print coverage info to stdout."""
total_modules
=
len
(
coverage_data
)
line_coverage_data
=
[
line_coverage
for
(
line_coverage
,
branch_coverage
)
in
coverage_data
.
values
()]
branch_coverage_data
=
[
branch_coverage
for
(
line_coverage
,
branch_coverage
)
in
coverage_data
.
values
()]
summed_line_coverage_data
=
sum
(
line_coverage_data
)
summed_branch_coverage_data
=
sum
(
branch_coverage_data
)
# By default, GitLab CI parses only integers.
averaged_line_coverage
=
int
(
round
(
summed_line_coverage_data
/
total_modules
,
0
))
averaged_branch_coverage
=
int
(
round
(
summed_branch_coverage_data
/
total_modules
,
0
))
print
(
"Line Coverage: Total {}%"
.
format
(
averaged_line_coverage
))
print
(
"Branch Coverage: {}%"
.
format
(
averaged_branch_coverage
))
if
__name__
==
"__main__"
:
module_names
=
get_modules_from_pom_file
()
module_to_coverage
=
extract_line_and_branch_coverage
(
module_names
)
print_averaged_line_coverage
(
module_to_coverage
)
pom.xml
View file @
c6301548
...
...
@@ -21,7 +21,7 @@
<module>
./VadereSimulator
</module>
<module>
./VadereState
</module>
<module>
./VadereUtils
</module>
<module>
VadereAnnotation
</module>
<module>
./
VadereAnnotation
</module>
</modules>
<!-- global dependencies! -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment