From eafb8eb9921e315b1229eeeb50f3ecf88cc3b338 Mon Sep 17 00:00:00 2001 From: Minoru Osuka Date: Mon, 20 Mar 2023 21:48:11 +0900 Subject: [PATCH] Add test --- Makefile | 27 +++++++++++++++++++++++++++ examples/analysis_example.py | 2 +- pyproject.toml | 7 +++++++ src/lib.rs | 2 +- tests/__init__py | 0 tests/test_analyze.py | 23 +++++++++++++++++++++++ 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 tests/__init__py create mode 100644 tests/test_analyze.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c764b0f --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +clean: + cargo clean + find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf + +lint: + black --check examples tests + +fmt: + cargo fmt + black examples/* tests/* + +.PHONY: tests +test: + cargo test + python3 -m pytest tests + +develop: + maturin develop --release + +build: + maturin build -i python3 --release + +install: + pip install . lindera_py + +uninstall: + pip uninstall -y lindera_py diff --git a/examples/analysis_example.py b/examples/analysis_example.py index 9695cc9..e8d090d 100644 --- a/examples/analysis_example.py +++ b/examples/analysis_example.py @@ -17,5 +17,5 @@ def main(): print(f"token: {token.text}, details: {token.details}") -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/pyproject.toml b/pyproject.toml index 683ae1c..2c0d8cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,8 @@ build-backend = "maturin" [project] name = "lindera-py" +description = "Python binding for Lindera." +readme = "README.md" requires-python = ">=3.7" classifiers = [ "Programming Language :: Rust", @@ -11,3 +13,8 @@ classifiers = [ "Programming Language :: Python :: Implementation :: PyPy", ] +[project.optional-dependencies] +test = [ + "pytest >= 7.2.0", + "black >= 23.1.0" +] diff --git a/src/lib.rs b/src/lib.rs index c157a16..e450105 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use pyo3::exceptions::PyValueError; use pyo3::prelude::*; use lindera::analyzer::Analyzer; -use lindera::{FilteredToken}; +use lindera::FilteredToken; #[pyclass(name = "Analyzer")] struct PyAnalyzer { diff --git a/tests/__init__py b/tests/__init__py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_analyze.py b/tests/test_analyze.py new file mode 100644 index 0000000..ef95b3b --- /dev/null +++ b/tests/test_analyze.py @@ -0,0 +1,23 @@ +from pathlib import Path +from lindera_py import Analyzer + + +def test_analyze(): + lindera_conf_path = Path("resources") / "lindera_ipadic_conf.json" + analyzer = Analyzer(config_path=str(lindera_conf_path)) + + text = "Linderaは形態素解析エンジンです。ユーザー辞書も利用可能です。" + + # tokenize the text + tokens = analyzer.analyze(text) + + assert tokens[0].text == "Lindera" + assert tokens[1].text == "形態素" + assert tokens[2].text == "解析" + assert tokens[3].text == "エンジン" + assert tokens[4].text == "ユーザ" + assert tokens[5].text == "辞書" + assert tokens[6].text == "利用" + assert tokens[7].text == "可能" + + assert len(tokens) == 8