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

Function rand_locale

Modules/_decimal/tests/formathelper.py:318–342  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

316# Generate random format strings with random locale setting
317# [[fill]align][sign][#][0][width][,][.precision][type]
318def rand_locale():
319 try:
320 loc = random.choice(locale_list)
321 locale.setlocale(locale.LC_ALL, loc)
322 except locale.Error as err:
323 pass
324 active = sorted(random.sample(range(5), random.randrange(6)))
325 s = ''
326 have_align = 0
327 for elem in active:
328 if elem == 0: # fill+align
329 s += chr(random.randrange(32, 128))
330 s += random.choice('<>=^')
331 have_align = 1
332 elif elem == 1: # sign
333 s += random.choice('+- ')
334 elif elem == 2 and not have_align: # zeropad
335 s += '0'
336 elif elem == 3: # width
337 s += str(random.randrange(1, 100))
338 elif elem == 4: # prec
339 s += '.'
340 s += str(random.randrange(100))
341 s += 'n'
342 return s

Callers 1

test_formatFunction · 0.90

Calls 4

strFunction · 0.85
choiceMethod · 0.80
randrangeMethod · 0.80
sampleMethod · 0.45

Tested by 1

test_formatFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…