Skip to content

Commit

Permalink
ci: Write first testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Apr 30, 2024
1 parent 1bbbf0f commit d9b5c0c
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 1 deletion.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Run CI

on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Lint by pre-commit
run: |
pip install pre-commit
pre-commit run --all-files
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Configure venv
run: |
pip install uv
uv venv
uv pip install -r requirements-dev.lock
- name: Run tests
run: |
source .venv/bin/activate
pytest
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ build-backend = "hatchling.build"
managed = true
dev-dependencies = [
"esbonio~=0.16.4",
"pytest~=8.2.0",
]

[tool.rye.scripts]
setup = {chain = ["setup:sync", "setup:pre-commit"]}
"setup:sync" = "rye sync --no-lock --all-features"
"setup:pre-commit" = "pre-commit install"

test = "pytest"

[tool.ruff.lint]
select = ["C90", "D", "E", "F", "I", "W"]
Expand Down
6 changes: 6 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@ idna==3.7
# via requests
imagesize==1.4.1
# via sphinx
iniconfig==2.0.0
# via pytest
jinja2==3.1.3
# via sphinx
lsprotocol==2023.0.1
# via pygls
markupsafe==2.1.5
# via jinja2
packaging==24.0
# via pytest
# via sphinx
platformdirs==4.2.1
# via esbonio
pluggy==1.5.0
# via pytest
pygls==1.3.1
# via esbonio
pygments==2.17.2
# via sphinx
pyspellchecker==0.8.1
# via esbonio
pytest==8.2.0
requests==2.31.0
# via sphinx
snowballstemmer==2.2.0
Expand Down
4 changes: 4 additions & 0 deletions tests/.ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extend = "../pyproject.toml"

[lint]
ignore = ["D100", "D103"]
9 changes: 9 additions & 0 deletions tests/patterns/budoux-example-plain/pseudoxml.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<document source="<string>">
<paragraph>
あなたに
<word-break>
寄り添う
<word-break>
最先端の
<word-break>
テクノロジー。
1 change: 1 addition & 0 deletions tests/patterns/budoux-example-plain/source.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
あなたに寄り添う最先端のテクノロジー。
29 changes: 29 additions & 0 deletions tests/test_it.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from pathlib import Path
from typing import List

import budoux
import pytest
from docutils.core import publish_doctree, publish_from_doctree

root = Path(__file__).parent


def get_pattern_dirs() -> List[Path]:
"""Return structure of folder-path as test pattern.
.. note:: This is for parametrize.
"""
return [p for p in (root / "patterns").glob("*") if p.is_dir()]


@pytest.mark.parametrize("pattern_dir", get_pattern_dirs())
def test_parse_all_sentences(pattern_dir: Path):
from rst_budoux import parse_all_sentences

source = pattern_dir / "source.rst"
expect = pattern_dir / "pseudoxml.txt"
parser = budoux.load_default_japanese_parser()
document = publish_doctree(source.read_text())
document = parse_all_sentences(parser, document)
result = publish_from_doctree(document, writer_name="pseudoxml").decode("utf-8")
assert result == expect.read_text()

0 comments on commit d9b5c0c

Please sign in to comment.