Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Robot test reporter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTI Tools
Robot test reporter
Commits
c46f0478
Commit
c46f0478
authored
4 years ago
by
brydenf
Browse files
Options
Downloads
Patches
Plain Diff
WIP to include pie chart in separate work sheet
Signed-off-by:
Frank Bryden
<
Frank.Bryden@etsi.org
>
parent
79519070
No related branches found
No related tags found
1 merge request
!1
Charts
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
parse_test_results.py
+7
-2
7 additions, 2 deletions
parse_test_results.py
write_excel.py
+52
-3
52 additions, 3 deletions
write_excel.py
with
59 additions
and
5 deletions
parse_test_results.py
+
7
−
2
View file @
c46f0478
...
...
@@ -19,16 +19,15 @@ class TestOutputParser:
"""
def
__init__
(
self
,
input_file
,
output_file
):
self
.
test_entries
=
[]
self
.
load_file
(
input_file
)
self
.
api
=
""
self
.
output_file
=
output_file
self
.
robot_file_contents
=
""
self
.
load_file
(
input_file
)
def
load_file
(
self
,
fname
):
"""
Load xml file
"""
with
open
(
fname
,
"
r
"
,
encoding
=
"
utf8
"
)
as
robot_file
:
self
.
robot_file_contents
=
robot_file
.
read
()
...
...
@@ -40,6 +39,7 @@ class TestOutputParser:
"""
Run parser, extracting all info to create the test entries
"""
soup
=
BeautifulSoup
(
self
.
robot_file_contents
,
"
lxml
"
)
# Suite information
...
...
@@ -60,6 +60,11 @@ class TestOutputParser:
excel_writer
=
ExcelWriter
(
self
.
output_file
)
for
entry
in
self
.
test_entries
:
excel_writer
.
write_test_entry
(
entry
)
# Write chart
excel_writer
.
write_pie_chart
()
# And finally, save the work book
excel_writer
.
save
()
def
create_test_entry
(
self
,
xml_obj
):
...
...
This diff is collapsed.
Click to expand it.
write_excel.py
+
52
−
3
View file @
c46f0478
...
...
@@ -6,6 +6,7 @@ from openpyxl import Workbook, load_workbook
from
openpyxl.utils
import
get_column_letter
from
openpyxl.styles
import
Font
from
openpyxl.styles.fills
import
PatternFill
from
openpyxl.chart
import
PieChart
,
Reference
class
ExcelWriter
:
"""
...
...
@@ -15,9 +16,9 @@ class ExcelWriter:
PASS_COL
=
"
00FF00
"
FAIL_COL
=
"
FF0000
"
def
__init__
(
self
,
output_file
):
self
.
output_file
=
output_file
self
.
work_book
=
self
.
get_workbook
()
self
.
work_sheet
=
self
.
work_book
.
active
self
.
output_file
=
output_file
def
get_entry_with_id
(
self
,
test_id
):
"""
...
...
@@ -42,13 +43,13 @@ class ExcelWriter:
for
cell
in
self
.
work_sheet
[
"
A
"
]:
if
cell
.
value
is
None
:
return
cell
.
row
return
1
return
cell
.
row
+
1
def
write_test_entry
(
self
,
test_entry
):
"""
Write a test entry to the work_sheet
"""
existing_entry_row
=
self
.
get_entry_with_id
(
test_entry
.
id
)
existing_entry_row
=
self
.
get_entry_with_id
(
test_entry
.
test_
id
)
last_row
=
self
.
get_last_row
()
# Use the above two values to pick a row
entry_row
=
existing_entry_row
if
existing_entry_row
!=
-
1
else
last_row
...
...
@@ -78,6 +79,54 @@ class ExcelWriter:
work_book
=
Workbook
()
init_workbook
(
work_book
)
return
work_book
def
get_chart_work_sheet
(
self
):
"""
Returns work sheet where charts will be drawn to.
Creates if does not exist
"""
try
:
chart_work_sheet
=
self
.
work_book
[
"
charts
"
]
return
chart_work_sheet
except
KeyError
:
return
self
.
work_book
.
create_sheet
(
"
charts
"
)
def
write_pie_chart_data
(
self
):
"""
Writes pie chart data (the charts sheet) required to construct the pie chart later
"""
chart_work_sheet
=
self
.
get_chart_work_sheet
()
# Get data from main work sheet
last_row
=
self
.
get_last_row
()
data
=
Reference
(
self
.
work_sheet
,
min_col
=
3
,
max_col
=
3
,
min_row
=
2
,
max_row
=
last_row
)
# Construct pie chart
pie
=
PieChart
()
pie
.
add_data
(
data
,
titles_from_data
=
True
)
#pie.set_categories(labels)
pie
.
title
=
"
PASS/FAIL Distribution
"
chart_work_sheet
.
add_chart
(
pie
,
"
A1
"
)
def
write_pie_chart
(
self
):
"""
Writes a pie chart showing PASS/FAIL stats.
Writes the chart to a separate work sheet.
"""
chart_work_sheet
=
self
.
get_chart_work_sheet
()
# Get data from main work sheet
last_row
=
self
.
get_last_row
()
data
=
Reference
(
self
.
work_sheet
,
min_col
=
3
,
max_col
=
3
,
min_row
=
2
,
max_row
=
last_row
)
# Construct pie chart
pie
=
PieChart
()
pie
.
add_data
(
data
,
titles_from_data
=
True
)
#pie.set_categories(labels)
pie
.
title
=
"
PASS/FAIL Distribution
"
chart_work_sheet
.
add_chart
(
pie
,
"
A1
"
)
def
save
(
self
):
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment