Skip to content

Commit

Permalink
Add final bits of test coverage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsvine committed May 6, 2022
1 parent a7af394 commit feb9d08
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pdfplumber/display.py
Expand Up @@ -10,7 +10,7 @@
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

Expand Down
2 changes: 1 addition & 1 deletion pdfplumber/pdf.py
Expand Up @@ -46,7 +46,7 @@ def __init__(
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
Expand Down
25 changes: 25 additions & 0 deletions tests/test_display.py
Expand Up @@ -4,7 +4,10 @@
import os
import unittest

import pytest

import pdfplumber
from pdfplumber.table import TableFinder

logging.disable(logging.ERROR)

Expand Down Expand Up @@ -34,6 +37,11 @@ def test_debug_tablefinder(self):
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")
Expand All @@ -52,3 +60,20 @@ def test_cropped(self):

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

0 comments on commit feb9d08

Please sign in to comment.