From c6ed7c0563995573791156546cf962819935d952 Mon Sep 17 00:00:00 2001 From: Anthony Blackshaw Date: Thu, 4 Aug 2016 12:59:01 +0100 Subject: [PATCH] Fix for `Lorem` maker and new `Faker` locale changes. --- mongoframes/factory/makers/__init__.py | 5 ++++- mongoframes/factory/makers/text.py | 8 ++++---- setup.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mongoframes/factory/makers/__init__.py b/mongoframes/factory/makers/__init__.py index 4b1c8fc..8bc658d 100644 --- a/mongoframes/factory/makers/__init__.py +++ b/mongoframes/factory/makers/__init__.py @@ -105,8 +105,11 @@ def _finish(self, value): return provider(**self._kwargs) @staticmethod - def get_fake(locale): + def get_fake(locale=None): """Return a shared faker factory used to generate fake data""" + if locale is None: + locale = Faker.default_locale + if not hasattr(Maker, '_fake_' + locale): Faker._fake = faker.Factory.create(locale) return Faker._fake diff --git a/mongoframes/factory/makers/text.py b/mongoframes/factory/makers/text.py index 0252e8d..2c63c96 100644 --- a/mongoframes/factory/makers/text.py +++ b/mongoframes/factory/makers/text.py @@ -2,7 +2,7 @@ import re import string -from mongoframes.factory.makers import Maker +from mongoframes.factory.makers import Faker, Maker __all__ = [ 'Code', @@ -103,16 +103,16 @@ def _assemble(self): quantity = int(self._quantity) if self._text_type == 'body': - return '\n'.join(self.get_fake().paragraphs(nb=quantity)) + return '\n'.join(Faker.get_fake().paragraphs(nb=quantity)) if self._text_type == 'paragraph': - return self.get_fake().paragraph( + return Faker.get_fake().paragraph( nb_sentences=quantity, variable_nb_sentences=False ) if self._text_type == 'sentence': - return self.get_fake().sentence( + return Faker.get_fake().sentence( nb_words=quantity, variable_nb_words=False ) diff --git a/setup.py b/setup.py index 9b5f8f0..f0bbfbd 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='1.1.1', + version='1.1.2', description='A fast unobtrusive MongoDB ODM for Python', long_description=long_description,