Skip to content

Commit 0e4adf9

Browse files
Create docstrings for test_name_generator.py
1 parent 331a179 commit 0e4adf9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests_and_examples/test_name_generator.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
"""Automatically generate tests names.
2+
3+
This script updates all tests stored JSON files in the examples/ directory by
4+
replacing the current test name by a new one, generated based on the structure
5+
of the tests. It takes into account field types, operators being used,
6+
parameters etc.
7+
"""
8+
19
import collections
210
import json
311

412

513
def generate_name(query_type, test):
14+
"""Generate the test name based on the test type (count entity, aggregation
15+
etc) and its data.
16+
"""
617
name = generate_start(query_type)
718
name += ' '
819

@@ -28,6 +39,7 @@ def generate_name(query_type, test):
2839

2940

3041
def generate_start(query_type):
42+
"""Generate the first part of the test name."""
3143
query_name = query_type.upper()
3244
a_or_an = 'a'
3345

@@ -39,6 +51,7 @@ def generate_start(query_type):
3951

4052

4153
def generate_fields(fields):
54+
"""Generate the fields being used in the test."""
4255
if len(fields) == 0:
4356
return 'using automatically created fields'
4457

@@ -64,6 +77,7 @@ def generate_fields(fields):
6477

6578

6679
def generate_operators(query):
80+
"""Generate the operators being used in the test."""
6781
query_string = json.dumps(query)
6882
valid_operators = ['and', 'or', 'not', 'freqgroup']
6983
existing_operators = [operator for operator in valid_operators
@@ -94,6 +108,7 @@ def generate_operators(query):
94108

95109

96110
def generate_parameters(query):
111+
"""Generate the parameters being used in the test."""
97112
query_string = json.dumps(query)
98113
valid_parameters = [
99114
'equals', 'not-equals', 'range', 'gt', 'gte', 'lt', 'lte', 'between',
@@ -127,6 +142,7 @@ def generate_parameters(query):
127142

128143

129144
def generate_end(test):
145+
"""Generate the last part of the test name."""
130146
text = ''
131147

132148
metric = generate_metric(test)
@@ -151,6 +167,7 @@ def generate_end(test):
151167

152168

153169
def generate_metric(test):
170+
"""Generate the metrics and histogram being used in the test."""
154171
text = ''
155172
query_string = json.dumps(test['query'])
156173

@@ -179,6 +196,7 @@ def generate_metric(test):
179196

180197

181198
def generate_timezone(test):
199+
"""Generate the timezone being used in the test."""
182200
text = ''
183201
index_string = json.dumps(test['index'])
184202
query_string = json.dumps(test['query'])
@@ -205,6 +223,7 @@ def generate_timezone(test):
205223

206224

207225
def generate_relative_time(test):
226+
"""Generate the relative being used in the test."""
208227
text = []
209228
query_string = json.dumps(test['query'])
210229

@@ -239,6 +258,7 @@ def generate_relative_time(test):
239258

240259

241260
def main():
261+
"""Generate tests names for all JSON files in the examples/ directory."""
242262
query_types = [
243263
'count_entity',
244264
'count_event',

0 commit comments

Comments
 (0)