From e28f09512600ff1e4c250c65a5d2a58ba5adf494 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Mon, 31 Mar 2014 11:45:14 -0400
Subject: [PATCH 1/2] Do away with the module-level singleton.

---
 libtaskotron/config.py     | 21 +--------------------
 testing/functest_config.py |  8 ++++----
 testing/test_config.py     | 19 +++----------------
 3 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/libtaskotron/config.py b/libtaskotron/config.py
index 5364654..91bd71d 100644
--- a/libtaskotron/config.py
+++ b/libtaskotron/config.py
@@ -30,27 +30,8 @@ CONF_FILE = 'taskotron.yaml'
 # environment variable name for setting config profile
 PROFILE_VAR = 'TASKOTRON_PROFILE'
 
-# a singleton instance of Config
-_config = None
 
-
-def get_config():
-    '''Get Config instance.
-
-    @return either @class Config or its subclass, depending on taskotron
-            profile used. This method is implemented using the singleton pattern
-            - you will always receive the same instance, which will get
-            auto-initialized on the first method call.
-    @throw TaskotronConfigError if file config parsing and handling failed
-    '''
-
-    global _config
-    if not _config:
-        _config = _get_instance()
-    return _config
-
-
-def _get_instance():
+def load_config():
     '''Do everything necessary to fully initialize Config instance, update it
     with external configuration, make all final touches.
 
diff --git a/testing/functest_config.py b/testing/functest_config.py
index c066bc4..147cd4d 100644
--- a/testing/functest_config.py
+++ b/testing/functest_config.py
@@ -55,7 +55,7 @@ class TestConfig(object):
         # create an empty config file
         tmpconffile.write('# just a comment')
 
-        conf = config.get_config()
+        conf = config.load_config()
         assert conf.profile == config.ProfileName.DEVELOPMENT
 
     def test_profile_override_in_conf(self, tmpconffile):
@@ -64,7 +64,7 @@ class TestConfig(object):
         # set a profile in config file
         tmpconffile.write('profile: %s' % config.ProfileName.PRODUCTION)
 
-        conf = config.get_config()
+        conf = config.load_config()
         assert conf.profile == config.ProfileName.PRODUCTION
 
     def test_profile_envvar(self, monkeypatch, tmpconffile):
@@ -75,7 +75,7 @@ class TestConfig(object):
         # set a profile in config file
         tmpconffile.write('profile: %s' % config.ProfileName.DEVELOPMENT)
 
-        conf = config.get_config()
+        conf = config.load_config()
         assert conf.profile == config.ProfileName.PRODUCTION
 
     def test_conf_file_overrride(self, monkeypatch, tmpconffile):
@@ -89,7 +89,7 @@ profile: %s
 tmpdir: /some/path
 '''     % config.ProfileName.DEVELOPMENT)
 
-        conf = config.get_config()
+        conf = config.load_config()
         assert conf.tmpdir == '/some/path'
         assert conf.tmpdir != config.ProductionConfig().tmpdir
 
diff --git a/testing/test_config.py b/testing/test_config.py
index 176f463..2329922 100644
--- a/testing/test_config.py
+++ b/testing/test_config.py
@@ -14,11 +14,6 @@ from libtaskotron import exceptions as exc
 
 class TestConfig(object):
 
-    def teardown_method(self, method):
-        '''Run this after every method execution ends'''
-        # reset the singleton instance back
-        config._config = None
-
     def unset_profile(self, monkeypatch):
         '''Unset the profile environment variable
 
@@ -36,20 +31,12 @@ class TestConfig(object):
     def test_testing_profile(self):
         '''By default we should have a testing profile'''
         assert os.getenv(config.PROFILE_VAR) == config.ProfileName.TESTING
-        conf = config.get_config()
+        conf = config.load_config()
         print conf
         assert conf.profile == config.ProfileName.TESTING
         assert isinstance(conf, config.TestingConfig)
         assert not conf.load_conf_files
 
-    def test_singleton_instance(self):
-        '''Test whether we really have a singleton Config instance'''
-        conf = config.get_config()
-        assert isinstance(conf, config.Config)
-        assert conf is config._config
-        conf2 = config.get_config()
-        assert conf2 is conf
-
     def test_load_defaults(self):
         '''Test _load_defaults() function'''
         for attr, value in vars(config.ProfileName).items():
@@ -112,7 +99,7 @@ option5: False''')
 
     def test_merge_config(self):
         '''Test _merge_config() function'''
-        conf = config.get_config()
+        conf = config.load_config()
         # let's try to override 'tmpdir'
         # the only exception is 'profile', it must not be overridden
         assert hasattr(conf, 'tmpdir')
@@ -146,5 +133,5 @@ option5: False''')
         self.disable_create_dirs(monkeypatch)
         # make sure we don't find any config files
         monkeypatch.setattr(config, 'CONF_DIRS', [])
-        conf = config.get_config()
+        conf = config.load_config()
         assert conf.profile == config.ProfileName.DEVELOPMENT
-- 
1.9.0

