From 929ea7551135df0cc2ac9d67f4fbbecf701a11f6 Mon Sep 17 00:00:00 2001 From: Frans Date: Fri, 29 Jan 2021 20:58:37 +0100 Subject: [PATCH] fix for problem in Table.insert_all on search for columns per chunk of rows --- sqlite_utils/db.py | 12 ++++++------ tests/test_cli.py | 21 +++++++++++++++++---- tests/test_insert_files.py | 6 ++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 14a9efc..c47935b 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -1886,12 +1886,12 @@ class Table(Queryable): if hash_id: all_columns.insert(0, hash_id) else: - all_columns += [ - column - for record in chunk - for column in record - if column not in all_columns - ] + for record in chunk: + all_columns += [ + column + for column in record + if column not in all_columns + ] validate_column_names(all_columns) first = False diff --git a/tests/test_cli.py b/tests/test_cli.py index 381997b..dd7f7b6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -4,6 +4,7 @@ from click.testing import CliRunner import json import os import pytest +import sys from sqlite_utils.utils import sqlite3, find_spatialite import textwrap @@ -93,7 +94,10 @@ def test_tables_counts_and_columns_csv(db_path, format, expected): result = CliRunner().invoke( cli.cli, ["tables", "--counts", "--columns", format, db_path] ) - assert result.output.strip() == expected + if sys.platform == 'win32': + assert result.output.strip().replace('\r', '') == expected + else: + assert result.output.strip() == expected def test_tables_schema(db_path): @@ -860,12 +864,18 @@ def test_query_csv(db_path, format, expected): cli.cli, [db_path, "select id, name, age from dogs", format] ) assert 0 == result.exit_code - assert result.output == expected + if sys.platform == 'win32': + assert result.output.replace('\r', '') == expected + else: + assert result.output == expected # Test the no-headers option: result = CliRunner().invoke( cli.cli, [db_path, "select id, name, age from dogs", "--no-headers", format] ) - assert result.output.strip() == "\n".join(expected.split("\n")[1:]).strip() + if sys.platform == 'win32': + assert result.output.strip().replace('\r', '') == "\n".join(expected.split("\n")[1:]).strip() + else: + assert result.output.strip() == "\n".join(expected.split("\n")[1:]).strip() _all_query = "select id, name, age from dogs" @@ -1750,7 +1760,10 @@ def test_search(tmpdir, fts, extra_arg, expected): catch_exceptions=False, ) assert result.exit_code == 0 - assert result.output == expected + if sys.platform == 'win32': + assert result.output.replace('\r', '') == expected + else: + assert result.output == expected _TRIGGERS_EXPECTED = '[{"name": "blah", "table": "articles", "sql": "CREATE TRIGGER blah AFTER INSERT ON articles\\nBEGIN\\n UPDATE counter SET count = count + 1;\\nEND"}]\n' diff --git a/tests/test_insert_files.py b/tests/test_insert_files.py index f17f279..c31e927 100644 --- a/tests/test_insert_files.py +++ b/tests/test_insert_files.py @@ -1,3 +1,5 @@ +import os + from sqlite_utils import cli, Database from click.testing import CliRunner import pathlib @@ -42,7 +44,7 @@ def test_insert_files(): one, two, three = ( rows_by_path["one.txt"], rows_by_path["two.txt"], - rows_by_path["nested/three.txt"], + rows_by_path[os.path.join("nested", "three.txt")], ) assert { "content": b"This is file one", @@ -64,7 +66,7 @@ def test_insert_files(): "content": b"Three is nested", "md5": "12580f341781f5a5b589164d3cd39523", "name": "three.txt", - "path": "nested/three.txt", + "path": os.path.join("nested", "three.txt"), "sha256": "6dd45aaaaa6b9f96af19363a92c8fca5d34791d3c35c44eb19468a6a862cc8cd", "size": 15, }.items() <= three.items()