def test_process(self): def f1(): PipedProcess(None) def f2(): PipedProcess('java')(None) self.assertRaises(AssertionError, f1) self.assertRaises(AssertionError, f2) class Callback(object): def __init__(self, data = None): self.data = data def read(self, pipe): return pipe.read() def send(self, pipe): if self.data != None: pipe.write(self.data) cls_file = os.path.join(os.path.dirname(__file__), "echo_process.class") src_file = os.path.join(os.path.dirname(__file__), "echo_process.java") destination = os.path.join(os.path.dirname(GRAVITY_LIB_HOME), 'test') if os.path.exists(cls_file): os.remove(cls_file) r = PipedProcess('javac')(Callback(), [ "-d %s" % destination, src_file ] ) self.assertEqual(os.path.exists(cls_file), True) jr = JavaClassRunner('gravity.common.echo_process') jr.classpath = [ destination ] d = "Hello World" r = jr(Callback(d)) self.assertEqual(d, r)
def _tokenize(self, text): if self.class_loader: if self.ner_instance == None: self.ner_instance = self.class_loader.loadClass(self.java_class())(self.jython_parameters()) l = self.jython_tagger_listener() self.ner_instance.tag(text, l); return l.result else: callback = self.callback(text) java_runner = JavaClassRunner(self.java_class()) java_runner.options = self.java_options() java_runner.classpath = self.java_classpath() return java_runner(callback, self.parameters())
def test_process(self): def f1(): PipedProcess(None) def f2(): PipedProcess('java')(None) self.assertRaises(AssertionError, f1) self.assertRaises(AssertionError, f2) class Callback(object): def __init__(self, data=None): self.data = data def read(self, pipe): return pipe.read() def send(self, pipe): if self.data != None: pipe.write(self.data) cls_file = os.path.join(os.path.dirname(__file__), "echo_process.class") src_file = os.path.join(os.path.dirname(__file__), "echo_process.java") destination = os.path.join(os.path.dirname(GRAVITY_LIB_HOME), 'test') if os.path.exists(cls_file): os.remove(cls_file) r = PipedProcess('javac')(Callback(), ["-d %s" % destination, src_file]) self.assertEqual(os.path.exists(cls_file), True) jr = JavaClassRunner('gravity.common.echo_process') jr.classpath = [destination] d = "Hello World" r = jr(Callback(d)) self.assertEqual(d, r)