Пример #1
0
    def test_libpath_defaulting(self):
        '''Test automatic library path defaulting.'''
        orig = os.getenv(environment.MeCabEnv.MECAB_PATH)

        try:
            del os.environ[environment.MeCabEnv.MECAB_PATH]
            noenv = environment.MeCabEnv()

            if sys.platform == 'win32':
                res = Popen(['mecab', '-D'], stdout=PIPE).communicate()
                lines = res[0].decode()
                dicinfo = lines.split(os.linesep)
                t = [t for t in dicinfo if t.startswith('filename')]
                ldir = t[0].split('etc')[0][10:].strip()
                expected = os.path.join(ldir, 'bin', 'libmecab.dll')
            else:
                if sys.platform == 'darwin':
                    lib = 'libmecab.dylib'
                else:
                    lib = 'libmecab.so'

                res = Popen(['mecab-config', '--libs-only-L'],
                            stdout=PIPE).communicate()
                lines = res[0].decode()
                linfo = lines.strip()
                expected = os.path.join(linfo, lib)

            self.assertEqual(noenv.libpath, expected)
        finally:
            os.environ[environment.MeCabEnv.MECAB_PATH] = orig
Пример #2
0
    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)
Пример #3
0
    def setUp(self):
        cwd = os.getcwd()
        if sys.platform == 'win32':
            self.testfile = os.path.join(cwd, 'tests', 'test_sjis')
        else:
            self.testfile = os.path.join(cwd, 'tests', 'test_utf8')

        self.env = env.MeCabEnv()

        with codecs.open(self.testfile, 'r') as f:
            self.text = f.readlines()[0].strip()
Пример #4
0
    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)
Пример #5
0
    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()

        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)
Пример #6
0
    def test_charset_defaulting(self):
        '''Test automatic charset defaulting.'''
        orig = os.getenv(environment.MeCabEnv.MECAB_CHARSET)

        try:
            del os.environ[environment.MeCabEnv.MECAB_CHARSET]
            noenv = environment.MeCabEnv()

            res = Popen(['mecab', '-D'], stdout=PIPE).communicate()
            lines = res[0].decode()
            dicinfo = lines.split(os.linesep)
            t = [t for t in dicinfo if t.startswith('charset')]
            expected = t[0].split('\t')[1].strip()

            self.assertEqual(noenv.charset.lower(), expected.lower())
        finally:
            os.environ[environment.MeCabEnv.MECAB_CHARSET] = orig
Пример #7
0
 def setUp(self):
     self.env = environment.MeCabEnv()
Пример #8
0
 def setUp(self):
     self.env = env.MeCabEnv()
     self.op = OptionParse(self.env.charset)