# Path: confab/files.py
# def _import(module_name, dir_name):
#     """
#     Load python module from file system without reloading.
# 
#     Raises ImportError if not found.
#     """
#     # assign module a name that's not likely to conflict
#     safe_name = _safe_name(module_name, dir_name)
# 
#     # check if module is already loaded
#     existing = sys.modules.get(safe_name)
#     if existing:
#         return existing
# 
#     # try to load module
#     module_info = imp.find_module(module_name, [dir_name])
#     try:
#         module = imp.load_module(safe_name, *module_info)
#     except ImportError as e:
#         # In the normal case, an import error is raised during imp.find_module()
#         # because the module is not found. However, ImportError can also be raised
#         # if the module itself contains other ImportErrors. Rather than depend on the
#         # error message or invent a non-standard exception type, decorate the error
#         # with the path to the module that was found.
#         e.module_path = module_info[1]
#         raise e
#     return module


from os.path import dirname, join
from unittest import TestCase
from nose.tools import eq_, ok_
from confab.files import _import
"""
Tests for file operations.
"""



class TestImport(TestCase):

    def setUp(self):
        self.dir_name = join(dirname(__file__), 'data/default')

    def test_import_empty(self):
        module = _import("empty", self.dir_name)
        ok_(module)

    def test_import_simple(self):
        module = _import("simple", self.dir_name)
        ok_(module)
        eq_("bar", module.foo)

    def test_import_not_found(self):
        with self.assertRaises(ImportError) as e:

# Path: confab/files.py
# def _import(module_name, dir_name):
#     """
#     Load python module from file system without reloading.
# 
#     Raises ImportError if not found.
#     """
#     # assign module a name that's not likely to conflict
#     safe_name = _safe_name(module_name, dir_name)
# 
#     # check if module is already loaded
#     existing = sys.modules.get(safe_name)
#     if existing:
#         return existing
# 
#     # try to load module
#     module_info = imp.find_module(module_name, [dir_name])
#     try:
#         module = imp.load_module(safe_name, *module_info)
#     except ImportError as e:
#         # In the normal case, an import error is raised during imp.find_module()
#         # because the module is not found. However, ImportError can also be raised
#         # if the module itself contains other ImportErrors. Rather than depend on the
#         # error message or invent a non-standard exception type, decorate the error
#         # with the path to the module that was found.
#         e.module_path = module_info[1]
#         raise e
#     return module


# Path: confab/tests/test_files.py
from os.path import dirname, join
from unittest import TestCase
from nose.tools import eq_, ok_
from confab.files import _import

"""
Tests for file operations.
"""



class TestImport(TestCase):

    def setUp(self):
        self.dir_name = join(dirname(__file__), 'data/default')

    def test_import_empty(self):
        module = _import("empty", self.dir_name)
        ok_(module)

    def test_import_simple(self):
        module = _import("simple", self.dir_name)
        ok_(module)
        eq_("bar", module.foo)

    def test_import_not_found(self):
        with self.assertRaises(ImportError) as e:

            _import("missing", self.dir_name)