class TestRegistry(TestCase): def setUp(self): self._registry = Registry() def test_register(self): def foo(config): self.assertEqual({"foo": "bar"}, config) return {"qux": "baz"} self._registry.register("foo", foo) result = self._registry.execute("foo", {"foo": "bar"}) self.assertEqual({"qux": "baz"}, result) def test_execute_raises_invalid_module(self): with self.assertRaises(InvalidModule): self._registry.execute("foo", lambda: None)
def main(): option_parser = optparse.OptionParser() option_parser.add_option( "-v", "--version", dest="version", default=None, help="set the version of the output package") option_parser.add_option( "-c", "--config", dest="config_file", default=None, help="use a specific config file instead of .ubuild.json") option_parser.add_option( "-m", "--build_module", dest="build_module", default=False, action="store_true", help="run build command for the module, if applicable") options, _ = option_parser.parse_args() config_file = options.config_file or _DEFAULT_JSON_FILE config = load_configuration(config_file) extra_config = { "options.config": options.config_file, "options.version": options.version } registry = Registry() import_modules = config.get("import_modules", []) import_modules = set(import_modules + _DEFAULT_IMPORT_MODULES) for module_name in import_modules: module = importlib.import_module(module_name) module.register(registry) context = {} for step_configuration in config["steps"]: step_name = step_configuration.pop("name") step_configuration.update(extra_config) registry.execute( step_name, context, step_configuration, helpers.execute)
def setUp(self): self._registry = Registry()