Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,7 @@ def extract(
@click.option("--text", is_flag=True, help="Store file content as TEXT, not BLOB")
@click.option(
"--encoding",
default="utf-8",
help="Character encoding for input, defaults to utf-8",
)
@click.option("-s", "--silent", is_flag=True, help="Don't show a progress bar")
Expand Down
33 changes: 33 additions & 0 deletions tests/test_insert_files.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import subprocess
import sys

import pytest
Expand Down Expand Up @@ -151,6 +152,38 @@ def test_insert_files_stdin(use_text, encoding, input, expected):
assert {"path": "stdin-name", key: expected}.items() <= row.items()


@pytest.mark.skipif(
sys.platform.startswith("win"), reason="Requires the POSIX C locale"
)
def test_insert_files_uses_utf8_by_default_in_ascii_locale(tmp_path):
source = tmp_path / "input.txt"
source.write_text("São Paulo", encoding="utf-8")
db_path = tmp_path / "files.db"
result = subprocess.run(
[
sys.executable,
"-m",
"sqlite_utils",
"insert-files",
str(db_path),
"files",
str(source),
"--text",
"--silent",
],
env={
**os.environ,
"LC_ALL": "C",
"PYTHONCOERCECLOCALE": "0",
"PYTHONUTF8": "0",
},
capture_output=True,
)
assert result.returncode == 0, result.stderr
with Database(db_path) as db:
assert next(db.table("files").rows)["content_text"] == "São Paulo"


@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="Windows has a different way of handling default encodings",
Expand Down
Loading