def setUp(self): cwd = os.getcwd() if sys.platform == 'win32': self.textfile = os.path.join(cwd, 'tests', 'test_sjis.txt') else: self.textfile = os.path.join(cwd, 'tests', 'test_utf8.txt') yamlfile = os.path.join(cwd, 'tests', 'test_utf8.yml') self.env = env.MeCabEnv() self.b2s, self.s2b = support.string_support(self.env.charset) self.testrc = os.path.join(cwd, 'tests', 'testmecabrc') with codecs.open(self.textfile, 'r') as f: self.text = f.readlines()[0].strip() with codecs.open(yamlfile, 'r', encoding='utf-8') as f: self.yaml = yaml.load(f) cmd = ['mecab', '-P'] mout = Popen(cmd, stdout=PIPE).communicate() res = self.b2s(mout[0]) m = re.search('(?<=dicdir:\s).*', res) ipadic = path.abspath(m.group(0).strip()) with open(path.join(os.getcwd(), 'tests', 'mecabrc.tmp'), 'r') as fin: tmpl = Template(fin.read()) tmpl = tmpl.substitute({'ipadic': ipadic}) with open(self.testrc, 'w') as fout: fout.write(tmpl)
def setUp(self): self.env = env.MeCabEnv() enc = self.env.charset self.bytes2str, self.str2bytes = support.string_support(enc) self.split_pattern, self.split_features = support.splitter_support(enc) cwd = os.getcwd() yamlfile = os.path.join(cwd, 'tests', 'test_utf8.yml') with codecs.open(yamlfile, 'r', encoding='utf-8') as f: self.yaml = yaml.load(f)