Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils.py: Fixing assertion in drange to allow equal inputs #246

Merged
merged 5 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pdfminer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def fsplit(pred, objs):
# drange
def drange(v0, v1, d):
"""Returns a discrete range."""
assert v0 < v1, str((v0, v1, d))
return range(int(v0)//d, int(v1+d)//d)


Expand Down
40 changes: 40 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from nose.tools import assert_equal

from pdfminer.layout import LTComponent
from pdfminer.utils import make_compat_str, Plane


class TestPlane(object):
def test_find_nothing_in_empty_bbox(self):
plane, _ = self.given_plane_with_one_object()
result = list(plane.find((50, 50, 100, 100)))
assert_equal(result, [])

def test_find_nothing_after_removing(self):
plane, obj = self.given_plane_with_one_object()
plane.remove(obj)
result = list(plane.find((0, 0, 100, 100)))
assert_equal(result, [])

def test_find_object_in_whole_plane(self):
plane, obj = self.given_plane_with_one_object()
result = list(plane.find((0, 0, 100, 100)))
assert_equal(result, [obj])

def test_find_if_object_is_smaller_than_gridsize(self):
plane, obj = self.given_plane_with_one_object(object_size=1, gridsize=100)
result = list(plane.find((0, 0, 100, 100)))
assert_equal(result, [obj])

def test_find_object_if_much_larger_than_gridsize(self):
plane, obj = self.given_plane_with_one_object(object_size=100, gridsize=10)
result = list(plane.find((0, 0, 100, 100)))
assert_equal(result, [obj])

@staticmethod
def given_plane_with_one_object(object_size=50, gridsize=50):
bounding_box = (0, 0, 100, 100)
plane = Plane(bounding_box, gridsize)
obj = LTComponent((0, 0, object_size, object_size))
plane.add(obj)
return plane, obj