Esempio n. 1
0
def test_cli_output_format():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, 'health.pdf')
        outfile = os.path.join(tempdir, 'health.{}')
        runner = CliRunner()

        # json
        result = runner.invoke(cli, ['--format', 'json', '--output', outfile.format('json'),
                                     'stream', infile])
        assert result.exit_code == 0

        # excel
        result = runner.invoke(cli, ['--format', 'excel', '--output', outfile.format('xlsx'),
                                     'stream', infile])
        assert result.exit_code == 0

        # html
        result = runner.invoke(cli, ['--format', 'html', '--output', outfile.format('html'),
                                     'stream', infile])
        assert result.exit_code == 0

        # zip
        result = runner.invoke(cli, ['--zip', '--format', 'csv', '--output', outfile.format('csv'),
                                     'stream', infile])
        assert result.exit_code == 0
Esempio n. 2
0
def test_cli_output_format():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, "health.pdf")

        runner = CliRunner()

        # json
        outfile = os.path.join(tempdir, "health.json")
        result = runner.invoke(
            cli,
            ["--format", "json", "--output", outfile, "stream", infile],
        )
        assert result.exit_code == 0, f"Output: {result.output}"

        # excel
        outfile = os.path.join(tempdir, "health.xlsx")
        result = runner.invoke(
            cli,
            ["--format", "excel", "--output", outfile, "stream", infile],
        )
        assert result.exit_code == 0, f"Output: {result.output}"

        # html
        outfile = os.path.join(tempdir, "health.html")
        result = runner.invoke(
            cli,
            ["--format", "html", "--output", outfile, "stream", infile],
        )
        assert result.exit_code == 0, f"Output: {result.output}"

        # markdown
        outfile = os.path.join(tempdir, "health.md")
        result = runner.invoke(
            cli,
            ["--format", "markdown", "--output", outfile, "stream", infile],
        )
        assert result.exit_code == 0, f"Output: {result.output}"

        # zip
        outfile = os.path.join(tempdir, "health.csv")
        result = runner.invoke(
            cli,
            [
                "--zip",
                "--format",
                "csv",
                "--output",
                outfile,
                "stream",
                infile,
            ],
        )
        assert result.exit_code == 0, f"Output: {result.output}"
Esempio n. 3
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
Esempio n. 4
0
def test_cli_quiet():
    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
Esempio n. 5
0
def test_cli_stream():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, "budget.pdf")
        outfile = os.path.join(tempdir, "budget.csv")
        runner = CliRunner()
        result = runner.invoke(
            cli, ["--format", "csv", "--output", outfile, "stream", infile])
        assert result.exit_code == 0
        assert result.output == "Found 1 tables\n"

        result = runner.invoke(cli, ["--format", "csv", "stream", infile])
        output_error = "Error: Please specify output file path using --output"
        assert output_error in result.output

        result = runner.invoke(cli, ["--output", outfile, "stream", infile])
        format_error = "Please specify output file format using --format"
        assert format_error in result.output
Esempio n. 6
0
def test_cli_stream():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, 'budget.pdf')
        outfile = os.path.join(tempdir, 'budget.csv')
        runner = CliRunner()
        result = runner.invoke(cli, ['--format', 'csv', '--output', outfile,
                                     'stream', infile])
        assert result.exit_code == 0
        assert result.output == 'Found 1 tables\n'

        result = runner.invoke(cli, ['--format', 'csv', 'stream', infile])
        output_error = 'Error: Please specify output file path using --output'
        assert output_error in result.output

        result = runner.invoke(cli, ['--output', outfile, 'stream', infile])
        format_error = 'Please specify output file format using --format'
        assert format_error in result.output
Esempio n. 7
0
def test_cli_password():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, "health_protected.pdf")
        outfile = os.path.join(tempdir, "health_protected.csv")
        runner = CliRunner()
        result = runner.invoke(
            cli,
            [
                "--password",
                "userpass",
                "--format",
                "csv",
                "--output",
                outfile,
                "stream",
                infile,
            ],
        )
        assert result.exit_code == 0
        assert result.output == "Found 1 tables\n"

        output_error = "file has not been decrypted"
        # no password
        result = runner.invoke(
            cli, ["--format", "csv", "--output", outfile, "stream", infile]
        )
        assert output_error in str(result.exception)

        # bad password
        result = runner.invoke(
            cli,
            [
                "--password",
                "wrongpass",
                "--format",
                "csv",
                "--output",
                outfile,
                "stream",
                infile,
            ],
        )
        assert output_error in str(result.exception)
Esempio n. 8
0
def test_cli_output_format():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, "health.pdf")
        outfile = os.path.join(tempdir, "health.{}")
        runner = CliRunner()

        # json
        result = runner.invoke(
            cli,
            ["--format", "json", "--output", outfile.format("json"), "stream", infile],
        )
        assert result.exit_code == 0

        # excel
        result = runner.invoke(
            cli,
            ["--format", "excel", "--output", outfile.format("xlsx"), "stream", infile],
        )
        assert result.exit_code == 0

        # html
        result = runner.invoke(
            cli,
            ["--format", "html", "--output", outfile.format("html"), "stream", infile],
        )
        assert result.exit_code == 0

        # zip
        result = runner.invoke(
            cli,
            [
                "--zip",
                "--format",
                "csv",
                "--output",
                outfile.format("csv"),
                "stream",
                infile,
            ],
        )
        assert result.exit_code == 0
def test_cli_password():
    with TemporaryDirectory() as tempdir:
        infile = os.path.join(testdir, 'health_protected.pdf')
        outfile = os.path.join(tempdir, 'health_protected.csv')
        runner = CliRunner()
        result = runner.invoke(cli, ['--password', 'userpass',
                                     '--format', 'csv', '--output', outfile,
                                     'stream', infile])
        assert result.exit_code == 0
        assert result.output == 'Found 1 tables\n'

        output_error = 'file has not been decrypted'
        # no password
        result = runner.invoke(cli, ['--format', 'csv', '--output', outfile,
                                     'stream', infile])
        assert output_error in str(result.exception)

        # bad password
        result = runner.invoke(cli, ['--password', 'wrongpass',
                                     '--format', 'csv', '--output', outfile,
                                     'stream', infile])
        assert output_error in str(result.exception)