コード例 #1
0
def reload_hdb_connector():  # pragma: no cover
    '''
    As hdb_connector uses pyhdb or dbapi, if these packages are installed on the fly,
    we need to reload the connector to import the correct api
    '''
    def __import_mod(name):
        '''
        Find more info in: https://docs.python.org/2/library/imp.html
        '''
        try:
            return sys.modules[name]
        except KeyError:
            pass

        file_ptr, pathname, description = imp.find_module(name)

        try:
            return imp.load_module(name, file_ptr, pathname, description)
        finally:
            # Since we may exit via an exception, close file_ptr explicitly.
            if file_ptr:
                file_ptr.close()

    if sys.version_info.major == 2:
        # pyhdbcli has a cyclical import so it raises an error, but the module is loaded properly
        try:
            __import_mod('pyhdbcli')
        except ImportError:
            pass
        __import_mod('hdbcli/dbapi')
        __import_mod('hdbcli')

    reload_module(hdb_connector)
コード例 #2
0
 def test_get_encodings(self):
     # reload locales modules before and after to defeat memoization of
     # get_encodings()
     reload_module(locales)
     with patch('sys.getdefaultencoding', return_value='xyzzy'):
         encodings = locales.get_encodings()
         for enc in (__salt_system_encoding__, 'xyzzy', 'utf-8', 'latin-1'):
             self.assertIn(enc, encodings)
     reload_module(locales)
コード例 #3
0
ファイル: locales_test.py プロジェクト: DaveQB/salt
 def test_get_encodings(self):
     # reload locales modules before and after to defeat memoization of
     # get_encodings()
     reload_module(locales)
     with patch('sys.getdefaultencoding', return_value='xyzzy'):
         encodings = locales.get_encodings()
         for enc in (__salt_system_encoding__, 'xyzzy', 'utf-8', 'latin-1'):
             self.assertIn(enc, encodings)
     reload_module(locales)
コード例 #4
0
 def test_get_encodings(self):
     # reload locales modules before and after to defeat memoization of
     # get_encodings()
     reload_module(locales)
     with patch("sys.getdefaultencoding", return_value="xyzzy"):
         encodings = locales.get_encodings()
         for enc in (__salt_system_encoding__, "xyzzy", "utf-8", "latin-1"):
             self.assertIn(enc, encodings)
     reload_module(locales)