1
1
import pytest
2
2
from mock_generators .config import load_generators
3
- from mock_generators .logic .generate_values import literal_generator_from_value , actual_generator_for_raw_property , generator_for_raw_property , keyword_generator_for_raw_property
3
+ from mock_generators .logic .generate_values import literal_generator_from_value , actual_generator_for_raw_property , generator_for_raw_property , keyword_generator_for_raw_property , find_longest_float_precision
4
4
5
5
6
6
test_generators = load_generators ("mock_generators/named_generators.json" )
@@ -85,6 +85,21 @@ def test_integer_list_multi(self):
85
85
except Exception as e :
86
86
assert False , f'Exception: { e } '
87
87
88
+ class TestLiteralSupport :
89
+ def test_find_longest_float_percision (self ):
90
+ try :
91
+ test_floats = [1.01 , 2.002 , 3.004 ]
92
+ precision = find_longest_float_precision (test_floats )
93
+ assert precision == 3
94
+ except Exception as e :
95
+ assert False , f'Exception: { e } '
96
+
97
+ try :
98
+ test_floats = [1 , - 2 ]
99
+ precision = find_longest_float_precision (test_floats )
100
+ assert precision == 0
101
+ except Exception as e :
102
+ assert False , f'Exception: { e } '
88
103
89
104
class TestLiteralGenerators :
90
105
def test_integer (self ):
@@ -102,14 +117,21 @@ def test_integer(self):
102
117
def test_float (self ):
103
118
try :
104
119
test_string = "1.0"
105
- # This should be equivalent to the integer generator with arg of [1]
106
120
generator , args = literal_generator_from_value (test_string , test_generators )
107
- # Test generator returned creates acceptable value
108
121
value = generator .generate (args )
109
122
assert value == 1.0
110
123
except Exception as e :
111
124
assert False , f'Exception: { e } '
112
125
126
+ def test_negative_float (self ):
127
+ try :
128
+ test_string = "-1.0"
129
+ generator , args = literal_generator_from_value (test_string , test_generators )
130
+ value = generator .generate (args )
131
+ assert value == - 1.0
132
+ except Exception as e :
133
+ assert False , f'Exception: { e } '
134
+
113
135
114
136
def test_int_range (self ):
115
137
try :
@@ -126,16 +148,77 @@ def test_int_range(self):
126
148
def test_float_range (self ):
127
149
try :
128
150
test_string = "1.0-2"
129
- # This should be equivalent to the integer generator with arg of [1]
130
151
generator , args = literal_generator_from_value (test_string , test_generators )
131
- # Test generator returned creates acceptable value
132
152
value = generator .generate (args )
133
153
assert value <= 2.0
134
154
assert value >= 1.0
135
155
except Exception as e :
136
156
assert False , f'Exception: { e } '
157
+ try :
158
+ test_string = "1-2.0"
159
+ generator , args = literal_generator_from_value (test_string , test_generators )
160
+ value = generator .generate (args )
161
+ assert value <= 2.0
162
+ assert value >= 1.0
163
+ except Exception as e :
164
+ assert False , f'Exception: { e } '
165
+ try :
166
+ test_string = "1.0-2.0"
167
+ generator , args = literal_generator_from_value (test_string , test_generators )
168
+ value = generator .generate (args )
169
+ assert value <= 2.0
170
+ assert value >= 1.0
171
+ except Exception as e :
172
+ assert False , f'Exception: { e } '
173
+ try :
174
+ test_string = "1--2.02"
175
+ generator , args = literal_generator_from_value (test_string , test_generators )
176
+ value = generator .generate (args )
177
+ assert value <= 1.00
178
+ assert value >= - 2.01
179
+ except Exception as e :
180
+ assert False , f'Exception: { e } '
181
+ try :
182
+ test_string = "1.01--2.02"
183
+ generator , args = literal_generator_from_value (test_string , test_generators )
184
+ value = generator .generate (args )
185
+ assert value <= 1.01
186
+ assert value >= - 2.01
187
+ except Exception as e :
188
+ assert False , f'Exception: { e } '
137
189
138
-
190
+ try :
191
+ test_string = "-10.0003-20"
192
+ generator , args = literal_generator_from_value (test_string , test_generators )
193
+ value = generator .generate (args )
194
+ assert value <= 20.0000
195
+ assert value >= - 10.0003
196
+ except Exception as e :
197
+ assert False , f'Exception: { e } '
198
+ try :
199
+ test_string = "-10.01-20.02"
200
+ generator , args = literal_generator_from_value (test_string , test_generators )
201
+ value = generator .generate (args )
202
+ assert value <= 20.02
203
+ assert value >= - 10.01
204
+ except Exception as e :
205
+ assert False , f'Exception: { e } '
206
+ try :
207
+ test_string = "-73--74.004"
208
+ generator , args = literal_generator_from_value (test_string , test_generators )
209
+ value = generator .generate (args )
210
+ assert value <= - 73.000
211
+ assert value >= - 74.004
212
+ except Exception as e :
213
+ assert False , f'Exception: { e } '
214
+ try :
215
+ test_string = "-73.979--74.004"
216
+ generator , args = literal_generator_from_value (test_string , test_generators )
217
+ value = generator .generate (args )
218
+ assert value <= - 73.979
219
+ assert value >= - 74.004
220
+ except Exception as e :
221
+ assert False , f'Exception: { e } '
139
222
def test_int_list (self ):
140
223
try :
141
224
test_string = "[1,2,3]"
0 commit comments