File size: 1,757 Bytes
e4b9a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0

import unittest

from pythainlp import __main__, cli
from pythainlp.cli.benchmark import App as BenchmarkApp
from pythainlp.cli.data import App as DataApp
from pythainlp.cli.tokenize import App as TokenizeApp


class CliTestCaseX(unittest.TestCase):
    def test_cli_benchmark(self):
        self.assertTrue(hasattr(cli, "benchmark"))

        with self.assertRaises(SystemExit) as ex:
            DataApp(["thainlp", "benchmark"])
        self.assertEqual(ex.exception.code, 2)

        self.assertIsNotNone(
            BenchmarkApp(
                [
                    "thainlp",
                    "benchmark",
                    "word-tokenization",
                    "--input-file",
                    "./tests/data/input.txt",
                    "--test-file",
                    "./tests/data/test.txt",
                    "--save-details",
                ]
            )
        )

    def test_cli_tokenize(self):
        self.assertIsNotNone(
            TokenizeApp(
                [
                    "thainlp",
                    "tokenize",
                    "sent",
                    "-s",
                    "|",
                    (
                        "ถ้าฉันยิงกระต่ายได้ ฉันก็ยิงฟาสซิสต์ได้"
                        "กระสุนสำหรับสมองของคุณวันนี้"
                        "แต่คุณก็จะลืมมันไปทั้งหมดอีกครั้ง"
                    ),
                ]
            )
        )