Skip to content

Commit bb99e81

Browse files
committed
tests: update unit testings
1 parent 9390776 commit bb99e81

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ pip install rapidocr_pdf
4040

4141
#### 脚本使用
4242

43-
⚠️注意:在`rapidocr_pdf>=0.2.0`中,已经适配`rapidocr>=2.0.0`版本,可以通过参数来使用不同OCR推理引擎来提速。
44-
下面的`ocr_params`为示例参数,详细请参见RapidOCR官方文档:[docs](https://rapidai.github.io/RapidOCRDocs/main/install_usage/rapidocr/usage/#_4)
43+
⚠️注意:在`rapidocr_pdf>=0.4.0`中,支持`page_num_list`参数为负数,假设总页数为2,范围为`[-2, 1]`
4544

4645
⚠️注意:在`rapidocr_pdf>=0.3.0`中,支持了`page_num_list`参数,默认为None,全部提取。**如果指定,页码从0开始**
4746

47+
⚠️注意:在`rapidocr_pdf>=0.2.0`中,已经适配`rapidocr>=2.0.0`版本,可以通过参数来使用不同OCR推理引擎来提速。
48+
下面的`ocr_params`为示例参数,详细请参见RapidOCR官方文档:[docs](https://rapidai.github.io/RapidOCRDocs/main/install_usage/rapidocr/usage/#_4)
49+
4850
```python
4951
from rapidocr_pdf import RapidOCRPDF
5052

tests/test_main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ def test_cli(capsys, command, expected_output):
3838
assert output[0][1].split("\n")[0].strip() == expected_output
3939

4040

41+
def test_negative_page_num():
42+
pdf_path = test_dir / "direct_and_image.pdf"
43+
result = extracter(pdf_path, page_num_list=[-1])
44+
45+
assert result[0][1].split("\n")[0].strip() == "Microsoft"
46+
47+
48+
def test_error_negative_page_num():
49+
pdf_path = test_dir / "direct_and_image.pdf"
50+
with pytest.raises(RapidOCRPDFError) as exc_info:
51+
result = extracter(pdf_path, page_num_list=[-3])
52+
assert exc_info.type is RapidOCRPDFError
53+
54+
4155
def test_page_num():
4256
pdf_path = test_dir / "direct_extract.pdf"
4357
result = extracter(pdf_path, page_num_list=[0])

0 commit comments

Comments
 (0)