diff --git a/camelot/__main__.py b/camelot/__main__.py index 93040c6..a0b82a6 100755 --- a/camelot/__main__.py +++ b/camelot/__main__.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import - __all__ = ("main",) diff --git a/camelot/ext/ghostscript/_gsprint.py b/camelot/ext/ghostscript/_gsprint.py index b31b768..9896805 100644 --- a/camelot/ext/ghostscript/_gsprint.py +++ b/camelot/ext/ghostscript/_gsprint.py @@ -81,6 +81,7 @@ def delete_instance(instance): """ return libgs.gsapi_delete_instance(instance) + if sys.platform == "win32": c_stdstream_call_t = WINFUNCTYPE(c_int, gs_main_instance, POINTER(c_char), c_int) else: @@ -247,7 +248,10 @@ if sys.platform == "win32": libgs = __win32_finddll() if not libgs: import ctypes.util - libgs = ctypes.util.find_library("".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll"))) # finds in %PATH% + + libgs = ctypes.util.find_library( + "".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")) + ) # finds in %PATH% if not libgs: raise RuntimeError("Please make sure that Ghostscript is installed") libgs = windll.LoadLibrary(libgs) diff --git a/camelot/image_processing.py b/camelot/image_processing.py index 7b87101..08acb23 100644 --- a/camelot/image_processing.py +++ b/camelot/image_processing.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import division - import cv2 import numpy as np diff --git a/camelot/parsers/lattice.py b/camelot/parsers/lattice.py index 197ff9f..5469fac 100644 --- a/camelot/parsers/lattice.py +++ b/camelot/parsers/lattice.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import division import os import sys import copy diff --git a/camelot/parsers/stream.py b/camelot/parsers/stream.py index 33f2fe5..35cf4eb 100644 --- a/camelot/parsers/stream.py +++ b/camelot/parsers/stream.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import division import os import logging import warnings diff --git a/camelot/utils.py b/camelot/utils.py index 11d28dd..fd5c87f 100644 --- a/camelot/utils.py +++ b/camelot/utils.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -from __future__ import division -import re import os -import sys +import re import random import shutil import string diff --git a/setup.py b/setup.py index b83f566..0619f12 100644 --- a/setup.py +++ b/setup.py @@ -71,10 +71,10 @@ def setup_package(): # Trove classifiers # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7' + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8' ]) try: diff --git a/tests/__init__.py b/tests/__init__.py index a946ff7..96c475e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,2 +1,3 @@ import matplotlib -matplotlib.use('agg') + +matplotlib.use("agg") diff --git a/tests/data.py b/tests/data.py index 2eeddb4..7e53792 100755 --- a/tests/data.py +++ b/tests/data.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals - data_stream = [ ["States-A", "Revenue", "", "Capital", "", "Total", "Others(1)", "Total"], diff --git a/tests/test_errors.py b/tests/test_errors.py index 0a11c55..702439c 100755 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -10,88 +10,93 @@ import camelot testdir = os.path.dirname(os.path.abspath(__file__)) testdir = os.path.join(testdir, "files") -filename = os.path.join(testdir, 'foo.pdf') +filename = os.path.join(testdir, "foo.pdf") def test_unknown_flavor(): - message = ("Unknown flavor specified." - " Use either 'lattice' or 'stream'") + message = "Unknown flavor specified." " Use either 'lattice' or 'stream'" with pytest.raises(NotImplementedError, match=message): - tables = camelot.read_pdf(filename, flavor='chocolate') + tables = camelot.read_pdf(filename, flavor="chocolate") def test_input_kwargs(): message = "columns cannot be used with flavor='lattice'" with pytest.raises(ValueError, match=message): - tables = camelot.read_pdf(filename, columns=['10,20,30,40']) + tables = camelot.read_pdf(filename, columns=["10,20,30,40"]) def test_unsupported_format(): - message = 'File format not supported' - filename = os.path.join(testdir, 'foo.csv') + message = "File format not supported" + filename = os.path.join(testdir, "foo.csv") with pytest.raises(NotImplementedError, match=message): tables = camelot.read_pdf(filename) def test_stream_equal_length(): - message = ("Length of table_areas and columns" - " should be equal") + message = "Length of table_areas and columns" " should be equal" with pytest.raises(ValueError, match=message): - tables = camelot.read_pdf(filename, flavor='stream', - table_areas=['10,20,30,40'], columns=['10,20,30,40', '10,20,30,40']) + tables = camelot.read_pdf( + filename, + flavor="stream", + 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') + filename = os.path.join(testdir, "image.pdf") with warnings.catch_warnings(): - warnings.simplefilter('error') + 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.' + 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') + filename = os.path.join(testdir, "blank.pdf") with warnings.catch_warnings(): - warnings.simplefilter('error') + warnings.simplefilter("error") with pytest.raises(UserWarning) as e: tables = camelot.read_pdf(filename) - assert str(e.value) == 'No tables found on page-1' + assert str(e.value) == "No tables found on page-1" def test_no_tables_found_logs_suppressed(): - filename = os.path.join(testdir, 'foo.pdf') + filename = os.path.join(testdir, "foo.pdf") with warnings.catch_warnings(): # the test should fail if any warning is thrown - warnings.simplefilter('error') + warnings.simplefilter("error") try: tables = camelot.read_pdf(filename, suppress_stdout=True) except Warning as e: warning_text = str(e) - pytest.fail('Unexpected warning: {}'.format(warning_text)) + pytest.fail("Unexpected warning: {}".format(warning_text)) def test_no_tables_found_warnings_suppressed(): - filename = os.path.join(testdir, 'blank.pdf') + filename = os.path.join(testdir, "blank.pdf") with warnings.catch_warnings(): # the test should fail if any warning is thrown - warnings.simplefilter('error') + warnings.simplefilter("error") try: tables = camelot.read_pdf(filename, suppress_stdout=True) except Warning as e: warning_text = str(e) - pytest.fail('Unexpected warning: {}'.format(warning_text)) + pytest.fail("Unexpected warning: {}".format(warning_text)) def test_no_password(): - filename = os.path.join(testdir, 'health_protected.pdf') - message = 'file has not been decrypted' + filename = os.path.join(testdir, "health_protected.pdf") + message = "file has not been decrypted" with pytest.raises(Exception, match=message): tables = camelot.read_pdf(filename) def test_bad_password(): - filename = os.path.join(testdir, 'health_protected.pdf') - message = 'file has not been decrypted' + filename = os.path.join(testdir, "health_protected.pdf") + message = "file has not been decrypted" with pytest.raises(Exception, match=message): - tables = camelot.read_pdf(filename, password='wrongpass') + tables = camelot.read_pdf(filename, password="wrongpass") diff --git a/tests/test_plotting.py b/tests/test_plotting.py index f267e29..cec9df6 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -11,57 +11,50 @@ testdir = os.path.dirname(os.path.abspath(__file__)) testdir = os.path.join(testdir, "files") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_text_plot(): filename = os.path.join(testdir, "foo.pdf") tables = camelot.read_pdf(filename) - return camelot.plot(tables[0], kind='text') + return camelot.plot(tables[0], kind="text") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_grid_plot(): filename = os.path.join(testdir, "foo.pdf") tables = camelot.read_pdf(filename) - return camelot.plot(tables[0], kind='grid') + return camelot.plot(tables[0], kind="grid") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_lattice_contour_plot(): filename = os.path.join(testdir, "foo.pdf") tables = camelot.read_pdf(filename) - return camelot.plot(tables[0], kind='contour') + return camelot.plot(tables[0], kind="contour") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_stream_contour_plot(): filename = os.path.join(testdir, "tabula/12s0324.pdf") - tables = camelot.read_pdf(filename, flavor='stream') - return camelot.plot(tables[0], kind='contour') + tables = camelot.read_pdf(filename, flavor="stream") + return camelot.plot(tables[0], kind="contour") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_line_plot(): filename = os.path.join(testdir, "foo.pdf") tables = camelot.read_pdf(filename) - return camelot.plot(tables[0], kind='line') + return camelot.plot(tables[0], kind="line") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_joint_plot(): filename = os.path.join(testdir, "foo.pdf") tables = camelot.read_pdf(filename) - return camelot.plot(tables[0], kind='joint') + return camelot.plot(tables[0], kind="joint") -@pytest.mark.mpl_image_compare( - baseline_dir="files/baseline_plots", remove_text=True) +@pytest.mark.mpl_image_compare(baseline_dir="files/baseline_plots", remove_text=True) def test_textedge_plot(): filename = os.path.join(testdir, "tabula/12s0324.pdf") - tables = camelot.read_pdf(filename, flavor='stream') - return camelot.plot(tables[0], kind='textedge') + tables = camelot.read_pdf(filename, flavor="stream") + return camelot.plot(tables[0], kind="textedge")