Repository: joke2k/faker
Pull request #220 (2015-04-15 19:42:15)

dynamically compile list of providers

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

Coverage decreased (-9.88%) to 79.68% when pulling **210b3180fc46ba766657e3237a7adb6f75e6f621 on fcurella:feature/custom-providers** into **2f8c749c01174cceb5bcbe94285cda73293ffcf6 on joke2k:master**.

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

Coverage decreased (-9.88%) to 79.68% when pulling **210b3180fc46ba766657e3237a7adb6f75e6f621 on fcurella:feature/custom-providers** into **2f8c749c01174cceb5bcbe94285cda73293ffcf6 on joke2k:master**.

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

Coverage decreased (-0.42%) to 88.5% when pulling **7b4141db92f42f1876053d52045f6c075920f5a8 on fcurella:feature/custom-providers** into **01eb8e4b53911eea6b038563366858f8ffa26925 on joke2k:master**.

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

Coverage decreased (-0.42%) to 88.5% when pulling **7b4141db92f42f1876053d52045f6c075920f5a8 on fcurella:feature/custom-providers** into **01eb8e4b53911eea6b038563366858f8ffa26925 on joke2k:master**.

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

Coverage decreased (-0.42%) to 88.5% when pulling **7b4141db92f42f1876053d52045f6c075920f5a8 on fcurella:feature/custom-providers** into **01eb8e4b53911eea6b038563366858f8ffa26925 on joke2k:master**.

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

Coverage decreased (-0.4%) to 88.53% when pulling **7b4141db92f42f1876053d52045f6c075920f5a8 on fcurella:feature/custom-providers** into **01eb8e4b53911eea6b038563366858f8ffa26925 on joke2k:master**.

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

Coverage decreased (-0.4%) to 88.53% when pulling **7b4141db92f42f1876053d52045f6c075920f5a8 on fcurella:feature/custom-providers** into **01eb8e4b53911eea6b038563366858f8ffa26925 on joke2k:master**.


Patch:
diff --git a/faker/config.py b/faker/config.py
index 085831ea..a9a1431b 100644
--- a/faker/config.py
+++ b/faker/config.py
@@ -1,27 +1,13 @@
 # coding=utf-8
-from faker.utils.loading import find_available_locales
+from importlib import import_module
+from faker.utils.loading import find_available_locales, find_available_providers
 
 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',
+DEFAULT_PROVIDERS_MODULES = (
+    'faker.providers',
 )
 
+DEFAULT_PROVIDERS = find_available_providers([import_module(path) for path in DEFAULT_PROVIDERS_MODULES])
+
 AVAILABLE_LOCALES = find_available_locales(DEFAULT_PROVIDERS)
diff --git a/faker/utils/loading.py b/faker/utils/loading.py
index 1dee2410..b9e026f8 100644
--- a/faker/utils/loading.py
+++ b/faker/utils/loading.py
@@ -28,3 +28,11 @@ def find_available_locales(providers):
             langs = list_module(provider_module)
             available_locales.update(langs)
     return available_locales
+
+
+def find_available_providers(modules):
+    available_providers = set()
+    for providers_mod in modules:
+        providers = 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 85556b63..22c9cd47 100644
--- a/faker/tests/__init__.py
+++ b/faker/tests/__init__.py
@@ -102,7 +102,6 @@ class UtilsTestCase(unittest.TestCase):
         result = add_dicts(t1, t2, t3)
         self.assertEqual(result, {'a': 1, 'c': 3, 'b': 3, 'd': 4})
 
-
     def test_find_available_locales(self):
         from faker.utils.loading import find_available_locales
         from faker.config import DEFAULT_PROVIDERS
@@ -110,6 +109,38 @@ class UtilsTestCase(unittest.TestCase):
         result = find_available_locales(DEFAULT_PROVIDERS)
         self.assertNotEqual(len(result), 0)
 
+    def test_find_available_providers(self):
+        from faker.utils.loading import find_available_providers
+        from faker.config import DEFAULT_PROVIDERS_MODULES
+        from importlib import import_module
+
+        modules = [import_module(path) for path in DEFAULT_PROVIDERS_MODULES]
+        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',
+        ]))
+        self.assertEqual(providers, expected_providers)
+
+
 class FactoryTestCase(unittest.TestCase):
 
     def setUp(self):