Merged in [18020] from rjsparks@nostrum.com:
Construct Faker objects used for person name generation only once. Results in a roughly 20% speedup of the test-suite.
- Legacy-Id: 18023
Note: SVN reference [18020] has been migrated to Git commit c60cc1b1a0
This commit is contained in:
commit
0f17e03121
|
@ -24,14 +24,20 @@ from ietf.person.name import normalize_name, unidecode_name
|
|||
|
||||
fake = faker.Factory.create()
|
||||
|
||||
def random_faker():
|
||||
def setup():
|
||||
global acceptable_fakers
|
||||
# The transliteration of some arabic and devanagari names introduces
|
||||
# non-alphabetic characgters that don't work with the draft author
|
||||
# extraction code, and also don't seem to match the way people with arabic
|
||||
# names romanize arabic names. Exlude those locales from name generation
|
||||
# in order to avoid test failures.
|
||||
locales = set( [ l for l in faker.config.AVAILABLE_LOCALES if not (l.startswith('ar_') or l.startswith('sg_')) ] )
|
||||
return faker.Faker(random.sample(locales, 1)[0])
|
||||
acceptable_fakers = [faker.Faker(locale) for locale in locales]
|
||||
setup()
|
||||
|
||||
def random_faker():
|
||||
global acceptable_fakers
|
||||
return random.sample(acceptable_fakers, 1)[0]
|
||||
|
||||
class UserFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in a new issue