Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
hive
hivemind
Commits
f74a6129
Commit
f74a6129
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Add comments to json_report_parser.py
parent
5ce6f29f
No related branches found
No related tags found
2 merge requests
!456
Release candidate v1 24
,
!246
API tests execution time reports
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/json_report_parser.py
+25
-3
25 additions, 3 deletions
scripts/json_report_parser.py
with
25 additions
and
3 deletions
scripts/json_report_parser.py
+
25
−
3
View file @
f74a6129
#!/usr/bin/python3
"""
Parse json file generated by pytest benchmarks and create htm report file
for files exceeding expected threshold print information to the console
"""
import
os
from
sys
import
exit
from
json
import
dumps
,
load
def
get_request_from_yaml
(
path_to_yaml
):
"""
Extract request parameters from given yaml file
Parameters:
- path_to_yaml - path to yaml file
Returns:
- string with request parameters
"""
import
yaml
yaml_document
=
None
with
open
(
path_to_yaml
,
"
r
"
)
as
yaml_file
:
...
...
@@ -17,14 +26,20 @@ def get_request_from_yaml(path_to_yaml):
return
""
def
make_class_path_dict
(
root_dir
):
import
os
"""
Scan root dir for files with given pattern and construct dictionary
with keys as path with replaced ., -, / characters and values as file path
Parameters:
- root_dir - dir to scan for files
Returns:
- dict class_name -> path
"""
from
fnmatch
import
fnmatch
pattern
=
"
*.tavern.yaml
"
ret
=
{}
for
path
,
subdirs
,
files
in
os
.
walk
(
root_dir
):
for
path
,
_
,
files
in
os
.
walk
(
root_dir
):
for
name
in
files
:
if
fnmatch
(
name
,
pattern
):
test_path
=
os
.
path
.
join
(
path
,
name
)
...
...
@@ -32,6 +47,13 @@ def make_class_path_dict(root_dir):
return
ret
def
class_to_path
(
class_name
,
class_to_path_dic
):
"""
Return path to test file basing on class name
Parameters:
- class_name - test to find,
- class_to_path_dic - dict with class -> path key/values
Return:
- path to test file
"""
from
fnmatch
import
fnmatch
for
c
,
p
in
class_to_path_dic
.
items
():
if
fnmatch
(
c
,
"
*
"
+
class_name
):
...
...
@@ -71,7 +93,7 @@ if __name__ == '__main__':
for
benchmark
in
json_data
[
'
benchmarks
'
]:
if
float
(
benchmark
[
'
stats
'
][
'
mean
'
])
>
args
.
time_threshold
:
ofile
.
write
(
"
<tr><td>{}<br/>Parameters: {}</td><td bgcolor=
\"
red
\"
>{:.4f}</td></tr>
\n
"
.
format
(
benchmark
[
'
name
'
],
get_request_from_yaml
(
class_to_path
(
benchmark
[
'
name
'
][
5
:],
class_to_path_dic
)),
benchmark
[
'
stats
'
][
'
mean
'
]))
above_treshold
.
append
((
benchmark
[
'
name
'
],
benchmark
[
'
stats
'
][
'
mean
'
],
get_request_from_yaml
(
class_to_path
(
benchmark
[
'
name
'
][
5
:],
class_to_path_dic
))))
above_treshold
.
append
((
benchmark
[
'
name
'
],
"
{:.4f}
"
.
format
(
benchmark
[
'
stats
'
][
'
mean
'
]
)
,
get_request_from_yaml
(
class_to_path
(
benchmark
[
'
name
'
][
5
:],
class_to_path_dic
))))
else
:
ofile
.
write
(
"
<tr><td>{}</td><td>{:.4f}</td></tr>
\n
"
.
format
(
benchmark
[
'
name
'
],
benchmark
[
'
stats
'
][
'
mean
'
]))
ofile
.
write
(
"
</table>
\n
"
)
...
...
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