Skip to content

Commit d86744c

Browse files
committed
Add unit tests
1 parent 8f425ee commit d86744c

20 files changed

+3469
-4
lines changed

.coverage

52 KB
Binary file not shown.

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.12"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v4
21+
with:
22+
version: "latest"
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
run: uv python install ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: uv sync --all-groups
29+
30+
- name: Run linting
31+
run: |
32+
uv run black --check src/
33+
uv run flake8 src/
34+
uv run isort --check-only src/
35+
36+
- name: Run tests with coverage
37+
run: |
38+
uv run pytest tests/ \
39+
--cov=src \
40+
--cov-report=xml \
41+
--cov-report=term-missing \
42+
-v
43+
44+
- name: Upload coverage to Codecov
45+
uses: codecov/codecov-action@v4
46+
with:
47+
file: ./coverage.xml
48+
fail_ci_if_error: false
49+
env:
50+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PYTHON_VERSION=3.12
1818
PYTHONPATH := $(or ${PYTHONPATH},.)
1919
TEST_DIR = tests/
2020

21-
LINT_SOURCES_PATHS = src/
21+
LINT_SOURCES_PATHS = src/ tests/
2222

2323
export PYTHONPATH
2424

@@ -169,10 +169,10 @@ clean: ## Clear temporary information
169169
####################
170170

171171
.PHONY: test
172-
## Run all tests
172+
## Run all tests with coverage
173173
test:
174174
PYTHONPATH=$(PYTHONPATH):src \
175-
$(PYTHON) -m pytest --disable-warnings $(TEST_DIR)
175+
$(PYTHON) -m pytest --cov=src --cov-report=term-missing --cov-report=html $(TEST_DIR)
176176

177177

178178
#################################################################################

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ src/
129129
EPUB → epub_parser.py → pagination.py → text_renderer.py → xtc_format.py → XTC/XTCH
130130
```
131131

132+
## Testing
133+
134+
Run tests with pytest:
135+
136+
```bash
137+
# Run all tests with coverage
138+
make test
139+
140+
# Run specific test file
141+
PYTHONPATH=.:src pytest tests/test_config.py -v
142+
143+
# Run tests matching pattern
144+
PYTHONPATH=.:src pytest -k "test_sanitize" -v
145+
```
146+
147+
The test suite covers:
148+
- **config.py**: Constants, heading size calculations
149+
- **epub_utils.py**: OPF finding, namespace handling
150+
- **optimizer.py**: CSS sanitization, manifest operations, font removal, image processing, EPUB rebuild
151+
- **xtc_format.py**: Binary encoding, quantization, container writing
152+
- **epub_parser.py**: HTML parsing, metadata extraction, TOC parsing
153+
- **text_renderer.py**: Font handling, text wrapping
154+
- **pagination.py**: Page layout, chapter detection
155+
- **converter.py**: End-to-end conversion, CLI argument handling, directory processing
156+
157+
### Test Fixtures
158+
159+
Test fixtures in `tests/fixtures/` include:
160+
- Minimal valid EPUB structure (container.xml, content.opf, chapter1.xhtml)
161+
- NCX and NAV navigation files
162+
- Generated test images (grayscale, color)
163+
132164
## Documentation
133165

134166
- [XTC/XTG/XTH/XTCH Format Specification](docs/xtc-format-spec.md) ([source](https://gist.github.com/CrazyCoder/b125f26d6987c0620058249f59f1327d))

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ omit = *tests*
2121

2222
[tool:pytest]
2323
python_files = tests.py test_*.py *_tests.py
24-
addopts = --cov-report=term-missing --cov-config=setup.cfg --cov=llmdoc
24+
addopts = --cov-report=term-missing --cov-config=setup.cfg --cov=src
2525
mock_traceback_monkeypatch = false
2626

2727
[mypy]

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Tests package

0 commit comments

Comments
 (0)