def fake_factory(source, locale=None, locales=None, providers=()): check_valid_identifier(source) if source[0] == u'_': raise ValueError(u'Bad source name %s' % (source,)) if locale is not None and locales is not None: raise ValueError(u'Cannot specify both single and multiple locales') if locale: locales = (locale,) elif locales: locales = tuple(locales) else: locales = None for l in (locales or ()): if l not in AVAILABLE_LOCALES: raise ValueError(u'Unsupported locale %r' % (l,)) def supports_source(locale): test_faker = faker.Faker(locale) for provider in providers: test_faker.add_provider(provider) return hasattr(test_faker, source) if locales is None: locales = list(filter(supports_source, AVAILABLE_LOCALES)) if not locales: raise ValueError(u'No such source %r' % (source,)) else: for l in locales: if not supports_source(locale): raise ValueError(u'Unsupported source %s for locale %s' % ( source, l )) return FakeFactoryStrategy(source, providers, locales)
def fake_factory(source, locale=None, locales=None, providers=()): note_deprecation( 'hypothesis.extra.fakefactory has been deprecated, because it does ' 'not support example discovery or shrinking. Consider using a lower-' 'level strategy (such as st.text()) instead.' ) check_valid_identifier(source) if source[0] == u'_': raise ValueError(u'Bad source name %s' % (source,)) if locale is not None and locales is not None: raise ValueError(u'Cannot specify both single and multiple locales') if locale: locales = (locale,) elif locales: locales = tuple(locales) else: locales = None for l in (locales or ()): if l not in AVAILABLE_LOCALES: raise ValueError(u'Unsupported locale %r' % (l,)) def supports_source(locale): test_faker = faker.Faker(locale) for provider in providers: test_faker.add_provider(provider) return hasattr(test_faker, source) if locales is None: locales = list(filter(supports_source, AVAILABLE_LOCALES)) if not locales: raise ValueError(u'No such source %r' % (source,)) else: for l in locales: if not supports_source(locale): raise ValueError(u'Unsupported source %s for locale %s' % ( source, l )) return FakeFactoryStrategy(source, providers, locales)
def fake_factory(source, locale=None, locales=None, providers=()): note_deprecation( 'hypothesis.extra.fakefactory has been deprecated, because it does ' 'not support example discovery or shrinking. Consider using a lower-' 'level strategy (such as st.text()) instead.' ) check_valid_identifier(source) if source[0] == u'_': raise ValueError(u'Bad source name %s' % (source,)) if locale is not None and locales is not None: raise ValueError(u'Cannot specify both single and multiple locales') if locale: locales = (locale,) elif locales: locales = tuple(locales) else: locales = None for l in (locales or ()): if l not in AVAILABLE_LOCALES: raise ValueError(u'Unsupported locale %r' % (l,)) def supports_source(locale): test_faker = faker.Faker(locale) for provider in providers: test_faker.add_provider(provider) return hasattr(test_faker, source) if locales is None: locales = list(filter(supports_source, AVAILABLE_LOCALES)) if not locales: raise ValueError(u'No such source %r' % (source,)) else: for l in locales: if not supports_source(locale): raise ValueError(u'Unsupported source %s for locale %s' % ( source, l )) return FakeFactoryStrategy(source, providers, locales)