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
+
1
9
import collections
2
10
import json
3
11
4
12
5
13
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
+ """
6
17
name = generate_start (query_type )
7
18
name += ' '
8
19
@@ -28,6 +39,7 @@ def generate_name(query_type, test):
28
39
29
40
30
41
def generate_start (query_type ):
42
+ """Generate the first part of the test name."""
31
43
query_name = query_type .upper ()
32
44
a_or_an = 'a'
33
45
@@ -39,6 +51,7 @@ def generate_start(query_type):
39
51
40
52
41
53
def generate_fields (fields ):
54
+ """Generate the fields being used in the test."""
42
55
if len (fields ) == 0 :
43
56
return 'using automatically created fields'
44
57
@@ -64,6 +77,7 @@ def generate_fields(fields):
64
77
65
78
66
79
def generate_operators (query ):
80
+ """Generate the operators being used in the test."""
67
81
query_string = json .dumps (query )
68
82
valid_operators = ['and' , 'or' , 'not' , 'freqgroup' ]
69
83
existing_operators = [operator for operator in valid_operators
@@ -94,6 +108,7 @@ def generate_operators(query):
94
108
95
109
96
110
def generate_parameters (query ):
111
+ """Generate the parameters being used in the test."""
97
112
query_string = json .dumps (query )
98
113
valid_parameters = [
99
114
'equals' , 'not-equals' , 'range' , 'gt' , 'gte' , 'lt' , 'lte' , 'between' ,
@@ -127,6 +142,7 @@ def generate_parameters(query):
127
142
128
143
129
144
def generate_end (test ):
145
+ """Generate the last part of the test name."""
130
146
text = ''
131
147
132
148
metric = generate_metric (test )
@@ -151,6 +167,7 @@ def generate_end(test):
151
167
152
168
153
169
def generate_metric (test ):
170
+ """Generate the metrics and histogram being used in the test."""
154
171
text = ''
155
172
query_string = json .dumps (test ['query' ])
156
173
@@ -179,6 +196,7 @@ def generate_metric(test):
179
196
180
197
181
198
def generate_timezone (test ):
199
+ """Generate the timezone being used in the test."""
182
200
text = ''
183
201
index_string = json .dumps (test ['index' ])
184
202
query_string = json .dumps (test ['query' ])
@@ -205,6 +223,7 @@ def generate_timezone(test):
205
223
206
224
207
225
def generate_relative_time (test ):
226
+ """Generate the relative being used in the test."""
208
227
text = []
209
228
query_string = json .dumps (test ['query' ])
210
229
@@ -239,6 +258,7 @@ def generate_relative_time(test):
239
258
240
259
241
260
def main ():
261
+ """Generate tests names for all JSON files in the examples/ directory."""
242
262
query_types = [
243
263
'count_entity' ,
244
264
'count_event' ,
0 commit comments