mirror of
https://github.com/jsvine/pdfplumber.git
synced 2026-08-29 08:34:23 +08:00
Add final bits of test coverage
Added weak tests for a couple of hard-to-test visual debugging methods in display.py. Also marked an exception-handling block in pdf.py as `pragma: nocover` because we don't yet have a PDF to test it with, but the logic there is simple and straightforward.
This commit is contained in:
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. The format
|
||||
|
||||
- Add type annotations, and refactor parts of the library accordingly.
|
||||
- Add enforcement of type annotations via `mypy --strict`.
|
||||
- Add final bits of test coverage.
|
||||
- Add `TableSettings` class, a behind-the-scenes handler for managing and validating table-extraction settings.
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -10,7 +10,7 @@ from . import utils
|
||||
from ._typing import T_bbox, T_num, T_obj, T_obj_list, T_point, T_seq
|
||||
from .table import T_table_settings, Table, TableFinder, TableSettings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
if TYPE_CHECKING: # pragma: nocover
|
||||
from pandas.core.frame import DataFrame
|
||||
from pandas.core.series import Series
|
||||
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ class PDF(Container):
|
||||
for k, v in self.metadata.items():
|
||||
try:
|
||||
self.metadata[k] = resolve_and_decode(v)
|
||||
except Exception as e:
|
||||
except Exception as e: # pragma: nocover
|
||||
if strict_metadata:
|
||||
# Raise an exception since unable to resolve the metadata value.
|
||||
raise
|
||||
|
||||
@@ -4,7 +4,10 @@ import logging
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
|
||||
import pdfplumber
|
||||
from pdfplumber.table import TableFinder
|
||||
|
||||
logging.disable(logging.ERROR)
|
||||
|
||||
@@ -34,6 +37,11 @@ class Test(unittest.TestCase):
|
||||
self.im.reset()
|
||||
settings = {"horizontal_strategy": "text", "intersection_tolerance": 5}
|
||||
self.im.debug_tablefinder(settings)
|
||||
finder = TableFinder(self.im.page, settings)
|
||||
self.im.debug_tablefinder(finder)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
self.im.debug_tablefinder(0)
|
||||
|
||||
def test_bytes_stream_to_image(self):
|
||||
path = os.path.join(HERE, "pdfs/nics-background-checks-2015-11.pdf")
|
||||
@@ -52,3 +60,20 @@ class Test(unittest.TestCase):
|
||||
|
||||
def test_copy(self):
|
||||
assert self.im.copy().original == self.im.original
|
||||
|
||||
def test_outline_words(self):
|
||||
self.im.outline_words(
|
||||
stroke="blue",
|
||||
fill=(0, 200, 10),
|
||||
stroke_width=2,
|
||||
x_tolerance=5,
|
||||
y_tolerance=5,
|
||||
)
|
||||
|
||||
def test_outline_chars(self):
|
||||
self.im.outline_chars(stroke="blue", fill=(0, 200, 10), stroke_width=2)
|
||||
|
||||
def test__repr_png_(self):
|
||||
png = self.im._repr_png_()
|
||||
assert isinstance(png, bytes)
|
||||
assert len(png) == 71948
|
||||
|
||||
Reference in New Issue
Block a user