From 8da1e0880f38cdd74fa1b73339860a46f3fa7227 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 9 Aug 2009 15:11:25 +0200 Subject: [PATCH] Better error reporting on the pipeline --- t/moe/pipeline.py | 11 +++++++++-- t/test.py | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/t/moe/pipeline.py b/t/moe/pipeline.py index 1804c5b..30c4c58 100644 --- a/t/moe/pipeline.py +++ b/t/moe/pipeline.py @@ -5,6 +5,9 @@ import bisect import imp import moe.log +class MoePipeError(Exception): + """Failure of the MoePipeline.""" + class MoePipeline: """Moe pipeline.""" @@ -17,7 +20,7 @@ class MoePipeline: triple = (pri,name,fun) pos = bisect.bisect(self.pipe, triple) if pos <= self.index: - raise RuntimeError, "MoePipeline.insert cannot alter the past" + raise MoePipeError, "Pipeline insert cannot alter the past" self.pipe.insert(pos, triple) def dump(self, file=sys.stdout): @@ -38,7 +41,11 @@ class MoePipeline: modname = "moe.hooks." + name moe.log.verbose(">> Loading hook %s\n" % name) if not sys.modules.has_key(modname): - fp, path, desc = imp.find_module(name, ["moe/hooks"]) + ## FIXME: Configuration variable for the hook directory? + try: + fp, path, desc = imp.find_module(name, ["moe/hooks"]) + except ImportError: + raise MoePipeError, "Cannot find hook module " + modname try: imp.load_module(modname, fp, path, desc) finally: diff --git a/t/test.py b/t/test.py index 1740395..7250720 100755 --- a/t/test.py +++ b/t/test.py @@ -6,6 +6,7 @@ sys.path.append('.') import moe.meta import moe.config import moe.eval +import moe.pipeline #m = moe.meta.MoeMeta() #m['a'] = '1' @@ -29,4 +30,9 @@ s.dump_defs() print "***" s.dump() -print moe.eval.init_pipeline(s, 'stk_') +p = moe.pipeline.MoePipeline('test') +p.insert(10, 'brum', lambda x: p.insert(30, 'xyzzy', lambda y:y)) +p.insert(20, 'brummm', lambda x: x) +p.configure("y") +p.dump() +p.run(5) -- 2.39.2