# Path: pywrap/import_hook.py
# class CppFinder(object):
#     """Finds C++ headers and builds Python bindings."""
#     def __init__(self, import_path="."):
#         self.config = Config()
#         self.import_path = import_path
# 
#     def find_module(self, fullname, path):
#         header_ending = None
#         for ending in self.config.cpp_header_endings:
#             if os.path.exists(self.import_path + os.sep + fullname + "." +
#                               ending):
#                 header_ending = ending
#                 break
#         if header_ending is None:
#             return None
# 
#         header = self.import_path + os.sep + fullname + "." + header_ending
#         lib = fullname + ".so"
#         if not os.path.exists(lib):
#             files = make_cython_wrapper(header, [], config=self.config)
#             files["setup_import.py"] = files["setup.py"]
#             del files["setup.py"]
# 
#             write_files(files)
#             try:
#                 run_setup("setup_import.py")
#             finally:
#                 filenames = [fullname + ".cpp"]
#                 filenames.extend(files.keys())
#                 remove_files(filenames)
# 
#         return None
# 
# Path: pywrap/testing.py
# PREFIX = os.sep.join(__file__.split(os.sep)[:-2] + ["test"])
# 
# Path: pywrap/utils.py
# def remove_files(filenames):
#     """Remove files if they exist."""
#     for f in filenames:
#         if os.path.exists(f):
#             os.remove(f)


import sys
        import doubleindoubleout
from pywrap.import_hook import CppFinder
from pywrap.testing import PREFIX
from pywrap.utils import remove_files
from nose.tools import assert_equal, assert_raises


def test_import_hook_missing_header():
    del sys.meta_path[:]
    sys.meta_path.append(CppFinder(import_path=PREFIX))
    try:
        assert_raises(ImportError, __import__, "missing")
    finally:
        del sys.meta_path[:]


def test_import_hook():
    del sys.meta_path[:]

# Path: pywrap/import_hook.py
# class CppFinder(object):
#     """Finds C++ headers and builds Python bindings."""
#     def __init__(self, import_path="."):
#         self.config = Config()
#         self.import_path = import_path
# 
#     def find_module(self, fullname, path):
#         header_ending = None
#         for ending in self.config.cpp_header_endings:
#             if os.path.exists(self.import_path + os.sep + fullname + "." +
#                               ending):
#                 header_ending = ending
#                 break
#         if header_ending is None:
#             return None
# 
#         header = self.import_path + os.sep + fullname + "." + header_ending
#         lib = fullname + ".so"
#         if not os.path.exists(lib):
#             files = make_cython_wrapper(header, [], config=self.config)
#             files["setup_import.py"] = files["setup.py"]
#             del files["setup.py"]
# 
#             write_files(files)
#             try:
#                 run_setup("setup_import.py")
#             finally:
#                 filenames = [fullname + ".cpp"]
#                 filenames.extend(files.keys())
#                 remove_files(filenames)
# 
#         return None
# 
# Path: pywrap/testing.py
# PREFIX = os.sep.join(__file__.split(os.sep)[:-2] + ["test"])
# 
# Path: pywrap/utils.py
# def remove_files(filenames):
#     """Remove files if they exist."""
#     for f in filenames:
#         if os.path.exists(f):
#             os.remove(f)


# Path: test/test_import_hook.py
import sys
        import doubleindoubleout
from pywrap.import_hook import CppFinder
from pywrap.testing import PREFIX
from pywrap.utils import remove_files
from nose.tools import assert_equal, assert_raises



def test_import_hook_missing_header():
    del sys.meta_path[:]
    sys.meta_path.append(CppFinder(import_path=PREFIX))
    try:
        assert_raises(ImportError, __import__, "missing")
    finally:
        del sys.meta_path[:]


def test_import_hook():
    del sys.meta_path[:]

    sys.meta_path.append(CppFinder(import_path=PREFIX))