# Path: bento/core/testing.py
# def create_fake_package_from_bento_infos(top_node, bento_infos, bscripts=None):
#     if bscripts is None:
#         bscripts = {}
#     for loc, content in bento_infos.items():
#         n = top_node.make_node(loc)
#         n.parent.mkdir()
#         n.write(content)
#     for loc, content in bscripts.items():
#         n = top_node.make_node(loc)
#         n.parent.mkdir()
#         n.write(content)
# 
#     d = raw_parse(bento_infos["bento.info"])
#     _kw, files = raw_to_pkg_kw(d, {}, None)
#     subpackages = _kw.get("subpackages", {})
# 
#     py_modules = _kw.get("py_modules", [])
#     if "extensions" in _kw:
#         extensions = list(_kw["extensions"].values())
#     else:
#         extensions = []
#     if "compiled_libraries" in _kw:
#         compiled_libraries = list(_kw["compiled_libraries"].values())
#     else:
#         compiled_libraries = []
#     if "extra_source_files" in _kw:
#         extra_source_files = list(_kw["extra_source_files"])
#     else:
#         extra_source_files = []
# 
#     packages = _kw.get("packages", [])
#     for name, spkg in subpackages.items():
#         n = top_node.search(name)
#         n.write(bento_infos[name])
#         d = n.parent
#         for py_module in spkg.py_modules:
#             m = d.make_node(py_module)
#             py_modules.append(m.path_from(top_node))
# 
#         extensions.extend(flatten_extensions(top_node, spkg))
#         compiled_libraries.extend(flatten_compiled_libraries(top_node, spkg))
#         packages.extend(flatten_packages(top_node, spkg))
# 
#     return create_fake_package(top_node, packages, py_modules, extensions, compiled_libraries,
#                                extra_source_files)
# 
# Path: bento/commands/utils.py
# def has_cython_code(pkg):
#     for extension in pkg.extensions.values():
#         for source in extension.sources:
#             if source.endswith("pyx"):
#                 return True
# 
#     if pkg.subpackages:
#         for spkg in pkg.subpackages.values():
#             for extension in spkg.extensions.values():
#                 for source in extension.sources:
#                     if source.endswith("pyx"):
#                         return True
#     return False


import os
import tempfile
import shutil
import os.path as op
from bento.core \
    import \
        PackageDescription
from bento.compat.api.moves \
    import \
        unittest
from bento.core.node \
    import \
        create_base_nodes
from bento.core.testing \
    import \
        create_fake_package_from_bento_infos
from bento.commands.utils \
    import \
        has_cython_code
        os.chdir(self.d)

        self.top_node, self.build_node, self.run_node = create_base_nodes()

    def tearDown(self):
        os.chdir(self.old_dir)
        shutil.rmtree(self.d)

    def test_simple_cython(self):
        bento_info = """\
Library:
    Extension: foo
        Sources: foo1.c, foo2.pyx
"""
        bentos = {"bento.info": bento_info}
        create_fake_package_from_bento_infos(self.run_node, bentos)

        pkg = PackageDescription.from_string(bento_info)
        self.assertTrue(has_cython_code(pkg))

    def test_simple_no_cython(self):
        bento_info = """\
Library:
    Extension: foo
        Sources: foo1.c, foo2.c
"""
        bentos = {"bento.info": bento_info}
        create_fake_package_from_bento_infos(self.run_node, bentos)

        pkg = PackageDescription.from_string(bento_info)

# Path: bento/core/testing.py
# def create_fake_package_from_bento_infos(top_node, bento_infos, bscripts=None):
#     if bscripts is None:
#         bscripts = {}
#     for loc, content in bento_infos.items():
#         n = top_node.make_node(loc)
#         n.parent.mkdir()
#         n.write(content)
#     for loc, content in bscripts.items():
#         n = top_node.make_node(loc)
#         n.parent.mkdir()
#         n.write(content)
# 
#     d = raw_parse(bento_infos["bento.info"])
#     _kw, files = raw_to_pkg_kw(d, {}, None)
#     subpackages = _kw.get("subpackages", {})
# 
#     py_modules = _kw.get("py_modules", [])
#     if "extensions" in _kw:
#         extensions = list(_kw["extensions"].values())
#     else:
#         extensions = []
#     if "compiled_libraries" in _kw:
#         compiled_libraries = list(_kw["compiled_libraries"].values())
#     else:
#         compiled_libraries = []
#     if "extra_source_files" in _kw:
#         extra_source_files = list(_kw["extra_source_files"])
#     else:
#         extra_source_files = []
# 
#     packages = _kw.get("packages", [])
#     for name, spkg in subpackages.items():
#         n = top_node.search(name)
#         n.write(bento_infos[name])
#         d = n.parent
#         for py_module in spkg.py_modules:
#             m = d.make_node(py_module)
#             py_modules.append(m.path_from(top_node))
# 
#         extensions.extend(flatten_extensions(top_node, spkg))
#         compiled_libraries.extend(flatten_compiled_libraries(top_node, spkg))
#         packages.extend(flatten_packages(top_node, spkg))
# 
#     return create_fake_package(top_node, packages, py_modules, extensions, compiled_libraries,
#                                extra_source_files)
# 
# Path: bento/commands/utils.py
# def has_cython_code(pkg):
#     for extension in pkg.extensions.values():
#         for source in extension.sources:
#             if source.endswith("pyx"):
#                 return True
# 
#     if pkg.subpackages:
#         for spkg in pkg.subpackages.values():
#             for extension in spkg.extensions.values():
#                 for source in extension.sources:
#                     if source.endswith("pyx"):
#                         return True
#     return False


# Path: bento/commands/tests/test_utils.py
import os
import tempfile
import shutil
import os.path as op
from bento.core \
    import \
        PackageDescription
from bento.compat.api.moves \
    import \
        unittest
from bento.core.node \
    import \
        create_base_nodes
from bento.core.testing \
    import \
        create_fake_package_from_bento_infos
from bento.commands.utils \
    import \
        has_cython_code

        os.chdir(self.d)

        self.top_node, self.build_node, self.run_node = create_base_nodes()

    def tearDown(self):
        os.chdir(self.old_dir)
        shutil.rmtree(self.d)

    def test_simple_cython(self):
        bento_info = """\
Library:
    Extension: foo
        Sources: foo1.c, foo2.pyx
"""
        bentos = {"bento.info": bento_info}
        create_fake_package_from_bento_infos(self.run_node, bentos)

        pkg = PackageDescription.from_string(bento_info)
        self.assertTrue(has_cython_code(pkg))

    def test_simple_no_cython(self):
        bento_info = """\
Library:
    Extension: foo
        Sources: foo1.c, foo2.c
"""
        bentos = {"bento.info": bento_info}
        create_fake_package_from_bento_infos(self.run_node, bentos)

        pkg = PackageDescription.from_string(bento_info)

        self.assertFalse(has_cython_code(pkg))