diff --git a/tests/test_importers.py b/tests/test_importers.py index 5c63d71930ed4ff95f4666d8b7546d9be3df3952..bb8757c9c33b65b7a1d8a4d6acd77205465e8fd1 100644 --- a/tests/test_importers.py +++ b/tests/test_importers.py @@ -1,8 +1,11 @@ +import csv import datetime import decimal +import io import importlib import itertools import pathlib +import shutil import re import pytest @@ -28,6 +31,25 @@ class TestImporters: with source_path.open() as source_file: assert importer.can_import(source_file) + @pytest.mark.parametrize('source_path,importer,header_rows,header_cols', [ + (t['source'], t['importer'], t['header_rows'], t['header_cols']) + for t in test_data if t.get('header_rows') + ]) + def test_can_import_squared_csv(self, source_path, importer, header_rows, header_cols): + # Sometimes when we munge spreadsheets by hand (e.g., to filter by + # project) tools like LibreOffice Calc write a "squared" spreadsheet, + # where every row has the same length. This test ensures the results + # are still recognized for import. + with io.StringIO() as squared_file: + csv_writer = csv.writer(squared_file) + with source_path.open() as source_file: + for row in itertools.islice(csv.reader(source_file), header_rows): + padding = [None] * (header_cols - len(row)) + csv_writer.writerow(row + padding) + shutil.copyfileobj(source_file, squared_file) + squared_file.seek(0) + assert importer.can_import(squared_file) + @pytest.mark.parametrize('source_path,import_class,expect_results', [ (t['source'], t['importer'], t['expect']) for t in test_data ])