Remove future imports

This commit is contained in:
Vinayak Mehta
2020-05-24 17:33:13 +05:30
parent 3afb72b872
commit f725f04223
11 changed files with 59 additions and 66 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
import matplotlib
matplotlib.use('agg')
matplotlib.use("agg")
-2
View File
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
data_stream = [
["States-A", "Revenue", "", "Capital", "", "Total", "Others(1)", "Total"],
+33 -28
View File
@@ -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")
+16 -23
View File
@@ -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")