-
Notifications
You must be signed in to change notification settings - Fork 18
/
generate_xlsx_report.py
905 lines (798 loc) · 36.9 KB
/
generate_xlsx_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
#!/usr/bin/python
#################################################################
# Use and redistribution is source and binary forms is permitted
# subject to the OMG-DDS INTEROPERABILITY TESTING LICENSE found
# at the following URL:
#
# https://github.com/omg-dds/dds-rtps/blob/master/LICENSE.md
#
#################################################################
import argparse
import junitparser
import lxml
import pathlib
import xlsxwriter
import sys
import os
import re
import datetime
from rtps_test_utilities import log_message
import test_suite
class XlxsReportArgumentParser:
"""Class that parse the arguments of the application."""
def argument_parser():
parser = argparse.ArgumentParser(
description='Creation of an xlsx report of interoperability of products compliant '
'with OMG DDS-RTPS standard. This script generates automatically '
'the verification between two shape_main executables. '
'It also generates an XML report in JUnit format.',
add_help=True)
gen_opts = parser.add_argument_group(title='general options')
gen_opts.add_argument('-o', '--output',
default=None,
required=True,
type=str,
metavar='output',
help='Path to the output file. It should have an xlsx file extension')
gen_opts.add_argument('-i', '--input',
default=None,
required=True,
type=str,
metavar='input',
help='Path to the input file. It should have an xml file extension')
return parser
class ProductUtils:
@staticmethod
def get_company_name(product:str) -> str:
"""Returns the company name"""
if 'connext' in product.lower():
return 'Real-Time Innovations (RTI)'
elif 'opendds' in product.lower():
return 'OpenDDS Foundation'
elif 'coredx' in product.lower():
return 'Twin Oaks Computing, Inc'
elif 'intercom' in product.lower():
return 'Kongsberg'
elif 'fastdds' in product.lower():
return 'eProsima'
elif 'dust' in product.lower():
return 'S2E Software Systems'
else:
raise RuntimeError('Impossible to get company name: ' + product)
@staticmethod
def get_product_name(product:str) -> str:
"""Returns a beautified product name and version"""
# set the beautified name and version
if 'connext' in product.lower():
return 'Connext DDS ' + re.search(r'([\d.]+)', product).group(1)
elif 'opendds' in product.lower():
return 'OpenDDS ' + re.search(r'([\d.]+)', product).group(1)
elif 'coredx' in product.lower():
return 'CoreDX DDS ' + re.search(r'([\d.]+)', product).group(1)
elif 'intercom' in product.lower():
return 'InterCOM DDS ' + re.search(r'([\d.]+)', product).group(1)
elif 'fastdds' in product.lower():
return 'FastDDS ' + re.search(r'([\d.]+)', product).group(1)
elif 'dust_dds' in product.lower():
return 'Dust DDS ' + re.search(r'([\d.]+)', product).group(1)
else:
raise RuntimeError('Impossible to get product name: ' + product)
class JunitAggregatedData:
"""
Class that contains the JUnit aggregated data as a tuple of 2 integers
[tests_passed, total_tests]. This identifies one cell in the summary
table that shows the product and the amount of tests passed and total.
"""
data: tuple[int,int] # [tests_passed, total_tests]
def __init__(self, passed_tests: int, total_tests: int) -> None:
self.data = [passed_tests, total_tests]
def get_passed_tests(self):
return self.data[0]
def get_total_tests(self):
return self.data[1]
def __str__(self) -> str:
return f'({self.data[0]}, {self.data[1]})'
class JunitTestCaseAggregatedData:
"""
Class that contains the JUnit aggregated data per test case. The table
generated from this class shows the tests passed per product (as
Publisher or Subscriber) and with all other products (as Subscribers or
Publishers, the opposite).
This tuple is composed by 2 strings that identifies the other product
(Publisher or Subscriber), the test name and whether the test was
successful or not.
"""
# [publisher or subscriber name, test_name, passed_tests]
data: tuple[str,str,bool] = None
def __init__(self, product: str, test_name: str, passed: bool) -> None:
self.data = (product, test_name, passed)
def get_product_name(self):
return self.data[0]
def get_test_name(self):
return self.data[1]
def get_passed(self):
return self.data[2]
def __str__(self) -> str:
return f'{self.data}'
class JunitData:
"""
This class represents all extracted data from the JUnit results. This is the
data that will be represented in the xlsx document.
summary_dict: dictionary that contains the passed_tests/total_tests per
product(key)
product_summary_dict: dictionary that contains the passed_tests/total_tests
information per pair of products (key). For example
RTI Connext/OpenDDS --> passed_tests/total_tests
publisher_product_dict: dictionary that contains a list with all results of
all tests for a specific publisher product (key)
with all other products as subscriber.
subscriber_product_dict: dictionary that contains a list with all results of
all tests for a specific publisher product (key)
with all other products as subscriber.
"""
# [product, aggregated data]
summary_dict: dict[str,JunitAggregatedData] = {}
# [(publisher_name, subscriber_name), aggregated data]
product_summary_dict: dict[(str,str),JunitAggregatedData] = {}
# [publisher_name, list of test case aggregated data]
publisher_product_dict: dict[str,list[JunitTestCaseAggregatedData]] = {}
# [subscriber_name, list of test case aggregated data]
subscriber_product_dict: dict[str,list[JunitTestCaseAggregatedData]] = {}
def __init__(self, input: pathlib.Path):
self.get_info(input)
@staticmethod
def xml_parser(file):
"""Function to parse the XML file"""
parser = lxml.etree.XMLParser(huge_tree=True)
return lxml.etree.parse(file, parser)
def update_value_aggregated_data_dict(self,
dictionary: dict,
key: str,
value: JunitAggregatedData) -> None:
"""
Update the value of the 'key' in the 'dictionary'. If the key
doesn't exist, add the new value to the dictionary, otherwise,
add the numbers from 'value' to the current dictionary value.
"""
if key in dictionary:
updated_data = JunitAggregatedData(
dictionary[key].get_passed_tests() + value.get_passed_tests(),
dictionary[key].get_total_tests() + value.get_total_tests(),
)
dictionary[key] = updated_data
else:
dictionary[key] = value
def update_value_to_product_dict(self,
key: str,
product_dict: dict[str,list[JunitTestCaseAggregatedData]],
value: JunitTestCaseAggregatedData) -> None:
"""
Update the value of the 'key' in the 'product_dict'. If the key
doesn't exist, add the new value to the dictionary (as a list of 1
elements), otherwise, add the element from 'value' to the current
dictionary value (list).
"""
if key in product_dict:
product_dict[key].append(value)
else:
product_dict[key] = [value]
def get_info(self, input: pathlib.Path = None):
"""
Get the information from the JUnit XML file and store it in the
the corresponding fields of this class.
"""
# get the DOM of the XML
xml = junitparser.JUnitXml.fromfile(input, parse_func=self.xml_parser)
# for every test suite in the XML
for suite in list(iter(xml)):
# get beautified publisher and subscriber names from the test suite
# name
product_names = re.search(r'([\S]+)\-\-\-([\S]+)', suite.name)
publisher_name = ProductUtils.get_product_name(product_names.group(1))
subscriber_name = ProductUtils.get_product_name(product_names.group(2))
# get the value of the passed_tests and total_tests as a
# JunitAggregatedData
element = JunitAggregatedData(
suite.tests - suite.failures - suite.skipped - suite.errors,
suite.tests
)
# update the information of the product in the summary_dict with
# the information of the publisher and the subscriber
self.update_value_aggregated_data_dict(
self.summary_dict, publisher_name, element)
# do not add duplicated data if the publisher and subscriber names
# are the same
if publisher_name != subscriber_name:
self.update_value_aggregated_data_dict(
self.summary_dict, subscriber_name, element)
# Get table with the summary of the test passed/total_tests for
# every product as publisher and as subscriber
product_dict_key = (publisher_name, subscriber_name)
product_test_data = JunitAggregatedData(
suite.tests - suite.failures - suite.skipped - suite.errors,
suite.tests)
self.update_value_aggregated_data_dict(
self.product_summary_dict,
product_dict_key,
product_test_data)
# for each test case in the test suite, fill out the dictionaries
# that contains information about the product as publisher and
# subscriber
for case in list(iter(suite)):
test_name = re.search(r'((?:Test_)[\S]+_\d+)', case.name).group(1)
# update the value of the publisher_name as publisher with
# all products as subscribers.
# the tuple is (subscriber_name, test_name, is_passed)
publisher_test_result = JunitTestCaseAggregatedData(
product=subscriber_name,
test_name=test_name,
passed=case.is_passed
)
# add the resulting tuple to the publisher dictionary, the key
# is the publisher_name because it will be the publisher table
# against all product as subscribers
self.update_value_to_product_dict(
key=publisher_name,
value=publisher_test_result,
product_dict=self.publisher_product_dict
)
# update the value of the subscriber_name as subscriber with
# all products as publishers.
# the tuple is (publisher_name, test_name, is_passed)
subscriber_test_result = JunitTestCaseAggregatedData(
product=publisher_name,
test_name=test_name,
passed=case.is_passed
)
# add the resulting tuple to the subscriber dictionary, the key
# is the subscriber_name because it will be the subscriber table
# against all product as publishers
self.update_value_to_product_dict(
key=subscriber_name,
value=subscriber_test_result,
product_dict=self.subscriber_product_dict
)
class ColorUtils:
"""Set specific colors"""
GREEN = '#4EB168'
LIME = '#86A336'
YELLOW ='#B58F19'
ORANGE = '#DB722e'
RED = '#F2505A'
class XlsxReport:
"""
This class creates a workbook that shows the following information in
its worksheets:
* Summary: two tables that contain:
* passed_tests/total_tests for every product
* passed_tests/total_tests for every product as publisher and subscriber
* One worksheet per product that shows the test results as publisher
and as subscriber
The parameters of this class are:
* workbook: the workbook created by xlsxwriter
* __data: private member that contains the data represented in the
workbook
* __formats: private member that contains the formats of the workbook
"""
workbook: xlsxwriter.Workbook
__data: JunitData
__formats: dict = {} # contains the format name and formats objects
REPO_LINK = 'https://github.com/omg-dds/dds-rtps'
REPO_DOC = 'https://omg-dds.github.io/dds-rtps/'
def __init__(self, output: pathlib.Path, data: JunitData):
"""
Initializer that receives the JunitData and the output file. This
adds the formats used to the workbook and the different worksheets
"""
self.workbook = xlsxwriter.Workbook(output)
# set the default workbook size
self.workbook.set_size(2000,1500)
self.__data = data
self.add_formats()
self.create_summary_worksheet()
self.create_description_worksheet()
self.add_data_test_worksheet()
self.workbook.close()
def set_worksheet_defaults(self, worksheet: xlsxwriter.Workbook.worksheet_class):
# set default values
worksheet.set_zoom(130)
def create_summary_worksheet(self, name: str = 'Summary'):
"""
Creates a summary worksheet, with a header that contains static info
and a summary of the passed_tests/total_tests.
"""
summary_worksheet = self.workbook.add_worksheet(name=name)
self.set_worksheet_defaults(summary_worksheet)
# The static info of the summary requires 6 rows (row value 5) + 2 gaps
# rows.
# The tables leave the first column (value 0) as gap
self.add_data_summary_worksheet(
starting_row=9,
starting_column=1,
worksheet=summary_worksheet)
# After having all data that may have an unknown length, we call
# autofit to modify the column size to show all data, then we add
# the static data that does not require autofit
summary_worksheet.autofit()
self.add_static_data_summary_worksheet(summary_worksheet)
def create_description_worksheet(self, name: str = 'Test Descriptions'):
"""
Creates a test description worksheet from test_suite.py.
"""
description_worksheet = self.workbook.add_worksheet(name=name)
self.set_worksheet_defaults(description_worksheet)
# Set the test names and static data before doing the autofit.
self.add_static_data_description_worksheet(description_worksheet)
self.add_test_name_description_worksheet(description_worksheet)
description_worksheet.autofit()
# Add the title of the test after doing the autofit
self.add_title_description_worksheet(description_worksheet)
def add_formats(self):
"""Add the specific format"""
self.__formats['title'] = self.workbook.add_format({
'bold': True,
'font_size': 36,
'text_wrap': False
})
self.__formats['subtitle'] = self.workbook.add_format({
'font_size': 26
})
self.__formats['product_title'] = self.workbook.add_format({
'bold': True,
'align': 'center',
'valign': 'vcenter',
'font_size': 16,
'text_wrap': False
})
self.__formats['product_subtitle'] = self.workbook.add_format({
'bold': True,
'align': 'center',
'valign': 'vcenter'
})
self.__formats['bold'] = self.workbook.add_format(properties={'bold': True})
self.__formats['bold_w_border'] = self.workbook.add_format(
properties={'bold': True, 'border': 1})
self.__formats['result_green'] = value_format = self.workbook.add_format(
properties={'bg_color': ColorUtils.GREEN,
'bold': True, 'border': 1, 'align': 'center', 'valign': 'vcenter'})
self.__formats['result_lime'] = value_format = self.workbook.add_format(
properties={'bg_color': ColorUtils.LIME,
'bold': True, 'border': 1, 'align': 'center', 'valign': 'vcenter'})
self.__formats['result_yellow'] = value_format = self.workbook.add_format(
properties={'bg_color': ColorUtils.YELLOW,
'bold': True, 'border': 1, 'align': 'center', 'valign': 'vcenter'})
self.__formats['result_orange'] = value_format = self.workbook.add_format(
properties={'bg_color': ColorUtils.ORANGE,
'bold': True, 'border': 1, 'align': 'center', 'valign': 'vcenter'})
self.__formats['result_red'] = value_format = self.workbook.add_format(
properties={'bg_color': ColorUtils.RED,
'bold': True, 'border': 1, 'align': 'center', 'valign': 'vcenter'})
def get_format_color(self, index: int, num_elements: int):
"""
Return the corresponding color format depending on the ratio of
passed_tests/total_tests
"""
ratio = index / num_elements
if ratio < 0.25:
return self.__formats['result_red']
elif ratio < 0.5:
return self.__formats['result_orange']
elif ratio < 0.75:
return self.__formats['result_yellow']
elif ratio < 1:
return self.__formats['result_lime']
else: # ratio == 1
return self.__formats['result_green']
def get_format_color_bool(self, passed: bool):
"""
Get the corresponding color format depending on 'passed'.
Green if passed is True, Red otherwise
"""
if passed:
# Return GREEN
return self.get_format_color(1,1)
else:
# Return FALSE
return self.get_format_color(0,1)
def add_static_data_test(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
product_name: str,
pub_product_count: int,
sub_product_count) -> (int, int):
"""Add static data to the specific product worksheet"""
if sub_product_count > 0:
# the last column of the publisher table is
# `2 (column C) + product_count - 1`
# the -1 is because the column C is already counted
last_column_publisher = 1 + sub_product_count
if last_column_publisher > 2:
worksheet.merge_range(
# row 1, from column C till last_column_publisher
0, 2, 0, last_column_publisher,
'Publisher: ' + product_name,
self.__formats['product_title'])
worksheet.merge_range(
# row 2, from column C till last_column_publisher
1, 2, 1, last_column_publisher,
'Subscriber (next row): ',
self.__formats['product_title'])
else:
worksheet.write(
# row 1, column C
0, 2,
'Publisher: ' + product_name,
self.__formats['product_title'])
worksheet.write(
# row 2, column C
1, 2,
'Subscriber (next row): ',
self.__formats['product_title'])
if pub_product_count > 0:
# the subscriber table starts at last_column_publisher + 1
# the +1 is the gap between the publisher and subscriber tables
last_column_subscriber = last_column_publisher + 1 + pub_product_count
if last_column_subscriber > last_column_publisher + 2:
worksheet.merge_range(
# row 1, from column last_column_publisher + 2 till last_column_subscriber
# +2 = next_column + gap_between_tables
0, last_column_publisher + 2, 0, last_column_subscriber,
'Subscriber: ' + product_name,
self.__formats['product_title'])
worksheet.merge_range(
# row 2, from column last_column_publisher + 2 till last_column_subscriber
# +2 = next_column + gap_between_tables
1, last_column_publisher + 2, 1, last_column_subscriber,
'Publisher (next row): ',
self.__formats['product_title'])
else:
worksheet.write(
# row 1, column last_column_publisher + 2
# +2 = next_column + gap_between_tables
0, last_column_publisher + 2,
'Subscriber: ' + product_name,
self.__formats['product_title'])
worksheet.write(
# row 2, column last_column_publisher + 2
# +2 = next_column + gap_between_tables
1, last_column_publisher + 2,
'Publisher (next row): ',
self.__formats['product_title'])
return (1, last_column_subscriber)
def add_data_test_worksheet(self):
"""
Adds test data to the product worksheet, this includes all tests for
a product as publisher and all products as subscribers. And also,
a product as subscriber and all other products as publishers.
"""
# create a list that contains the worksheet names per product. These
# product names are the same for the publisher and the subscriber
pub_product_names = []
for name in self.__data.publisher_product_dict.keys():
pub_product_names.append(name)
sub_product_names = []
for name in self.__data.subscriber_product_dict.keys():
sub_product_names.append(name)
# Create a worksheet per product that contains the following info for
# all tests:
# * product as publisher with all other products as subscribers
# * product as subscriber with all other products as publishers
for name in pub_product_names:
# truncate the name of the string to 31 chars
worksheet = self.workbook.add_worksheet((name)[:31])
self.set_worksheet_defaults(worksheet)
current_cell = (1, 1) # B2
# next row
starting_row = current_cell[0] + 1
# Add table with the product as publisher
current_cell = self.add_product_table(
worksheet=worksheet,
starting_column=1, # B
starting_row=starting_row,
value=self.__data.publisher_product_dict[name],
print_test_name=True
)
# Set the column size of the separation column between publisher
# and subscriber tables
worksheet.set_column(current_cell[1] + 1, current_cell[1] + 1, 4)
# Add table with the product as subscriber
# as the test_name is not printed, the starting_column does not
# write anything, so, the table starts at starting_column + 1
if name in sub_product_names:
self.add_product_table(
worksheet=worksheet,
starting_column=current_cell[1] + 1, # next column
starting_row=starting_row,
value=self.__data.subscriber_product_dict[name],
print_test_name=False
)
# After having all data that may have an unknown length, we call
# autofit to modify the column size to show all data, then we add
# the static data that does not require autofit
worksheet.autofit()
self.add_static_data_test(
worksheet=worksheet,
product_name=name,
pub_product_count=len(pub_product_names),
sub_product_count=len(sub_product_names))
def add_product_table(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
starting_row: int,
starting_column: int,
value: list[JunitTestCaseAggregatedData],
print_test_name: bool):
"""
This function adds the test results for one specific publisher with
all products as subscribers and one specific subscriber with all
products as publishers to the worksheet.
"""
current_column = starting_column
current_row = starting_row
subscriber_row = starting_row
test_column = starting_column
# The starting cell is the title of the test column
if print_test_name:
worksheet.write(starting_row, starting_column,
'Test',
self.__formats['bold_w_border'])
# This column dictionary will keep the colum for the subscriber product
column_dict = {}
row_dict = {}
# for all elements (test results), add the corresponding value to the
# worksheet
for element in value:
if element.get_product_name() in column_dict:
# if the product has been added before, just set the
# process_column to the right column number.
process_column = column_dict[element.get_product_name()]
else:
# if the product hasn't been added before, add the tag to
# the corresponding column and set the process_column to the
# column where the result will be saved
current_column += 1
process_column = current_column
column_dict[element.get_product_name()] = current_column
worksheet.write(
subscriber_row,
current_column,
element.get_product_name(),
self.__formats['bold_w_border'])
if element.get_test_name() in row_dict:
# if the test has been added before, just set the
# process_row to the right row number.
process_row = row_dict[element.get_test_name()]
else:
# if the test hasn't been added before, add the tag to
# the corresponding row and set the process_row to the row
# where the result will be saved
current_row += 1
process_row = current_row
row_dict[element.get_test_name()] = current_row
if print_test_name:
worksheet.write(
current_row,
test_column,
element.get_test_name(),
self.__formats['bold_w_border'])
# set OK or ERROR if the test passed or not
str_result = 'OK' if element.get_passed() else 'ERROR'
worksheet.write(
process_row,
process_column,
str_result,
self.get_format_color_bool(element.get_passed()))
return (current_row, current_column)
def add_data_summary_worksheet(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
starting_row: int,
starting_column: int):
"""
This function adds the table passed_tests/total_tests per product and
another table with passed_tests/total_tests with all products as
publishers/subscribers.
"""
current_row = starting_row
current_column = starting_column
worksheet.write(
current_row, current_column,
'Company', self.__formats['bold_w_border'])
worksheet.write(
current_row, current_column + 1,
'Product', self.__formats['bold_w_border'])
worksheet.write(
current_row, current_column + 2,
'Test Passed', self.__formats['bold_w_border'])
current_row += 1
# Create table with the total passed_tests/total_tests per product
for product_name, value in self.__data.summary_dict.items():
worksheet.write(
current_row, current_column,
ProductUtils.get_company_name(product_name),
self.__formats['bold_w_border'])
worksheet.write(
current_row, current_column + 1,
product_name,
self.__formats['bold_w_border'])
worksheet.write(
current_row, current_column + 2,
str(value.get_passed_tests()) + ' / ' +
str(value.get_total_tests()),
self.get_format_color(value.get_passed_tests(),
value.get_total_tests()))
current_row += 1
# Add 2 rows of gap for the next table
current_row += 2
worksheet.write(
current_row, current_column,
'Publisher/Subscriber', self.__formats['bold_w_border'])
# create a dictionary to store the row/column of the product name
# for example, row_dict['Connext DDS 6.1.2'] = 30 means that the
# row (publisher) of Connext DDS 6.1.2 is in the xlsx row 29.
# Column for the publisher is always fixed: 1 --> B
# Row for the subscriber is always fixed: current_row
subscriber_row = current_row
publisher_column = 1
row_dict={} # publishers
column_dict={} # subscribers
# Add the table passed_tests/total_tests with all combinations of product
# as publishers and as subscribers
for (publisher_name, subscriber_name), value in self.__data.product_summary_dict.items():
# if the publisher hasn't been already processed yet, determine
# what is the process_row by selecting the next free row
# (current_row+1)
if not publisher_name in row_dict:
current_row += 1
process_row = current_row
row_dict[publisher_name] = current_row
worksheet.write(current_row, publisher_column,
publisher_name, self.__formats['bold_w_border'])
else:
# if the publisher has been already processed, just set the
# process_row to the corresponding row
process_row = row_dict[publisher_name]
# if the subscriber hasn't been already processed yet, determine
# what is the process_column by selecting the next free column
# (current_column+1)
if not subscriber_name in column_dict:
current_column += 1
process_column = current_column
column_dict[subscriber_name] = current_column
worksheet.write(subscriber_row, current_column,
subscriber_name, self.__formats['bold_w_border'])
else:
# if the subscriber has been already processed, just set the
# process_column to the corresponding column
process_column = column_dict[subscriber_name]
worksheet.write(process_row, process_column,
str(value.get_passed_tests()) + ' / ' +
str(value.get_total_tests()),
self.get_format_color(value.get_passed_tests(), value.get_total_tests()))
def add_static_data_summary_worksheet(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
name: str = 'Summary',
starting_row: int = 0, # row 1
starting_column: int = 1): # B column
"""
Add header to the summary worksheet, it includes the DDS logo, the
title and subtitle, the repo link and the time when the XLSX report
was generated. This static data requires 8 rows
"""
current_row = starting_row
# Add title
worksheet.write(
current_row, starting_column,
'DDS Interoperability tests', self.__formats['title'])
# Add Summary literal
current_row += 1
worksheet.write(
current_row, starting_column,
'Summary', self.__formats['subtitle'])
# Add DDS logo pic
current_row += 2
script_folder = os.path.dirname(__file__)
dds_logo_path = os.path.join(script_folder, 'resource/DDS-logo.jpg')
worksheet.insert_image(
row=current_row, col=starting_column,
filename=dds_logo_path,
options={'x_scale': 0.4, 'y_scale': 0.4, 'decorative': True, 'object_position': 2})
# Add date
current_row += 1
worksheet.write(current_row, starting_column + 1, 'Date')
date_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
worksheet.write(current_row, starting_column + 2, date_time)
# Add repo link
current_row += 1
worksheet.write(current_row, starting_column + 1,'Repo')
worksheet.write(current_row, starting_column + 2, self.REPO_LINK)
# Add repo doc link
current_row += 1
worksheet.write(current_row, starting_column + 1,'Documentation')
worksheet.write(current_row, starting_column + 2, self.REPO_DOC)
def add_static_data_description_worksheet(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
name: str = 'Test Descriptions',
starting_row: int = 0, # row 1
starting_column: int = 1): # B column
"""
Add header to the test descriptions worksheet, it includes the headers
of the columns.
"""
current_row = starting_row
# Add column headers
worksheet.write(
current_row, starting_column,
'Test Name', self.__formats['product_subtitle'])
worksheet.write(
current_row, starting_column + 1,
'Test Title', self.__formats['product_subtitle'])
worksheet.write_url(
current_row, starting_column + 2,
'https://omg-dds.github.io/dds-rtps/test_description.html',
string="Click here for full test descriptions")
def add_test_name_description_worksheet(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
starting_row: int = 1, # row 2
col: int = 1): # B column
"""Add test names to the test descriptions worksheet."""
current_row = starting_row
# Add test name
for test_name in test_suite.rtps_test_suite_1.keys():
worksheet.write(current_row, col, test_name, self.__formats['bold'])
current_row += 1
def add_title_description_worksheet(self,
worksheet: xlsxwriter.Workbook.worksheet_class,
starting_row: int = 1, # row 2
col: int = 2): # C column
"""Add short test description (aka title) to the test descriptions worksheet."""
current_row = starting_row
# Add test title
for value in test_suite.rtps_test_suite_1.values():
worksheet.write(current_row, col, value['title'])
current_row += 1
def get_file_extension(input) -> str:
"""Get file extension from the input as Path or str"""
input_string = ''
if isinstance(input, pathlib.Path):
input_string = str(input)
elif isinstance(input, str):
input_string = input
else:
raise RuntimeError('get_file_extension error, only Path, or str allowed')
return os.path.splitext(input_string)[1].lower()[1:]
def main():
# parse arguments
argument_parser = XlxsReportArgumentParser.argument_parser()
args = argument_parser.parse_args()
options = {
'input': args.input,
'output': args.output
}
# Get absolute paths from input and output
if options['input'] is not None:
input = pathlib.Path(options['input']).resolve()
else:
raise RuntimeError('no input file specified')
# Check if the input and output have the right extension
if not input.is_file() and get_file_extension(input) != 'xml':
raise RuntimeError('the input is not a file, or the extension is not xml')
if options['output'] is not None:
output = pathlib.Path(options['output']).resolve()
else:
raise RuntimeError('no output file specified')
if output.exists() or get_file_extension(output) != 'xlsx':
raise RuntimeError('output file already exist or is not pointing to an '
+ 'xlsl file')
try:
# generate a JunitData from the file in the input
junit_data = JunitData(input=input)
# generate report in the output from the JunitData
XlsxReport(output=output, data=junit_data)
except KeyboardInterrupt:
print('interrupted by user')
try:
sys.exit(1)
except SystemExit:
os._exit(1)
except Exception as e:
raise e
if __name__ == '__main__':
main()