Exemple #1
0
def write_report(file):
    """Write CSV report."""
    spi_report = SPIReport()
    # ensure that rows only contain keys defined in field_titles
    for line in csv_iterator(
            _filter_row_dicts(spi_report.rows(), spi_report.field_titles),
            spi_report.field_titles,
    ):
        file.write(line)
Exemple #2
0
def test_csv_iterator_with_error():
    """
    Tests that an error is appended to the CSV data is an error occurs during generation.

    This is as if the CSV data is being used as part of a streamed HTTP response, it will be to
    late to return an error status.
    """
    row = None

    with pytest.raises(ValueError):
        for row in csv_iterator(_rows(), {'id': 'id'}):  # noqa: B007
            pass

    assert row == INCOMPLETE_CSV_MESSAGE
Exemple #3
0
def write_report(file):
    """Write CSV report."""
    spi_report = SPIReport()
    for line in csv_iterator(spi_report.rows(), spi_report.field_titles):
        file.write(line)