diff --git a/camelot/parsers/lattice.py b/camelot/parsers/lattice.py index ca3731d..f4bc2c0 100644 --- a/camelot/parsers/lattice.py +++ b/camelot/parsers/lattice.py @@ -357,8 +357,8 @@ class Lattice(BaseParser): if not self.horizontal_text: if self.images: - warnings.warn('The page is image-based, Camelot only works with' - ' text-based PDF pages.'.format(os.path.basename(self.rootname))) + warnings.warn('{} is image-based, camelot only works on' + ' text-based pages.'.format(os.path.basename(self.rootname))) else: warnings.warn('No tables found on {}'.format( os.path.basename(self.rootname))) diff --git a/camelot/parsers/stream.py b/camelot/parsers/stream.py index 83e2598..d36212b 100644 --- a/camelot/parsers/stream.py +++ b/camelot/parsers/stream.py @@ -396,8 +396,8 @@ class Stream(BaseParser): if not self.horizontal_text: if self.images: - warnings.warn('The page is image-based, Camelot only works with' - ' text-based PDF pages.'.format(os.path.basename(self.rootname))) + warnings.warn('{} is image-based, camelot only works on' + ' text-based pages.'.format(os.path.basename(self.rootname))) else: warnings.warn('No tables found on {}'.format( os.path.basename(self.rootname))) diff --git a/tests/files/image.pdf b/tests/files/image.pdf new file mode 100644 index 0000000..83f5969 Binary files /dev/null and b/tests/files/image.pdf differ diff --git a/tests/test_errors.py b/tests/test_errors.py index e0dc24a..a4b38ec 100755 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -41,6 +41,15 @@ def test_stream_equal_length(): table_areas=['10,20,30,40'], columns=['10,20,30,40', '10,20,30,40']) +def test_image_warning(): + filename = os.path.join(testdir, 'image.pdf') + with warnings.catch_warnings(): + warnings.simplefilter('error') + with pytest.raises(UserWarning) as e: + tables = camelot.read_pdf(filename) + assert str(e.value) == 'page-1 is image-based, camelot only works on text-based pages.' + + def test_no_tables_found(): filename = os.path.join(testdir, 'blank.pdf') with warnings.catch_warnings():