def test_extension(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar Library: Extension: foo Sources: src/foo.c """ sub_bento_info = """\ Library: Extension: foo Sources: src/foo.c """ r_bento_info = """\ Name: foo Library: Extension: foo Sources: src/foo.c Extension: bar.foo Sources: bar/src/foo.c """ bentos = {"bento.info": bento_info, op.join("bar", "bento.info"): sub_bento_info} create_fake_package_from_bento_infos(run_node, bentos) node_pkg, r_node_pkg = self._create_package_and_reference(bento_info, r_bento_info) self.assertEqual( comparable_representation(self.top_node, node_pkg), comparable_representation(self.top_node, r_node_pkg) )
def test_py_packages(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar Library: Packages: bar """ sub_bento_info = """\ Library: Packages: foo """ r_bento_info = """\ Name: foo Library: Packages: bar, bar.foo """ bentos = {"bento.info": bento_info, "bar/bento.info": sub_bento_info} create_fake_package_from_bento_infos(run_node, bentos) node_pkg, r_node_pkg = self._create_package_and_reference(bento_info, r_bento_info) self.assertEqual(node_pkg.iter_category("packages"), r_node_pkg.iter_category("packages"))
def test_simple(self): bscript = """\ from bento.commands import hooks PRE = False POST = False @hooks.pre_configure def pre_configure(ctx): global PRE PRE = True @hooks.post_configure def post_configure(ctx): global POST POST = True """ bento = """\ Name: foo Version: 1.0 HookFile: bscript """ create_fake_package_from_bento_infos(self.top_node, {"bento.info": bento}, {"bscript": bscript}) conf, configure = prepare_configure(self.top_node, bento, ConfigureContext) bscript = self.top_node.search("bscript") m = create_hook_module(bscript.abspath()) self.assertEqual(len(find_pre_hooks([m], "configure")), 1) self.assertEqual(len(find_post_hooks([m], "configure")), 1)
def test_py_packages(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar Library: Packages: bar """ sub_bento_info = """\ Library: Packages: foo """ r_bento_info = """\ Name: foo Library: Packages: bar, bar.foo """ bentos = {"bento.info": bento_info, "bar/bento.info": sub_bento_info} create_fake_package_from_bento_infos(run_node, bentos) node_pkg, r_node_pkg = self._create_package_and_reference(bento_info, r_bento_info) self.assertEqual(comparable_representation(self.top_node, node_pkg), comparable_representation(self.top_node, r_node_pkg))
def test_py_packages(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar Library: Packages: bar """ sub_bento_info = """\ Library: Packages: foo """ r_bento_info = """\ Name: foo Library: Packages: bar, bar.foo """ bentos = { "bento.info": bento_info, op.join("bar", "bento.info"): sub_bento_info } create_fake_package_from_bento_infos(run_node, bentos) node_pkg, r_node_pkg = self._create_package_and_reference( bento_info, r_bento_info) self.assertEqual(comparable_representation(self.top_node, node_pkg), comparable_representation(self.top_node, r_node_pkg))
def _run_configure(self, bentos, bscripts=None, configure_argv=None, build_argv=None): top_node = self.top_node create_fake_package_from_bento_infos(top_node, bentos, bscripts) conf, configure = prepare_configure(top_node, bentos["bento.info"], self._configure_context) run_command_in_context(conf, configure) bld, build = prepare_build(top_node, bentos["bento.info"], self._build_context, build_argv) return conf, configure, bld, build
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))
def _create_contexts(self, bentos, bscripts=None, configure_args=None, build_args=None): top_node = self.top_node create_fake_package_from_bento_infos(top_node, bentos, bscripts) conf, configure = prepare_configure(top_node, bentos["bento.info"], self._configure_context) configure.run(conf) conf.shutdown() bld, build = prepare_build(top_node, conf.pkg, conf.package_options, self._build_context, build_args) return conf, configure, bld, build
def _test_installed_sections(self, bento_infos, r_sections): create_fake_package_from_bento_infos(self.top_node, bento_infos) conf, configure = prepare_configure(self.run_node, bento_infos["bento.info"]) run_command_in_context(conf, configure) bld, build = prepare_build(self.top_node, bento_infos["bento.info"]) run_command_in_context(bld, build) sections = bld.section_writer.sections self.assertEqual(comparable_installed_sections(sections), comparable_installed_sections(r_sections))
def test_hook(self): root = self.root top_node = self.top_node bento_info = """\ Name: foo HookFile: bar/bscript Recurse: bar """ bento_info2 = """\ Library: Packages: fubar """ bscript = """\ from bento.commands import hooks @hooks.pre_configure def configure(ctx): packages = ctx.local_pkg.packages ctx.local_node.make_node("test").write(str(packages)) """ bentos = { "bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2 } bscripts = {os.path.join("bar", "bscript"): bscript} create_fake_package_from_bento_infos(top_node, bentos, bscripts) conf, configure = prepare_configure(self.run_node, bento_info, ConfigureYakuContext) try: hook = top_node.search("bar/bscript") m = create_hook_module(hook.abspath()) for hook in find_pre_hooks([m], "configure"): conf.pre_recurse(root.find_dir(hook.local_dir)) try: hook(conf) finally: conf.post_recurse() test = top_node.search("bar/test") if test: self.assertEqual(test.read(), "['fubar']") else: self.fail("test dummy not found") finally: configure.finish(conf) conf.finish()
def _test_installed_sections(self, bento_infos, r_sections): create_fake_package_from_bento_infos(self.top_node, bento_infos) conf, configure = prepare_configure(self.run_node, bento_infos["bento.info"]) configure.run(conf) conf.shutdown() bld, build = prepare_build(self.top_node, conf.pkg, conf.package_options) build.run(bld) bld.shutdown() sections = bld.section_writer.sections self.assertEqual(comparable_installed_sections(sections), comparable_installed_sections(r_sections))
def test_basics(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar """ bento_info2 = """\ Recurse: foo Library: Extension: _foo Sources: foo.c CompiledLibrary: _bar Sources: foo.c """ bento_info3 = """\ Library: Packages: sub2 """ bentos = { "bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2, os.path.join("bar", "foo", "bento.info"): bento_info3, } create_fake_package_from_bento_infos(run_node, bentos) r_bento_info = """\ Name: foo Library: Packages: bar.foo.sub2 Extension: bar._foo Sources: bar/foo.c CompiledLibrary: bar._bar Sources: bar/foo.c """ node_pkg, r_node_pkg = self._create_package_and_reference(bento_info, r_bento_info) self.assertEqual( comparable_representation(self.top_node, node_pkg), comparable_representation(self.top_node, r_node_pkg) )
def test_hook(self): root = self.root top_node = self.top_node bento_info = """\ Name: foo HookFile: bar/bscript Recurse: bar """ bento_info2 = """\ Library: Packages: fubar """ bscript = """\ from bento.commands import hooks @hooks.pre_configure def configure(ctx): packages = ctx.local_pkg.packages ctx.local_node.make_node("test").write(str(packages)) """ bentos = {"bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2} bscripts = {os.path.join("bar", "bscript"): bscript} create_fake_package_from_bento_infos(top_node, bentos, bscripts) conf, configure = prepare_configure(self.run_node, bento_info, ConfigureYakuContext) try: hook = top_node.search("bar/bscript") m = create_hook_module(hook.abspath()) for hook in find_pre_hooks([m], "configure"): conf.pre_recurse(root.find_dir(hook.local_dir)) try: hook(conf) finally: conf.post_recurse() test = top_node.search("bar/test") if test: self.failUnlessEqual(test.read(), "['fubar']") else: self.fail("test dummy not found") finally: configure.finish(conf) conf.finish()
def test_basics(self): run_node = self.run_node bento_info = """\ Name: foo Recurse: bar """ bento_info2 = """\ Recurse: foo Library: Extension: _foo Sources: foo.c CompiledLibrary: _bar Sources: foo.c """ bento_info3 = """\ Library: Packages: sub2 """ bentos = { "bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2, os.path.join("bar", "foo", "bento.info"): bento_info3 } create_fake_package_from_bento_infos(run_node, bentos) r_bento_info = """\ Name: foo Library: Packages: bar.foo.sub2 Extension: bar._foo Sources: bar/foo.c CompiledLibrary: bar._bar Sources: bar/foo.c """ node_pkg, r_node_pkg = self._create_package_and_reference( bento_info, r_bento_info) self.assertEqual(comparable_representation(self.top_node, node_pkg), comparable_representation(self.top_node, r_node_pkg))
def test_sub_package(self): bento_info = """\ Recurse: foo Library: Extension: foo Sources: foo1.c """ bento_sub1_info = """ Library: Extension: bar Sources: bar.pyx """ bentos = {"bento.info": bento_info, op.join("foo", "bento.info"): bento_sub1_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(self): root = self.root top_node = self.top_node run_node = self.run_node bento_info = """\ Name: foo Recurse: bar """ bento_info2 = """\ Recurse: foo Library: Modules: fubar Extension: _foo Sources: foo.c """ bento_info3 = """\ Library: Modules: foufoufou Packages: sub2 """ bentos = {"bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2, os.path.join("bar", "foo", "bento.info"): bento_info3} create_fake_package_from_bento_infos(run_node, bentos) conf, configure = prepare_configure(run_node, bento_info, ConfigureYakuContext) configure.run(conf) conf.shutdown() build = BuildCommand() opts = OptionsContext.from_command(build) cmd_argv = [] bld = BuildYakuContext(None, cmd_argv, opts, conf.pkg, run_node) build.run(bld)
def test_py_module_invalid(self): """Ensure we get a package error when defining py modules in recursed bento.info.""" bento_info = """\ Name: foo Recurse: bar """ sub_bento_info = """\ Library: Modules: foo """ bentos = {"bento.info": bento_info, os.path.join("bar", "bento.info"): sub_bento_info} self.assertRaises(InvalidPackage, lambda: create_fake_package_from_bento_infos(self.run_node, bentos))
def test_py_module_invalid(self): """Ensure we get a package error when defining py modules in recursed bento.info.""" bento_info = """\ Name: foo Recurse: bar """ sub_bento_info = """\ Library: Modules: foo """ bentos = { "bento.info": bento_info, os.path.join("bar", "bento.info"): sub_bento_info } self.assertRaises( InvalidPackage, lambda: create_fake_package_from_bento_infos( self.run_node, bentos))