def get_faker(providers, locale=None): providers = [("faker.providers.%s" % provider if ("." not in provider) else provider) for provider in providers] locale = locale or (random.choice(["en_US"] + list(find_available_locales(providers)))) fake = faker.Factory.create(locale=locale) fake.locale = locale fake.locale_language = fake.locale.split("_")[0] return fake
def get_faker(providers, locale="en"): providers = [("faker.providers.%s" % provider if ("." not in provider) else provider) for provider in providers] locale = locale or (random.choice(["en_US"] + list(find_available_locales(providers)))) fake = faker.Factory.create(locale=locale) fake.locale = locale lang_code = fake.locale.split("_")[0] fake.locale_language = lang_code fake.language = lang_code return fake
def test_find_available_locales(self): from faker.utils.loading import find_available_locales from faker.config import DEFAULT_PROVIDERS result = find_available_locales(DEFAULT_PROVIDERS) self.assertNotEqual(len(result), 0)
def test_find_available_locales(self): result = find_available_locales(PROVIDERS) assert len(result) != 0
def test_find_available_locales(self): result = find_available_locales(PROVIDERS) self.assertNotEqual(len(result), 0)
def test_find_available_locales(self): from faker.utils.loading import find_available_locales from faker.config import PROVIDERS result = find_available_locales(PROVIDERS) self.assertNotEqual(len(result), 0)
# coding=utf-8 from faker.utils.loading import find_available_locales DEFAULT_LOCALE = 'en_US' DEFAULT_PROVIDERS = ( 'address', 'barcode', 'color', 'company', 'credit_card', 'currency', 'date_time', 'file', 'internet', 'job', 'lorem', 'misc', 'person', 'profile', 'python', 'phone_number', 'ssn', 'user_agent', ) AVAILABLE_LOCALES = find_available_locales(DEFAULT_PROVIDERS)
# coding=utf-8 from importlib import import_module from faker.utils.loading import find_available_locales, find_available_providers DEFAULT_LOCALE = 'en_US' META_PROVIDERS_MODULES = [ 'faker.providers', ] PROVIDERS = find_available_providers( [import_module(path) for path in META_PROVIDERS_MODULES]) AVAILABLE_LOCALES = find_available_locales(PROVIDERS)