Repository: joke2k/faker
Pull request #227 (2015-04-16 16:49:58)

use full module path for providers

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2354180/badge)](https://coveralls.io/builds/2354180)

Coverage decreased (-0.14%) to 88.88% when pulling **95c92bbbf76d1615a7279b9b262fcb8edc7d871e on fcurella:feature/custom-providers** into **b0d396be396e31ed760c7964e242a25d3c2a6c45 on joke2k:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2354180/badge)](https://coveralls.io/builds/2354180)

Coverage decreased (-0.14%) to 88.88% when pulling **95c92bbbf76d1615a7279b9b262fcb8edc7d871e on fcurella:feature/custom-providers** into **b0d396be396e31ed760c7964e242a25d3c2a6c45 on joke2k:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2354180/badge)](https://coveralls.io/builds/2354180)

Coverage decreased (-0.14%) to 88.88% when pulling **95c92bbbf76d1615a7279b9b262fcb8edc7d871e on fcurella:feature/custom-providers** into **b0d396be396e31ed760c7964e242a25d3c2a6c45 on joke2k:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/2354180/badge)](https://coveralls.io/builds/2354180)

Coverage decreased (-0.14%) to 88.88% when pulling **95c92bbbf76d1615a7279b9b262fcb8edc7d871e on fcurella:feature/custom-providers** into **b0d396be396e31ed760c7964e242a25d3c2a6c45 on joke2k:master**.


Patch:
diff --git a/faker/cli.py b/faker/cli.py
index 5c8a8a0f..94341c98 100644
--- a/faker/cli.py
+++ b/faker/cli.py
@@ -68,7 +68,7 @@ def print_doc(provider_or_field=None,
         if '.' in provider_or_field:
             parts = provider_or_field.split('.')
             locale = parts[-2] if parts[-2] in AVAILABLE_LOCALES else lang
-            fake = Factory.create(locale, providers=[parts[-1]])
+            fake = Factory.create(locale, providers=[provider_or_field])
             doc = documentor.Documentor(fake)
             doc.already_generated = base_provider_formatters
             print_provider(
diff --git a/faker/factory.py b/faker/factory.py
index 50d71852..9eb0106d 100644
--- a/faker/factory.py
+++ b/faker/factory.py
@@ -7,7 +7,6 @@ from importlib import import_module
 import locale as pylocale
 
 from faker import Generator
-from faker import providers as providers_mod
 from faker.config import DEFAULT_LOCALE, DEFAULT_PROVIDERS, AVAILABLE_LOCALES
 from faker.utils.loading import list_module
 
@@ -27,7 +26,6 @@ class Factory(object):
         providers = providers or DEFAULT_PROVIDERS
 
         faker = generator or Generator(**config)
-        faker.add_provider(providers_mod.BaseProvider)
 
         for prov_name in providers:
             prov_cls, lang_found = cls._get_provider_class(prov_name, locale)
@@ -62,32 +60,21 @@ class Factory(object):
         raise ValueError(msg)
 
     @classmethod
-    def _find_provider_class(cls, provider, locale=None):
-        providers_mod_name = providers_mod.__package__ or providers_mod.__name__
- 
-        path = "{providers}.{provider}".format(
-            providers=providers_mod_name,
-            provider=provider
-        )
-
-        provider_module = import_module(path)
+    def _find_provider_class(cls, provider_path, locale=None):
+        provider_module = import_module(provider_path)
+
         if getattr(provider_module, 'localized', False):
             available_locales = list_module(provider_module)
             if not locale or locale not in available_locales:
                 locale = getattr(provider_module, 'default_locale', DEFAULT_LOCALE)
 
-            path = "{providers}.{provider}.{locale}".format(
-                providers=providers_mod_name,
+            path = "{provider_path}.{locale}".format(
+                provider_path=provider_path,
                 locale=locale,
-                provider=provider
             )
             provider_module = import_module(path)
         else:
             if locale is not None:
-                path = "{providers}.{provider}".format(
-                    providers=providers_mod_name,
-                    provider=provider
-                )
-                provider_module = import_module(path)
+                provider_module = import_module(provider_path)
 
         return provider_module.Provider
diff --git a/faker/utils/loading.py b/faker/utils/loading.py
index b9e026f8..40e4b5da 100644
--- a/faker/utils/loading.py
+++ b/faker/utils/loading.py
@@ -13,17 +13,10 @@ def list_module(module):
 
 def find_available_locales(providers):
     available_locales = set()
-    from faker import providers as providers_mod
 
-    for provider in providers:
-        providers_mod_name = providers_mod.__package__ or providers_mod.__name__
- 
-        path = "{providers}.{provider}".format(
-            providers=providers_mod_name,
-            provider=provider
-        )
+    for provider_path in providers:
 
-        provider_module = import_module(path)
+        provider_module = import_module(provider_path)
         if getattr(provider_module, 'localized', False):
             langs = list_module(provider_module)
             available_locales.update(langs)
@@ -33,6 +26,6 @@ def find_available_locales(providers):
 def find_available_providers(modules):
     available_providers = set()
     for providers_mod in modules:
-        providers = list_module(providers_mod)
+        providers = ['.'.join([providers_mod.__package__, mod]) for mod in list_module(providers_mod)]
         available_providers.update(providers)
     return sorted(available_providers)


Test patch:
diff --git a/faker/tests/__init__.py b/faker/tests/__init__.py
index 22c9cd47..163958b4 100644
--- a/faker/tests/__init__.py
+++ b/faker/tests/__init__.py
@@ -2,6 +2,8 @@
 
 from __future__ import unicode_literals
 
+__loader__ = None
+
 import json
 import os
 import random
@@ -118,25 +120,25 @@ class UtilsTestCase(unittest.TestCase):
         providers = find_available_providers(modules)
 
         expected_providers = list(map(str, [
-            'address',
-            'barcode',
-            'color',
-            'company',
-            'credit_card',
-            'currency',
-            'date_time',
-            'file',
-            'internet',
-            'job',
-            'lorem',
-            'misc',
-            'miscelleneous',
-            'person',
-            'phone_number',
-            'profile',
-            'python',
-            'ssn',
-            'user_agent',
+            'faker.providers.address',
+            'faker.providers.barcode',
+            'faker.providers.color',
+            'faker.providers.company',
+            'faker.providers.credit_card',
+            'faker.providers.currency',
+            'faker.providers.date_time',
+            'faker.providers.file',
+            'faker.providers.internet',
+            'faker.providers.job',
+            'faker.providers.lorem',
+            'faker.providers.misc',
+            'faker.providers.miscelleneous',
+            'faker.providers.person',
+            'faker.providers.phone_number',
+            'faker.providers.profile',
+            'faker.providers.python',
+            'faker.providers.ssn',
+            'faker.providers.user_agent',
         ]))
         self.assertEqual(providers, expected_providers)
 
@@ -198,7 +200,7 @@ class FactoryTestCase(unittest.TestCase):
         output = StringIO()
         print_doc(output=output)
         print_doc('address', output=output)
-        print_doc('faker.providers.it_IT.person', output=output)
+        print_doc('faker.providers.person.it_IT', output=output)
         assert output.getvalue()
         self.assertRaises(AttributeError,
                           self.generator.get_formatter,