Skip to content

Commit

Permalink
Merge ec64789 into b661d75
Browse files Browse the repository at this point in the history
  • Loading branch information
unnonouno committed Oct 12, 2014
2 parents b661d75 + ec64789 commit 54023b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 2 additions & 4 deletions mrep/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

class MeCabParser(object):
def __init__(self, arg=''):
model = MeCab.Model_create(arg)
if model is None:
raise Exception('Cannot initialize mecab')
self.model = model
# it may throw RuntimeError
self.model = MeCab.Model(arg)

def parse(self, s):
tagger = self.model.createTagger()
Expand Down
7 changes: 6 additions & 1 deletion scripts/mrep
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ if __name__ == '__main__':
else:
printer = mrep.printer.Printer(color_begin, color_end)

parser = mrep.morph.MeCabParser(args.mecab_arg)
try:
parser = mrep.morph.MeCabParser(args.mecab_arg)
except Exception as e:
sys.stderr.write('Fail to initialize MeCab\n')
sys.stderr.write('%s\n' % e)
sys.exit(4)

if len(args.file) > 0:
for file in args.file:
Expand Down
6 changes: 6 additions & 0 deletions test/mrep_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ def test_no_pattern(self):
def test_version(self):
out = self.call('--version')
self.assertTrue(__version__ in str(out))

def test_invalid_mecab_arg(self):
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.call('--mecab-arg="--unknown-argument"', '.')

self.assertEqual(4, cm.exception.returncode)

0 comments on commit 54023b4

Please sign in to comment.