MCPcopy Index your code
hub / github.com/python/cpython / test_parsing

Method test_parsing

Lib/test/test_strtod.py:215–249  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

213 self.check_strtod(s)
214
215 def test_parsing(self):
216 # make '0' more likely to be chosen than other digits
217 digits = '000000123456789'
218 signs = ('+', '-', '')
219
220 # put together random short valid strings
221 # \d*[.\d*]?e
222 for i in range(1000):
223 for j in range(TEST_SIZE):
224 s = random.choice(signs)
225 intpart_len = random.randrange(5)
226 s += ''.join(random.choice(digits) for _ in range(intpart_len))
227 if random.choice([True, False]):
228 s += '.'
229 fracpart_len = random.randrange(5)
230 s += ''.join(random.choice(digits)
231 for _ in range(fracpart_len))
232 else:
233 fracpart_len = 0
234 if random.choice([True, False]):
235 s += random.choice(['e', 'E'])
236 s += random.choice(signs)
237 exponent_len = random.randrange(1, 4)
238 s += ''.join(random.choice(digits)
239 for _ in range(exponent_len))
240
241 if intpart_len + fracpart_len:
242 self.check_strtod(s)
243 else:
244 try:
245 float(s)
246 except ValueError:
247 pass
248 else:
249 assert False, "expected ValueError"
250
251 @test.support.bigmemtest(size=test.support._2G+10, memuse=3, dry_run=False)
252 def test_oversized_digit_strings(self, maxsize):

Callers

nothing calls this directly

Calls 4

check_strtodMethod · 0.95
choiceMethod · 0.80
randrangeMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected