# Path: pyqi/core/interface.py
# def get_command_names(config_base_name):
#     """Return a list of available command names.
# 
#     Command names are strings and are returned in alphabetical order.
#     ``config_base_name`` must be the python module path to a directory
#     containing config files.
#     """
#     # Load the interface configuration base.
#     try:
#         config_base_module = importlib.import_module(config_base_name)
#     except ImportError:
#         raise ImportError("Unable to load base config module: %s" %
#                           config_base_name)
# 
#     config_base_dir = dirname(config_base_module.__file__)
# 
#     # from http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python
#     command_names = CommandList()
#     for f in glob(join(config_base_dir, '*.py')):
#         command_name = basename(f)
# 
#         if not command_name.startswith('__init__'):
#             command_names.append(command_name[:-3])
#     command_names.sort()
# 
#     return command_names
# 
# def get_command_config(command_config_module, cmd, exit_on_failure=True):
#     """Get the configuration for a ``Command``"""
#     cmd_cfg = None
#     error_msg = None
#     python_cmd_name = cmd.replace('-', '_')
# 
#     try:
#         cmd_cfg = importlib.import_module('.'.join([command_config_module,
#                                                     python_cmd_name]))
#     except ImportError as e:
#         error_msg = str(e)
#         
#         if exit_on_failure:
#             stderr.write("Unable to import the command configuration for "
#                          "%s:\n" % cmd)
#             stderr.write(error_msg)
#             stderr.write('\n')
#             exit(1)
# 
#     return cmd_cfg, error_msg
# 
# Path: pyqi/util.py
# def is_py2():
#     """Check if we're using Python 2"""
#     if sys.version_info.major == 2:
#         return True
#     else:
#         return False


import sys
import pyqi.interfaces.optparse.config.make_bash_completion
from unittest import TestCase, main
from pyqi.core.interface import get_command_names, get_command_config
from pyqi.util import is_py2
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
from __future__ import division

__credits__ = ["Greg Caporaso", "Daniel McDonald", "Doug Wendel",
               "Jai Ram Rideout"]



class TopLevelTests(TestCase):
    def test_get_command_names(self):
        """Test that command names are returned from a config directory."""
        exp = ['make-bash-completion', 'make-command', 'make-optparse',
               'make-release', 'serve-html-interface']
        obs = get_command_names('pyqi.interfaces.optparse.config')
        self.assertEqual(obs, exp)

        # Invalid config dir.
        with self.assertRaises(ImportError):
            _ = get_command_names('foo.bar.baz-aar')

    def test_get_command_config(self):
        """Test successful and unsuccessful module loading."""
        cmd_cfg, error_msg = get_command_config(
                'pyqi.interfaces.optparse.config', 'make_bash_completion')
        self.assertEqual(cmd_cfg,
                         pyqi.interfaces.optparse.config.make_bash_completion)
        self.assertEqual(error_msg, None)


# Path: pyqi/core/interface.py
# def get_command_names(config_base_name):
#     """Return a list of available command names.
# 
#     Command names are strings and are returned in alphabetical order.
#     ``config_base_name`` must be the python module path to a directory
#     containing config files.
#     """
#     # Load the interface configuration base.
#     try:
#         config_base_module = importlib.import_module(config_base_name)
#     except ImportError:
#         raise ImportError("Unable to load base config module: %s" %
#                           config_base_name)
# 
#     config_base_dir = dirname(config_base_module.__file__)
# 
#     # from http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python
#     command_names = CommandList()
#     for f in glob(join(config_base_dir, '*.py')):
#         command_name = basename(f)
# 
#         if not command_name.startswith('__init__'):
#             command_names.append(command_name[:-3])
#     command_names.sort()
# 
#     return command_names
# 
# def get_command_config(command_config_module, cmd, exit_on_failure=True):
#     """Get the configuration for a ``Command``"""
#     cmd_cfg = None
#     error_msg = None
#     python_cmd_name = cmd.replace('-', '_')
# 
#     try:
#         cmd_cfg = importlib.import_module('.'.join([command_config_module,
#                                                     python_cmd_name]))
#     except ImportError as e:
#         error_msg = str(e)
#         
#         if exit_on_failure:
#             stderr.write("Unable to import the command configuration for "
#                          "%s:\n" % cmd)
#             stderr.write(error_msg)
#             stderr.write('\n')
#             exit(1)
# 
#     return cmd_cfg, error_msg
# 
# Path: pyqi/util.py
# def is_py2():
#     """Check if we're using Python 2"""
#     if sys.version_info.major == 2:
#         return True
#     else:
#         return False


# Path: tests/test_core/test_interface.py
import sys
import pyqi.interfaces.optparse.config.make_bash_completion
from unittest import TestCase, main
from pyqi.core.interface import get_command_names, get_command_config
from pyqi.util import is_py2

#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
from __future__ import division

__credits__ = ["Greg Caporaso", "Daniel McDonald", "Doug Wendel",
               "Jai Ram Rideout"]



class TopLevelTests(TestCase):
    def test_get_command_names(self):
        """Test that command names are returned from a config directory."""
        exp = ['make-bash-completion', 'make-command', 'make-optparse',
               'make-release', 'serve-html-interface']
        obs = get_command_names('pyqi.interfaces.optparse.config')
        self.assertEqual(obs, exp)

        # Invalid config dir.
        with self.assertRaises(ImportError):
            _ = get_command_names('foo.bar.baz-aar')

    def test_get_command_config(self):
        """Test successful and unsuccessful module loading."""
        cmd_cfg, error_msg = get_command_config(
                'pyqi.interfaces.optparse.config', 'make_bash_completion')
        self.assertEqual(cmd_cfg,
                         pyqi.interfaces.optparse.config.make_bash_completion)
        self.assertEqual(error_msg, None)


        cmd_cfg, error_msg = get_command_config(