Repository: joke2k/faker

Issue:
Refactor Profile to be used with locale: how
I got this idea but i'm not sure it would be the simplest: the actual profile.py becomes something like "internal_profile.py", its methods are renamed "internal_simple_profile()" and "internal_profile()", and is removed from the list of standard providers. Then we will have a standard profile.py that simply calls self.generator.internal_profile(). For each locale instead, we will be able to add more logic, for example to customize field names and eventually values. 

Do you think there would be a simpler way to do it?



Discussion:
We should probably rethink the way in which the profile provider generates the informations.
Surely the methods that return dictionaries can not use simple names like `profile()`. It would seem more appropriate as a name `profile_data()`. 

In my opinion the profile method should return something similar to `address()`.


Resolving patch:
diff --git a/faker/factory.py b/faker/factory.py
--- a/faker/factory.py
+++ b/faker/factory.py
@@ -25,6 +25,7 @@ def create(cls, locale=None, providers=None, generator=None, includes=None, **co
             msg = 'Invalid configuration for faker locale "{0}"'.format(locale)
             raise AttributeError(msg)
 
+        config['locale'] = locale
         providers = providers or PROVIDERS
 
         providers += includes
diff --git a/faker/generator.py b/faker/generator.py
--- a/faker/generator.py
+++ b/faker/generator.py
@@ -69,7 +69,15 @@ def get_formatter(self, formatter):
         try:
             return getattr(self, formatter)
         except AttributeError:
-            raise AttributeError('Unknown formatter "{0}"'.format(formatter))
+            if 'locale' in self.__config:
+                msg = 'Unknown formatter "{0}" with locale "{1}"'.format(
+                    formatter, self.__config['locale']
+                )
+            else:
+                raise AttributeError('Unknown formatter "{0}"'.format(
+                    formatter
+                ))
+            raise AttributeError(msg)
 
     def set_formatter(self, name, method):
         """
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -60,8 +60,10 @@
     test_suite='tests',
     zip_safe=zip_safe,
     install_requires=[
+        "email_validator>=1.0.2",
         "python-dateutil>=2.4",
         "six",
+        "ukpostcodeparser>=1.1.1",
     ],
     extras_require={
         ':python_version=="2.7"': [


Test patch:
diff --git a/tests/factory.py b/tests/factory.py
--- a/tests/factory.py
+++ b/tests/factory.py
@@ -55,8 +55,14 @@ def test_get_formatter_returns_correct_formatter(self):
                          self.generator.get_formatter('foo_formatter'))
 
     def test_get_formatter_throws_exception_on_incorrect_formatter(self):
-        with self.assertRaises(AttributeError):
+        with self.assertRaises(AttributeError) as exc:
             self.generator.get_formatter('barFormatter')
+            self.assertEqual(exc.args[0], 'Unknown formatter "barFormatter"')
+
+        faker = Factory.create('it_IT')
+        with self.assertRaises(AttributeError) as exc:
+            faker.get_formatter('barFormatter')
+            self.assertEqual(exc.args[0], 'Unknown formatter "barFormatter" with locale "it_IT"')
 
     def test_format_calls_formatter_on_provider(self):
         self.assertEqual('foobar', self.generator.format('foo_formatter'))
diff --git a/tests/requirements.txt b/tests/requirements.txt
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -1,3 +1,3 @@
 mock==1.0.1
-UkPostcodeParser==1.0.3
-email_validator>=1.0
\ No newline at end of file
+UkPostcodeParser>=1.1.1
+email_validator>=1.0.2
\ No newline at end of file