[MRG + 1] Add suppress_warnings flag (#155)
* Add suppress_warnings flag * Add --quiet flag to cli (to suppress warnings) * Remove TODO and update comment
This commit is contained in:
committed by
Vinayak Mehta
parent
1d064adc3e
commit
3def4a5aea
@@ -77,3 +77,17 @@ def test_cli_output_format():
|
||||
result = runner.invoke(cli, ['--zip', '--format', 'csv', '--output', outfile.format('csv'),
|
||||
'stream', infile])
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_cli_quiet_flag():
|
||||
with TemporaryDirectory() as tempdir:
|
||||
infile = os.path.join(testdir, 'blank.pdf')
|
||||
outfile = os.path.join(tempdir, 'blank.csv')
|
||||
runner = CliRunner()
|
||||
|
||||
result = runner.invoke(cli, ['--format', 'csv', '--output', outfile,
|
||||
'stream', infile])
|
||||
assert 'No tables found on page-1' in result.output
|
||||
|
||||
result = runner.invoke(cli, ['--quiet', '--format', 'csv',
|
||||
'--output', outfile, 'stream', infile])
|
||||
assert 'No tables found on page-1' not in result.output
|
||||
|
||||
@@ -139,7 +139,7 @@ def test_lattice_shift_text():
|
||||
tables = camelot.read_pdf(filename, line_size_scaling=40, shift_text=['r', 'b'])
|
||||
assert df_rb.equals(tables[0].df)
|
||||
|
||||
|
||||
|
||||
def test_repr():
|
||||
filename = os.path.join(testdir, "foo.pdf")
|
||||
tables = camelot.read_pdf(filename)
|
||||
|
||||
+14
-5
@@ -43,11 +43,20 @@ def test_stream_equal_length():
|
||||
|
||||
def test_no_tables_found():
|
||||
filename = os.path.join(testdir, 'blank.pdf')
|
||||
# TODO: use pytest.warns
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('error')
|
||||
try:
|
||||
with pytest.raises(UserWarning) as e:
|
||||
tables = camelot.read_pdf(filename)
|
||||
except Exception as e:
|
||||
assert type(e).__name__ == 'UserWarning'
|
||||
assert str(e) == 'No tables found on page-1'
|
||||
assert str(e.value) == 'No tables found on page-1'
|
||||
|
||||
|
||||
def test_no_tables_found_warnings_supressed():
|
||||
filename = os.path.join(testdir, 'blank.pdf')
|
||||
with warnings.catch_warnings():
|
||||
# the test should fail if any warning is thrown
|
||||
warnings.simplefilter('error')
|
||||
try:
|
||||
tables = camelot.read_pdf(filename, suppress_warnings=True)
|
||||
except Warning as e:
|
||||
warning_text = str(e)
|
||||
pytest.fail('Unexpected warning: {}'.format(warning_text))
|
||||
|
||||
Reference in New Issue
Block a user