Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuka committed Mar 20, 2023
1 parent b34ab29 commit eafb8eb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/analysis_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def main():
print(f"token: {token.text}, details: {token.details}")


if __name__ == '__main__':
if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ build-backend = "maturin"

[project]
name = "lindera-py"
description = "Python binding for Lindera."
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

[project.optional-dependencies]
test = [
"pytest >= 7.2.0",
"black >= 23.1.0"
]
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Empty file added tests/__init__py
Empty file.
23 changes: 23 additions & 0 deletions tests/test_analyze.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eafb8eb

Please sign in to comment.